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

HttpServerSession.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    HttpServerSession.h
00027 
00028    Description:
00029 
00030 
00031  ****************************************************************************/
00032 
00033 #ifndef _HTTP_SERVER_SESSION_H_
00034 #define _HTTP_SERVER_SESSION_H_
00035 /* Enable LAZY_BUF_ALLOC to delay allocation of buffers until they
00036 * are actually required.
00037 * Enabling LAZY_BUF_ALLOC, stop Http code from allocation space
00038 * for header buffer and tunnel buffer. The allocation is done by
00039 * the net code in read_from_net when data is actually written into
00040 * the buffer. By allocating memory only when it is required we can
00041 * reduce the memory consumed by TS process.
00042 *
00043 * IMPORTANT NOTE: enable/disable LAZY_BUF_ALLOC in HttpSM.h as well.
00044 */
00045 #define LAZY_BUF_ALLOC
00046 
00047 #include "P_Net.h"
00048 
00049 #include "HttpConnectionCount.h"
00050 #include "HttpProxyAPIEnums.h"
00051 
00052 class HttpSM;
00053 class MIOBuffer;
00054 class IOBufferReader;
00055 
00056 enum HSS_State {
00057   HSS_INIT,
00058   HSS_ACTIVE,
00059   HSS_KA_CLIENT_SLAVE,
00060   HSS_KA_SHARED
00061 };
00062 
00063 enum {
00064   HTTP_SS_MAGIC_ALIVE = 0x0123FEED,
00065   HTTP_SS_MAGIC_DEAD = 0xDEADFEED
00066 };
00067 
00068 class HttpServerSession : public VConnection
00069 {
00070 public:
00071   HttpServerSession()
00072     : VConnection(NULL),
00073       hostname_hash(),
00074       con_id(0), transact_count(0),
00075       state(HSS_INIT), to_parent_proxy(false), server_trans_stat(0),
00076       private_session(false),
00077       sharing_match(TS_SERVER_SESSION_SHARING_MATCH_BOTH),
00078       sharing_pool(TS_SERVER_SESSION_SHARING_POOL_GLOBAL),
00079       enable_origin_connection_limiting(false),
00080       connection_count(NULL), read_buffer(NULL),
00081       server_vc(NULL), magic(HTTP_SS_MAGIC_DEAD), buf_reader(NULL)
00082     { 
00083       ink_zero(server_ip);
00084     }
00085 
00086   void destroy();
00087   void new_connection(NetVConnection *new_vc);
00088 
00089   void reset_read_buffer(void)
00090   {
00091     ink_assert(read_buffer->_writer);
00092     ink_assert(buf_reader != NULL);
00093     read_buffer->dealloc_all_readers();
00094     read_buffer->_writer = NULL;
00095     buf_reader = read_buffer->alloc_reader();
00096   }
00097 
00098   IOBufferReader *get_reader()
00099   {
00100     return buf_reader;
00101   };
00102 
00103   virtual VIO *do_io_read(Continuation *c, int64_t nbytes = INT64_MAX, MIOBuffer *buf = 0);
00104 
00105   virtual VIO *do_io_write(Continuation *c = NULL, int64_t nbytes = INT64_MAX, IOBufferReader *buf = 0, bool owner = false);
00106 
00107   virtual void do_io_close(int lerrno = -1);
00108   virtual void do_io_shutdown(ShutdownHowTo_t howto);
00109 
00110   virtual void reenable(VIO *vio);
00111 
00112   void release();
00113   void attach_hostname(const char *hostname);
00114   NetVConnection *get_netvc()
00115   {
00116     return server_vc;
00117   };
00118 
00119   // Keys for matching hostnames
00120   IpEndpoint server_ip;
00121   INK_MD5 hostname_hash;
00122 
00123   int64_t con_id;
00124   int transact_count;
00125   HSS_State state;
00126 
00127   // Used to determine whether the session is for parent proxy
00128   // it is session to orgin server
00129   // We need to determine whether a closed connection was to
00130   // close parent proxy to update the
00131   // proxy.process.http.current_parent_proxy_connections
00132   bool to_parent_proxy;
00133 
00134   // Used to verify we are recording the server
00135   //   transaction stat properly
00136   int server_trans_stat;
00137 
00138   // Sessions become if authentication headers
00139   //  are sent over them
00140   bool private_session;
00141 
00142   // Copy of the owning SM's server session sharing settings
00143   TSServerSessionSharingMatchType sharing_match;
00144   TSServerSessionSharingPoolType sharing_pool;
00145   //  int share_session;
00146 
00147   LINK(HttpServerSession, ip_hash_link);
00148   LINK(HttpServerSession, host_hash_link);
00149 
00150   // Keep track of connection limiting and a pointer to the
00151   // singleton that keeps track of the connection counts.
00152   bool enable_origin_connection_limiting;
00153   ConnectionCount *connection_count;
00154 
00155   // The ServerSession owns the following buffer which use
00156   //   for parsing the headers.  The server session needs to
00157   //   own the buffer so we can go from a keep-alive state
00158   //   to being acquired and parsing the header without
00159   //   changing the buffer we are doing I/O on.  We can
00160   //   not change the buffer for I/O without issuing a
00161   //   an asyncronous cancel on NT
00162   MIOBuffer *read_buffer;
00163 
00164 private:
00165   HttpServerSession(HttpServerSession &);
00166 
00167   NetVConnection *server_vc;
00168   int magic;
00169 
00170   IOBufferReader *buf_reader;
00171 };
00172 
00173 extern ClassAllocator<HttpServerSession> httpServerSessionAllocator;
00174 
00175 inline void
00176 HttpServerSession::attach_hostname(const char *hostname)
00177 {
00178   if (CRYPTO_HASH_ZERO == hostname_hash) {
00179     ink_code_md5((unsigned char *) hostname, strlen(hostname), (unsigned char *) &hostname_hash);
00180   }
00181 }
00182 #endif

Generated by  doxygen 1.7.1