Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00048
00049
00050
00051
00052
00053
00054
00055
00056 class ServerSessionPool: public Continuation
00057 {
00058 public:
00059
00060
00061 ServerSessionPool();
00062
00063 int eventHandler(int event, void *data);
00064 protected:
00065
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
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;
00092 typedef TSHashTable<HostHashing> HostHashTable;
00093
00094 public:
00095
00096
00097 static bool match(HttpServerSession* ss, sockaddr const* addr, INK_MD5 const& host_hash, TSServerSessionSharingMatchType match_style);
00098
00099
00100
00101
00102
00103
00104
00105
00106 HttpServerSession* acquireSession(sockaddr const* addr, INK_MD5 const& host_hash, TSServerSessionSharingMatchType match_style);
00107
00108
00109 void releaseSession(HttpServerSession* ss);
00110
00111
00112 void purge();
00113
00114
00115
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
00145
00146 ServerSessionPool* m_g_pool;
00147 };
00148
00149 extern HttpSessionManager httpSessionManager;
00150
00151 #endif