• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

HttpSessionManager.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026    HttpSessionManager.h
00027 
00028    Description:
00029 
00030 
00031  ****************************************************************************/
00032 
00033 
00034 #ifndef _HTTP_SESSION_MANAGER_H_
00035 #define _HTTP_SESSION_MANAGER_H_
00036 
00037 #include "P_EventSystem.h"
00038 #include "HttpServerSession.h"
00039 #include <ts/Map.h>
00040 
00041 class HttpClientSession;
00042 class HttpSM;
00043 
00044 void
00045 initialize_thread_for_http_sessions(EThread *thread, int thread_index);
00046 
00047 /** A pool of server sessions.
00048 
00049     This is a continuation so that it can get callbacks from the server sessions.
00050     This is used to track remote closes on the sessions so they can be cleaned up.
00051 
00052     @internal Cleanup is the real reason we will always need an IP address mapping for the
00053     sessions. The I/O callback will have only the NetVC and thence the remote IP address for the
00054     closed session and we need to be able find it based on that.
00055 */
00056 class ServerSessionPool: public Continuation
00057 {
00058 public:
00059   /// Default constructor.
00060   /// Constructs an empty pool.
00061   ServerSessionPool();
00062   /// Handle events from server sessions.
00063   int eventHandler(int event, void *data);
00064  protected:
00065   /// Interface class for IP map.
00066   struct IPHashing
00067   {
00068     typedef uint32_t ID;
00069     typedef sockaddr const* Key;
00070     typedef HttpServerSession Value;
00071     typedef DList(HttpServerSession, ip_hash_link) ListHead;
00072 
00073     static ID hash(Key key) { return ats_ip_hash(key); }
00074     static Key key(Value const* value) { return &value->server_ip.sa; }
00075     static bool equal(Key lhs, Key rhs) { return ats_ip_addr_port_eq(lhs, rhs); }
00076   };
00077 
00078   /// Interface class for FQDN map.
00079   struct HostHashing
00080   {
00081     typedef uint64_t ID;
00082     typedef INK_MD5 const& Key;
00083     typedef HttpServerSession Value;
00084     typedef DList(HttpServerSession, host_hash_link) ListHead;
00085 
00086     static ID hash(Key key) { return key.fold(); }
00087     static Key key(Value const* value) { return value->hostname_hash; } 
00088     static bool equal(Key lhs, Key rhs) { return lhs == rhs; }
00089   };
00090 
00091   typedef TSHashTable<IPHashing> IPHashTable; ///< Sessions by IP address.
00092   typedef TSHashTable<HostHashing> HostHashTable; ///< Sessions by host name.
00093 
00094 public:
00095   /** Check if a session matches address and host name.
00096    */
00097   static bool match(HttpServerSession* ss, sockaddr const* addr, INK_MD5 const& host_hash, TSServerSessionSharingMatchType match_style);
00098 
00099   /** Get a session from the pool.
00100 
00101       The session is selected based on @a match_style equivalently to @a match. If found the session
00102       is removed from the pool.
00103 
00104       @return A pointer to the session or @c NULL if not matching session was found.
00105   */
00106   HttpServerSession* acquireSession(sockaddr const* addr, INK_MD5 const& host_hash, TSServerSessionSharingMatchType match_style);
00107   /** Release a session to to pool.
00108    */
00109   void releaseSession(HttpServerSession* ss);
00110 
00111   /// Close all sessions and then clear the table.
00112   void purge();
00113 
00114   // Pools of server sessions.
00115   // Note that each server session is stored in both pools.
00116   IPHashTable m_ip_pool;
00117   HostHashTable m_host_pool;
00118 };
00119 
00120 enum HSMresult_t
00121 {
00122   HSM_DONE,
00123   HSM_RETRY,
00124   HSM_NOT_FOUND
00125 };
00126 
00127 class HttpSessionManager
00128 {
00129 public:
00130   HttpSessionManager() : m_g_pool(NULL)
00131   { }
00132 
00133   ~HttpSessionManager()
00134   { }
00135 
00136   HSMresult_t acquire_session(Continuation *cont, sockaddr const* addr, const char *hostname,
00137                               HttpClientSession *ua_session, HttpSM *sm);
00138   HSMresult_t release_session(HttpServerSession *to_release);
00139   void purge_keepalives();
00140   void init();
00141   int main_handler(int event, void *data);
00142 
00143 private:
00144   /// Global pool, used if not per thread pools.
00145   /// @internal We delay creating this because the session manager is created during global statics init.
00146   ServerSessionPool* m_g_pool;
00147 };
00148 
00149 extern HttpSessionManager httpSessionManager;
00150 
00151 #endif

Generated by  doxygen 1.7.1