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  apr_pool_t *pool; /* pool to use in session */
84  struct h2_mplx *mplx; /* multiplexer for stream data */
85  struct h2_workers *workers; /* for executing stream tasks */
86  struct h2_filter_cin *cin; /* connection input filter context */
87  h2_conn_io io; /* io on httpd conn filters */
88  int padding_max; /* max number of padding bytes */
89  int padding_always; /* padding has precedence over I/O optimizations */
90  struct nghttp2_session *ngh2; /* the nghttp2 session (internal use) */
91 
92  h2_session_state state; /* state session is in */
93 
94  h2_session_props local; /* properties of local session */
95  h2_session_props remote; /* properites of remote session */
96 
97  unsigned int reprioritize : 1; /* scheduled streams priority changed */
98  unsigned int flush : 1; /* flushing output necessary */
99  unsigned int have_read : 1; /* session has read client data */
100  unsigned int have_written : 1; /* session did write data to client */
101  apr_interval_time_t wait_us; /* timeout during BUSY_WAIT state, micro secs */
102 
103  struct h2_push_diary *push_diary; /* remember pushes, avoid duplicates */
104 
105  struct h2_stream_monitor *monitor;/* monitor callbacks for streams */
106  int open_streams; /* number of client streams open */
107  int unsent_submits; /* number of submitted, but not yet written responses. */
108  int unsent_promises; /* number of submitted, but not yet written push promises */
109 
110  int responses_submitted; /* number of http/2 responses submitted */
111  int streams_reset; /* number of http/2 streams reset by client */
112  int pushes_promised; /* number of http/2 push promises submitted */
113  int pushes_submitted; /* number of http/2 pushed responses submitted */
114  int pushes_reset; /* number of http/2 pushed reset by client */
115 
116  apr_size_t frames_received; /* number of http/2 frames received */
117  apr_size_t frames_sent; /* number of http/2 frames sent */
118 
119  apr_size_t max_stream_count; /* max number of open streams */
120  apr_size_t max_stream_mem; /* max buffer memory for a single stream */
121 
122  apr_time_t idle_until; /* Time we shut down due to sheer boredom */
123  apr_time_t idle_sync_until; /* Time we sync wait until keepalive handling kicks in */
124  apr_size_t idle_frames; /* number of rcvd frames that kept session in idle state */
125  apr_interval_time_t idle_delay; /* Time we delay processing rcvd frames in idle state */
126 
127  apr_bucket_brigade *bbtmp; /* brigade for keeping temporary data */
128  struct apr_thread_cond_t *iowait; /* our cond when trywaiting for data */
129 
130  char status[64]; /* status message for scoreboard */
131  int last_status_code; /* the one already reported */
132  const char *last_status_msg; /* the one already reported */
133 
134  struct h2_iqueue *in_pending; /* all streams with input pending */
135  struct h2_iqueue *in_process; /* all streams ready for processing on a secondary */
136 
137 } h2_session;
138 
139 const char *h2_session_state_str(h2_session_state state);
140 
152  conn_rec *c, request_rec *r, server_rec *,
153  struct h2_workers *workers);
154 
156  int err, const char *msg);
157 
164 apr_status_t h2_session_process(h2_session *session, int async);
165 
169 apr_status_t h2_session_pre_close(h2_session *session, int async);
170 
177 void h2_session_abort(h2_session *session, apr_status_t reason);
178 
182 void h2_session_close(h2_session *session);
183 
188 int h2_session_push_enabled(h2_session *session);
189 
200  struct h2_stream *is, struct h2_push *push);
201 
203  struct h2_stream *stream,
204  const struct h2_priority *prio);
205 
206 #define H2_SSSN_MSG(s, msg) \
207  "h2_session(%ld,%s,%d): "msg, s->id, h2_session_state_str(s->state), \
208  s->open_streams
209 
210 #define H2_SSSN_LOG(aplogno, s, msg) aplogno H2_SSSN_MSG(s, msg)
211 
212 #endif /* defined(__mod_h2__h2_session__) */
int unsent_submits
Definition: h2_session.h:107
int pushes_submitted
Definition: h2_session.h:113
size_t apr_size_t
Definition: apr.h:393
struct nghttp2_session * ngh2
Definition: h2_session.h:90
apr_size_t max_stream_mem
Definition: h2_session.h:120
Definition: h2_session.h:65
apr_size_t max_stream_count
Definition: h2_session.h:119
Definition: h2_task.h:52
char status[64]
Definition: h2_session.h:130
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:86
request_rec * r
Definition: h2_session.h:80
Definition: h2_session.h:63
struct h2_iqueue * in_process
Definition: h2_session.h:135
Definition: h2_session.h:73
int pushes_reset
Definition: h2_session.h:114
struct h2_stream_monitor * monitor
Definition: h2_session.h:105
Definition: h2_session.h:66
apr_size_t frames_received
Definition: h2_session.h:116
apr_interval_time_t wait_us
Definition: h2_session.h:101
Definition: h2.h:75
Definition: h2_session.h:67
struct h2_push_diary * push_diary
Definition: h2_session.h:103
Definition: h2_push.h:28
apr_status_t h2_session_process(h2_session *session, int async)
h2_session_state state
Definition: h2_session.h:92
apr_bucket_brigade * bbtmp
Definition: h2_session.h:127
apr_status_t h2_session_create(h2_session **psession, conn_rec *c, request_rec *r, server_rec *, struct h2_workers *workers)
Definition: h2_conn_io.h:29
apr_size_t idle_frames
Definition: h2_session.h:124
Definition: h2_session.h:64
Definition: h2_session.h:72
Definition: apr_buckets.h:258
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:1183
int streams_reset
Definition: h2_session.h:111
int padding_always
Definition: h2_session.h:89
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:117
A structure to store information for each virtual server.
Definition: httpd.h:1370
unsigned int flush
Definition: h2_session.h:98
dav_error * err
Definition: mod_dav.h:203
int h2_session_push_enabled(h2_session *session)
int responses_submitted
Definition: h2_session.h:110
void h2_session_abort(h2_session *session, apr_status_t reason)
struct h2_ihash_t h2_ihash_t
Definition: h2_util.h:42
unsigned int have_written
Definition: h2_session.h:100
apr_pool_t * pool
Definition: h2_session.h:83
Definition: h2_stream.h:65
struct apr_thread_cond_t * iowait
Definition: h2_session.h:128
apr_time_t idle_until
Definition: h2_session.h:122
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:131
conn_rec * c
Definition: h2_session.h:79
Definition: h2_push.h:80
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:85
int open_streams
Definition: h2_session.h:106
const char * last_status_msg
Definition: h2_session.h:132
apr_interval_time_t idle_delay
Definition: h2_session.h:125
Definition: h2_session.h:68
unsigned int have_read
Definition: h2_session.h:99
A structure that represents the current request.
Definition: httpd.h:860
struct h2_iqueue * in_pending
Definition: h2_session.h:134
struct h2_session h2_session
Definition: h2_stream.h:54
Definition: h2_session.h:62
h2_conn_io io
Definition: h2_session.h:87
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:108
h2_session_props local
Definition: h2_session.h:94
apr_time_t idle_sync_until
Definition: h2_session.h:123
int apr_status_t
Definition: apr_errno.h:44
Definition: h2_session.h:70
request_rec * r
Definition: mod_dav.h:518
Definition: h2_session.h:71
Definition: apr_arch_thread_cond.h:34
int pushes_promised
Definition: h2_session.h:112
h2_session_props remote
Definition: h2_session.h:95
Definition: h2_workers.h:36
int padding_max
Definition: h2_session.h:88
void h2_session_close(h2_session *session)
struct h2_mplx * mplx
Definition: h2_session.h:84
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:97
Definition: h2_filter.h:25