~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/http2/HttpServerSession.cc

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
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
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
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.
 
22
 */
 
23
 
 
24
/****************************************************************************
 
25
 
 
26
   HttpServerSession.cc
 
27
 
 
28
   Description:
 
29
 
 
30
 
 
31
 ****************************************************************************/
 
32
 
 
33
#include "ink_config.h"
 
34
#include "Allocator.h"
 
35
#include "HttpServerSession.h"
 
36
#include "HttpSessionManager.h"
 
37
#include "HttpSM.h"
 
38
 
 
39
static int64_t next_ss_id = (int64_t) 0;
 
40
ClassAllocator<HttpServerSession> httpServerSessionAllocator("httpServerSessionAllocator");
 
41
 
 
42
void
 
43
HttpServerSession::destroy()
 
44
{
 
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;
 
49
  if (read_buffer) {
 
50
    free_MIOBuffer(read_buffer);
 
51
    read_buffer = NULL;
 
52
  }
 
53
 
 
54
  mutex.clear();
 
55
  httpServerSessionAllocator.free(this);
 
56
}
 
57
 
 
58
HttpServerSession *
 
59
HttpServerSession::allocate()
 
60
{
 
61
  ink_assert(0);
 
62
  return NULL;
 
63
}
 
64
 
 
65
void
 
66
HttpServerSession::new_connection(NetVConnection * new_vc)
 
67
{
 
68
  ink_assert(new_vc != NULL);
 
69
  server_vc = new_vc;
 
70
 
 
71
#ifdef TRANSACTION_ON_A_THREAD
 
72
  mutex = new_vc->thread->mutex;
 
73
#else
 
74
  mutex = new_vc->mutex;
 
75
#endif
 
76
 
 
77
  // Unique client session identifier.
 
78
  con_id = ink_atomic_increment64((int64_t *) (&next_ss_id), 1);
 
79
 
 
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
 
84
  // per host
 
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));
 
90
  }
 
91
#ifdef LAZY_BUF_ALLOC
 
92
  read_buffer = new_empty_MIOBuffer(HTTP_SERVER_RESP_HDR_BUFFER_INDEX);
 
93
#else
 
94
  read_buffer = new_MIOBuffer(HTTP_SERVER_RESP_HDR_BUFFER_INDEX);
 
95
#endif
 
96
  buf_reader = read_buffer->alloc_reader();
 
97
  Debug("http_ss", "[%" PRId64 "] session born, netvc %p", con_id, new_vc);
 
98
  state = HSS_INIT;
 
99
}
 
100
 
 
101
VIO *
 
102
HttpServerSession::do_io_read(Continuation * c, int64_t nbytes, MIOBuffer * buf)
 
103
{
 
104
  return server_vc->do_io_read(c, nbytes, buf);
 
105
}
 
106
 
 
107
VIO *
 
108
HttpServerSession::do_io_write(Continuation * c, int64_t nbytes, IOBufferReader * buf, bool owner)
 
109
{
 
110
  return server_vc->do_io_write(c, nbytes, buf, owner);
 
111
}
 
112
 
 
113
void
 
114
HttpServerSession::do_io_shutdown(ShutdownHowTo_t howto)
 
115
{
 
116
  server_vc->do_io_shutdown(howto);
 
117
}
 
118
 
 
119
void
 
120
HttpServerSession::do_io_close(int alerrno)
 
121
{
 
122
  if (state == HSS_ACTIVE) {
 
123
    HTTP_DECREMENT_DYN_STAT(http_current_server_transactions_stat);
 
124
    this->server_trans_stat--;
 
125
  }
 
126
 
 
127
  server_vc->do_io_close(alerrno);
 
128
  Debug("http_ss", "[%" PRId64 "] session closed", con_id);
 
129
  server_vc = NULL;
 
130
 
 
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);
 
133
 
 
134
  // Check to see if we are limiting the number of connections
 
135
  // per host
 
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));
 
141
    } else {
 
142
      Error("http_ss", "[%" PRId64 "] number of connections should be greater then zero: %u",
 
143
            con_id, connection_count->getCount(server_ip));
 
144
    }
 
145
  }
 
146
 
 
147
  if (to_parent_proxy) {
 
148
    HTTP_DECREMENT_DYN_STAT(http_current_parent_proxy_connections_stat);
 
149
  }
 
150
  destroy();
 
151
}
 
152
 
 
153
void
 
154
HttpServerSession::reenable(VIO * vio)
 
155
{
 
156
  server_vc->reenable(vio);
 
157
}
 
158
 
 
159
// void HttpServerSession::release()
 
160
//
 
161
//   Releases the session for K-A reuse
 
162
//
 
163
void
 
164
HttpServerSession::release()
 
165
{
 
166
  // Set our state to KA for stat issues
 
167
  state = HSS_KA_SHARED;
 
168
 
 
169
  // Private sessions are never released back to the shared pool
 
170
  if (private_session || HttpConfig::m_master.share_server_sessions == 0) {
 
171
    this->do_io_close();
 
172
    return;
 
173
  }
 
174
 
 
175
  HSMresult_t r = httpSessionManager.release_session(this);
 
176
 
 
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
 
181
    this->do_io_close();
 
182
  } else {
 
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);
 
187
  }
 
188
}