3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
/****************************************************************************
31
****************************************************************************/
33
#include "ink_config.h"
34
#include "Allocator.h"
35
#include "HttpServerSession.h"
36
#include "HttpSessionManager.h"
39
static int64_t next_ss_id = (int64_t) 0;
40
ClassAllocator<HttpServerSession> httpServerSessionAllocator("httpServerSessionAllocator");
43
HttpServerSession::destroy()
45
ink_release_assert(server_vc == NULL);
46
ink_assert(read_buffer);
47
ink_assert(server_trans_stat == 0);
48
magic = HTTP_SS_MAGIC_DEAD;
50
free_MIOBuffer(read_buffer);
55
httpServerSessionAllocator.free(this);
59
HttpServerSession::allocate()
66
HttpServerSession::new_connection(NetVConnection * new_vc)
68
ink_assert(new_vc != NULL);
71
#ifdef TRANSACTION_ON_A_THREAD
72
mutex = new_vc->thread->mutex;
74
mutex = new_vc->mutex;
77
// Unique client session identifier.
78
con_id = ink_atomic_increment64((int64_t *) (&next_ss_id), 1);
80
magic = HTTP_SS_MAGIC_ALIVE;
81
HTTP_SUM_GLOBAL_DYN_STAT(http_current_server_connections_stat, 1); // Update the true global stat
82
HTTP_INCREMENT_DYN_STAT(http_total_server_connections_stat);
83
// Check to see if we are limiting the number of connections
85
if (enable_origin_connection_limiting == true) {
86
if (connection_count == NULL)
87
connection_count = ConnectionCount::getInstance();
88
connection_count->incrementCount(server_ip);
89
Debug("http_ss", "[%" PRId64 "] new connection, ip: %u, count: %u", con_id, server_ip, connection_count->getCount(server_ip));
92
read_buffer = new_empty_MIOBuffer(HTTP_SERVER_RESP_HDR_BUFFER_INDEX);
94
read_buffer = new_MIOBuffer(HTTP_SERVER_RESP_HDR_BUFFER_INDEX);
96
buf_reader = read_buffer->alloc_reader();
97
Debug("http_ss", "[%" PRId64 "] session born, netvc %p", con_id, new_vc);
102
HttpServerSession::do_io_read(Continuation * c, int64_t nbytes, MIOBuffer * buf)
104
return server_vc->do_io_read(c, nbytes, buf);
108
HttpServerSession::do_io_write(Continuation * c, int64_t nbytes, IOBufferReader * buf, bool owner)
110
return server_vc->do_io_write(c, nbytes, buf, owner);
114
HttpServerSession::do_io_shutdown(ShutdownHowTo_t howto)
116
server_vc->do_io_shutdown(howto);
120
HttpServerSession::do_io_close(int alerrno)
122
if (state == HSS_ACTIVE) {
123
HTTP_DECREMENT_DYN_STAT(http_current_server_transactions_stat);
124
this->server_trans_stat--;
127
server_vc->do_io_close(alerrno);
128
Debug("http_ss", "[%" PRId64 "] session closed", con_id);
131
HTTP_SUM_GLOBAL_DYN_STAT(http_current_server_connections_stat, -1); // Make sure to work on the global stat
132
HTTP_SUM_DYN_STAT(http_transactions_per_server_con, transact_count);
134
// Check to see if we are limiting the number of connections
136
if (enable_origin_connection_limiting == true) {
137
if (connection_count->getCount(server_ip) > 0) {
138
connection_count->incrementCount(server_ip, -1);
139
Debug("http_ss", "[%" PRId64 "] connection closed, ip: %u, count: %u",
140
con_id, server_ip, connection_count->getCount(server_ip));
142
Error("http_ss", "[%" PRId64 "] number of connections should be greater then zero: %u",
143
con_id, connection_count->getCount(server_ip));
147
if (to_parent_proxy) {
148
HTTP_DECREMENT_DYN_STAT(http_current_parent_proxy_connections_stat);
154
HttpServerSession::reenable(VIO * vio)
156
server_vc->reenable(vio);
159
// void HttpServerSession::release()
161
// Releases the session for K-A reuse
164
HttpServerSession::release()
166
// Set our state to KA for stat issues
167
state = HSS_KA_SHARED;
169
// Private sessions are never released back to the shared pool
170
if (private_session || HttpConfig::m_master.share_server_sessions == 0) {
175
HSMresult_t r = httpSessionManager.release_session(this);
177
if (r == HSM_RETRY) {
178
// Session could not be put in the session manager
179
// due to lock contention
180
// FIX: should retry instead of closing
183
// The session was successfully put into the session
184
// manager and it will manage it
185
// (Note: should never get HSM_NOT_FOUND here)
186
ink_assert(r == HSM_DONE);