Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
h2_session.h
Go to the documentation of this file.
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __mod_h2__h2_session__
18 #define __mod_h2__h2_session__
19 
20 #include "h2_conn_io.h"
21 
41 #include "h2.h"
42 
43 struct apr_thread_mutext_t;
44 struct apr_thread_cond_t;
45 struct h2_ctx;
46 struct h2_config;
47 struct h2_filter_cin;
48 struct h2_ihash_t;
49 struct h2_mplx;
50 struct h2_priority;
51 struct h2_push;
52 struct h2_push_diary;
53 struct h2_session;
54 struct h2_stream;
55 struct h2_stream_monitor;
56 struct h2_task;
57 struct h2_workers;
58 
59 struct nghttp2_session;
60 
61 typedef enum {
62  H2_SESSION_EV_INIT, /* session was initialized */
63  H2_SESSION_EV_LOCAL_GOAWAY, /* we send a GOAWAY */
64  H2_SESSION_EV_REMOTE_GOAWAY, /* remote send us a GOAWAY */
65  H2_SESSION_EV_CONN_ERROR, /* connection error */
66  H2_SESSION_EV_PROTO_ERROR, /* protocol error */
67  H2_SESSION_EV_CONN_TIMEOUT, /* connection timeout */
68  H2_SESSION_EV_NO_IO, /* nothing has been read or written */
69  H2_SESSION_EV_FRAME_RCVD, /* a frame has been received */
70  H2_SESSION_EV_NGH2_DONE, /* nghttp2 wants neither read nor write anything */
71  H2_SESSION_EV_MPM_STOPPING, /* the process is stopping */
72  H2_SESSION_EV_PRE_CLOSE, /* connection will close after this */
73  H2_SESSION_EV_STREAM_CHANGE, /* a stream (state/input/output) changed */
75 
76 typedef struct h2_session {
77  long id; /* identifier of this session, unique
78  * inside a httpd process */
79  conn_rec *c; /* the connection this session serves */
80  request_rec *r; /* the request that started this in case
81  * of 'h2c', NULL otherwise */
82  server_rec *s; /* server/vhost we're starting on */
83  const struct h2_config *config; /* Relevant config for this session */
84  apr_pool_t *pool; /* pool to use in session */
85  struct h2_mplx *mplx; /* multiplexer for stream data */
86  struct h2_workers *workers; /* for executing stream tasks */
87  struct h2_filter_cin *cin; /* connection input filter context */
88  h2_conn_io io; /* io on httpd conn filters */
89  struct nghttp2_session *ngh2; /* the nghttp2 session (internal use) */
90 
91  h2_session_state state; /* state session is in */
92 
93  h2_session_props local; /* properties of local session */
94  h2_session_props remote; /* properites of remote session */
95 
96  unsigned int reprioritize : 1; /* scheduled streams priority changed */
97  unsigned int flush : 1; /* flushing output necessary */
98  unsigned int have_read : 1; /* session has read client data */
99  unsigned int have_written : 1; /* session did write data to client */
100  apr_interval_time_t wait_us; /* timeout during BUSY_WAIT state, micro secs */
101 
102  struct h2_push_diary *push_diary; /* remember pushes, avoid duplicates */
103 
104  struct h2_stream_monitor *monitor;/* monitor callbacks for streams */
105  int open_streams; /* number of client streams open */
106  int unsent_submits; /* number of submitted, but not yet written responses. */
107  int unsent_promises; /* number of submitted, but not yet written push promises */
108 
109  int responses_submitted; /* number of http/2 responses submitted */
110  int streams_reset; /* number of http/2 streams reset by client */
111  int pushes_promised; /* number of http/2 push promises submitted */
112  int pushes_submitted; /* number of http/2 pushed responses submitted */
113  int pushes_reset; /* number of http/2 pushed reset by client */
114 
115  apr_size_t frames_received; /* number of http/2 frames received */
116  apr_size_t frames_sent; /* number of http/2 frames sent */
117 
118  apr_size_t max_stream_count; /* max number of open streams */
119  apr_size_t max_stream_mem; /* max buffer memory for a single stream */
120 
121  apr_time_t idle_until; /* Time we shut down due to sheer boredom */
122  apr_time_t idle_sync_until; /* Time we sync wait until keepalive handling kicks in */
123  apr_size_t idle_frames; /* number of rcvd frames that kept session in idle state */
124  apr_interval_time_t idle_delay; /* Time we delay processing rcvd frames in idle state */
125 
126  apr_bucket_brigade *bbtmp; /* brigade for keeping temporary data */
127  struct apr_thread_cond_t *iowait; /* our cond when trywaiting for data */
128 
129  char status[64]; /* status message for scoreboard */
130  int last_status_code; /* the one already reported */
131  const char *last_status_msg; /* the one already reported */
132 
133  struct h2_iqueue *in_pending; /* all streams with input pending */
134  struct h2_iqueue *in_process; /* all streams ready for processing on slave */
135 
136 } h2_session;
137 
138 const char *h2_session_state_str(h2_session_state state);
139 
150  conn_rec *c, struct h2_ctx *ctx,
151  struct h2_workers *workers);
152 
163  request_rec *r, struct h2_ctx *ctx,
164  struct h2_workers *workers);
165 
167  int err, const char *msg);
168 
175 apr_status_t h2_session_process(h2_session *session, int async);
176 
180 apr_status_t h2_session_pre_close(h2_session *session, int async);
181 
188 void h2_session_abort(h2_session *session, apr_status_t reason);
189 
193 void h2_session_close(h2_session *session);
194 
199 int h2_session_push_enabled(h2_session *session);
200 
211  struct h2_stream *is, struct h2_push *push);
212 
214  struct h2_stream *stream,
215  const struct h2_priority *prio);
216 
217 #define H2_SSSN_MSG(s, msg) \
218  "h2_session(%ld,%s,%d): "msg, s->id, h2_session_state_str(s->state), \
219  s->open_streams
220 
221 #define H2_SSSN_LOG(aplogno, s, msg) aplogno H2_SSSN_MSG(s, msg)
222 
223 #endif /* defined(__mod_h2__h2_session__) */
int unsent_submits
Definition: h2_session.h:106
int pushes_submitted
Definition: h2_session.h:112
size_t apr_size_t
Definition: apr.h:375
struct nghttp2_session * ngh2
Definition: h2_session.h:89
apr_size_t max_stream_mem
Definition: h2_session.h:119
Definition: h2_session.h:65
apr_size_t max_stream_count
Definition: h2_session.h:118
Definition: h2_task.h:53
char status[64]
Definition: h2_session.h:129
struct h2_session * session
Definition: h2_stream.h:69
Definition: h2_mplx.h:57
void h2_session_event(h2_session *session, h2_session_event_t ev, int err, const char *msg)
struct h2_filter_cin * cin
Definition: h2_session.h:87
request_rec * r
Definition: h2_session.h:80
Definition: h2_session.h:63
struct h2_iqueue * in_process
Definition: h2_session.h:134
Definition: h2_session.h:73
int pushes_reset
Definition: h2_session.h:113
struct h2_stream_monitor * monitor
Definition: h2_session.h:104
Definition: h2_session.h:66
apr_size_t frames_received
Definition: h2_session.h:115
apr_interval_time_t wait_us
Definition: h2_session.h:100
Definition: h2.h:75
Definition: h2_session.h:67
struct h2_push_diary * push_diary
Definition: h2_session.h:102
Definition: h2_push.h:28
apr_status_t h2_session_process(h2_session *session, int async)
h2_session_state state
Definition: h2_session.h:91
apr_bucket_brigade * bbtmp
Definition: h2_session.h:126
Definition: h2_conn_io.h:29
apr_size_t idle_frames
Definition: h2_session.h:123
Definition: h2_session.h:64
Definition: h2_session.h:72
Definition: apr_buckets.h:258
Definition: h2_config.h:57
apr_int64_t apr_interval_time_t
Definition: apr_time.h:55
apr_status_t h2_session_set_prio(h2_session *session, struct h2_stream *stream, const struct h2_priority *prio)
Structure to store things which are per connection.
Definition: httpd.h:1124
int streams_reset
Definition: h2_session.h:110
server_rec * s
Definition: h2_session.h:82
Definition: h2_ctx.h:32
apr_int64_t apr_time_t
Definition: apr_time.h:45
Definition: h2.h:96
apr_size_t frames_sent
Definition: h2_session.h:116
A structure to store information for each virtual server.
Definition: httpd.h:1311
unsigned int flush
Definition: h2_session.h:97
dav_error * err
Definition: mod_dav.h:203
int h2_session_push_enabled(h2_session *session)
int responses_submitted
Definition: h2_session.h:109
void h2_session_abort(h2_session *session, apr_status_t reason)
const struct h2_config * config
Definition: h2_session.h:83
struct h2_ihash_t h2_ihash_t
Definition: h2_util.h:42
unsigned int have_written
Definition: h2_session.h:99
apr_pool_t * pool
Definition: h2_session.h:84
Definition: h2_stream.h:65
struct apr_thread_cond_t * iowait
Definition: h2_session.h:127
apr_time_t idle_until
Definition: h2_session.h:121
struct h2_stream * h2_session_push(h2_session *session, struct h2_stream *is, struct h2_push *push)
int last_status_code
Definition: h2_session.h:130
conn_rec * c
Definition: h2_session.h:79
Definition: h2_push.h:42
const char * h2_session_state_str(h2_session_state state)
apr_status_t h2_session_pre_close(h2_session *session, int async)
struct h2_workers * workers
Definition: h2_session.h:86
int open_streams
Definition: h2_session.h:105
const char * last_status_msg
Definition: h2_session.h:131
apr_interval_time_t idle_delay
Definition: h2_session.h:124
Definition: h2_session.h:68
unsigned int have_read
Definition: h2_session.h:98
A structure that represents the current request.
Definition: httpd.h:811
struct h2_iqueue * in_pending
Definition: h2_session.h:133
struct h2_session h2_session
Definition: h2_stream.h:54
Definition: h2_session.h:62
h2_conn_io io
Definition: h2_session.h:88
h2_session_state
Definition: h2.h:87
Definition: h2_session.h:69
Definition: h2_util.h:76
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
int unsent_promises
Definition: h2_session.h:107
h2_session_props local
Definition: h2_session.h:93
apr_time_t idle_sync_until
Definition: h2_session.h:122
int apr_status_t
Definition: apr_errno.h:44
Definition: h2_session.h:70
request_rec * r
Definition: mod_dav.h:515
Definition: h2_session.h:71
Definition: apr_arch_thread_cond.h:34
int pushes_promised
Definition: h2_session.h:111
h2_session_props remote
Definition: h2_session.h:94
Definition: h2_workers.h:36
apr_status_t h2_session_create(h2_session **psession, conn_rec *c, struct h2_ctx *ctx, struct h2_workers *workers)
void h2_session_close(h2_session *session)
struct h2_mplx * mplx
Definition: h2_session.h:85
Definition: h2_session.h:76
h2_session_event_t
Definition: h2_session.h:61
long id
Definition: h2_session.h:77
unsigned int reprioritize
Definition: h2_session.h:96
apr_status_t h2_session_rcreate(h2_session **psession, request_rec *r, struct h2_ctx *ctx, struct h2_workers *workers)
Definition: h2_filter.h:25