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

HttpServerSession.cc

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    HttpServerSession.cc
00027 
00028    Description:
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   // Used to do e.g. mutex = new_vc->thread->mutex; when per-thread pools enabled
00067   mutex = new_vc->mutex;
00068 
00069   // Unique client session identifier.
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); // Update the true global stat
00074   HTTP_INCREMENT_DYN_STAT(http_total_server_connections_stat);
00075   // Check to see if we are limiting the number of connections
00076   // per host
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); // Make sure to work on the global stat
00128   HTTP_SUM_DYN_STAT(http_transactions_per_server_con, transact_count);
00129 
00130   // Check to see if we are limiting the number of connections
00131   // per host
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 // void HttpServerSession::release()
00159 //
00160 //   Releases the session for K-A reuse
00161 //
00162 void
00163 HttpServerSession::release()
00164 {
00165   Debug("http_ss", "Releasing session, private_session=%d, sharing_match=%d", private_session, sharing_match);
00166   // Set our state to KA for stat issues
00167   state = HSS_KA_SHARED;
00168 
00169   // Private sessions are never released back to the shared pool
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     // Session could not be put in the session manager
00180     //  due to lock contention
00181     // FIX:  should retry instead of closing
00182     this->do_io_close();
00183   } else {
00184     // The session was successfully put into the session
00185     //    manager and it will manage it
00186     // (Note: should never get HSM_NOT_FOUND here)
00187     ink_assert(r == HSM_DONE);
00188   }
00189 }

Generated by  doxygen 1.7.1