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 #include "ink_config.h"
00032 #include "Allocator.h"
00033 #include "HttpServerSession.h"
00034 #include "HttpSessionManager.h"
00035 #include "HttpSM.h"
00036
00037 static int64_t next_ss_id = (int64_t) 0;
00038 ClassAllocator<HttpServerSession> httpServerSessionAllocator("httpServerSessionAllocator");
00039
00040
00041 void
00042 HttpServerSession::destroy()
00043 {
00044 ink_release_assert(server_vc == NULL);
00045 ink_assert(read_buffer);
00046 ink_assert(server_trans_stat == 0);
00047 magic = HTTP_SS_MAGIC_DEAD;
00048 if (read_buffer) {
00049 free_MIOBuffer(read_buffer);
00050 read_buffer = NULL;
00051 }
00052
00053 mutex.clear();
00054 if (TS_SERVER_SESSION_SHARING_POOL_THREAD == sharing_pool)
00055 THREAD_FREE(this, httpServerSessionAllocator, this_thread());
00056 else
00057 httpServerSessionAllocator.free(this);
00058 }
00059
00060 void
00061 HttpServerSession::new_connection(NetVConnection *new_vc)
00062 {
00063 ink_assert(new_vc != NULL);
00064 server_vc = new_vc;
00065
00066
00067 mutex = new_vc->mutex;
00068
00069
00070 con_id = ink_atomic_increment((int64_t *) (&next_ss_id), 1);
00071
00072 magic = HTTP_SS_MAGIC_ALIVE;
00073 HTTP_SUM_GLOBAL_DYN_STAT(http_current_server_connections_stat, 1);
00074 HTTP_INCREMENT_DYN_STAT(http_total_server_connections_stat);
00075
00076
00077 if (enable_origin_connection_limiting == true) {
00078 if (connection_count == NULL)
00079 connection_count = ConnectionCount::getInstance();
00080 connection_count->incrementCount(server_ip);
00081 char addrbuf[INET6_ADDRSTRLEN];
00082 Debug("http_ss", "[%" PRId64 "] new connection, ip: %s, count: %u",
00083 con_id,
00084 ats_ip_ntop(&server_ip.sa, addrbuf, sizeof(addrbuf)), connection_count->getCount(server_ip));
00085 }
00086 #ifdef LAZY_BUF_ALLOC
00087 read_buffer = new_empty_MIOBuffer(HTTP_SERVER_RESP_HDR_BUFFER_INDEX);
00088 #else
00089 read_buffer = new_MIOBuffer(HTTP_SERVER_RESP_HDR_BUFFER_INDEX);
00090 #endif
00091 buf_reader = read_buffer->alloc_reader();
00092 Debug("http_ss", "[%" PRId64 "] session born, netvc %p", con_id, new_vc);
00093 state = HSS_INIT;
00094 }
00095
00096 VIO *
00097 HttpServerSession::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
00098 {
00099 return server_vc->do_io_read(c, nbytes, buf);
00100 }
00101
00102 VIO *
00103 HttpServerSession::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner)
00104 {
00105 return server_vc->do_io_write(c, nbytes, buf, owner);
00106 }
00107
00108 void
00109 HttpServerSession::do_io_shutdown(ShutdownHowTo_t howto)
00110 {
00111 server_vc->do_io_shutdown(howto);
00112 }
00113
00114 void
00115 HttpServerSession::do_io_close(int alerrno)
00116 {
00117 if (state == HSS_ACTIVE) {
00118 HTTP_DECREMENT_DYN_STAT(http_current_server_transactions_stat);
00119 this->server_trans_stat--;
00120 }
00121
00122 Debug("http_ss", "[%" PRId64 "] session closing, netvc %p", con_id, server_vc);
00123
00124 server_vc->do_io_close(alerrno);
00125 server_vc = NULL;
00126
00127 HTTP_SUM_GLOBAL_DYN_STAT(http_current_server_connections_stat, -1);
00128 HTTP_SUM_DYN_STAT(http_transactions_per_server_con, transact_count);
00129
00130
00131
00132 if (enable_origin_connection_limiting == true) {
00133 if (connection_count->getCount(server_ip) > 0) {
00134 connection_count->incrementCount(server_ip, -1);
00135 char addrbuf[INET6_ADDRSTRLEN];
00136 Debug("http_ss", "[%" PRId64 "] connection closed, ip: %s, count: %u",
00137 con_id,
00138 ats_ip_ntop(&server_ip.sa, addrbuf, sizeof(addrbuf)),
00139 connection_count->getCount(server_ip));
00140 } else {
00141 Error("[%" PRId64 "] number of connections should be greater than zero: %u",
00142 con_id, connection_count->getCount(server_ip));
00143 }
00144 }
00145
00146 if (to_parent_proxy) {
00147 HTTP_DECREMENT_DYN_STAT(http_current_parent_proxy_connections_stat);
00148 }
00149 destroy();
00150 }
00151
00152 void
00153 HttpServerSession::reenable(VIO *vio)
00154 {
00155 server_vc->reenable(vio);
00156 }
00157
00158
00159
00160
00161
00162 void
00163 HttpServerSession::release()
00164 {
00165 Debug("http_ss", "Releasing session, private_session=%d, sharing_match=%d", private_session, sharing_match);
00166
00167 state = HSS_KA_SHARED;
00168
00169
00170 if (private_session || TS_SERVER_SESSION_SHARING_MATCH_NONE == sharing_match) {
00171 this->do_io_close();
00172 return;
00173 }
00174
00175 HSMresult_t r = httpSessionManager.release_session(this);
00176
00177
00178 if (r == HSM_RETRY) {
00179
00180
00181
00182 this->do_io_close();
00183 } else {
00184
00185
00186
00187 ink_assert(r == HSM_DONE);
00188 }
00189 }