Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
h2_mplx.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_mplx__
18 #define __mod_h2__h2_mplx__
19 
38 struct apr_pool_t;
39 struct apr_thread_mutex_t;
40 struct apr_thread_cond_t;
41 struct h2_bucket_beam;
42 struct h2_config;
43 struct h2_ihash_t;
44 struct h2_task;
45 struct h2_stream;
46 struct h2_request;
47 struct apr_thread_cond_t;
48 struct h2_workers;
49 struct h2_iqueue;
50 struct h2_ngn_shed;
51 struct h2_req_engine;
52 
53 #include <apr_queue.h>
54 
55 typedef struct h2_mplx h2_mplx;
56 
57 struct h2_mplx {
58  long id;
61  server_rec *s; /* server for master conn */
62 
63  unsigned int event_pending;
64  unsigned int aborted;
65  unsigned int is_registered; /* is registered at h2_workers */
66 
67  struct h2_ihash_t *streams; /* all streams currently processing */
68  struct h2_ihash_t *sredo; /* all streams that need to be re-started */
69  struct h2_ihash_t *shold; /* all streams done with task ongoing */
70  struct h2_ihash_t *spurge; /* all streams done, ready for destroy */
71 
72  struct h2_iqueue *q; /* all stream ids that need to be started */
73  struct h2_ififo *readyq; /* all stream ids ready for output */
74 
75  struct h2_ihash_t *redo_tasks; /* all tasks that need to be redone */
76 
77  int max_streams; /* max # of concurrent streams */
78  int max_stream_started; /* highest stream id that started processing */
79  int tasks_active; /* # of tasks being processed from this mplx */
80  int limit_active; /* current limit on active tasks, dynamic */
81  int max_active; /* max, hard limit # of active tasks in a process */
82  apr_time_t last_idle_block; /* last time, this mplx entered IDLE while
83  * streams were ready */
84  apr_time_t last_limit_change; /* last time, worker limit changed */
86 
91 
93 
95  apr_array_header_t *spare_slaves; /* spare slave connections */
96 
98 
100 };
101 
102 
103 
104 /*******************************************************************************
105  * Object lifecycle and information.
106  ******************************************************************************/
107 
109 
115  const struct h2_config *conf,
116  struct h2_workers *workers);
117 
126 void h2_mplx_release_and_join(h2_mplx *m, struct apr_thread_cond_t *wait);
127 
128 apr_status_t h2_mplx_pop_task(h2_mplx *m, struct h2_task **ptask);
129 
130 void h2_mplx_task_done(h2_mplx *m, struct h2_task *task, struct h2_task **ptask);
131 
137 int h2_mplx_shutdown(h2_mplx *m);
138 
139 int h2_mplx_is_busy(h2_mplx *m);
140 
141 /*******************************************************************************
142  * IO lifetime of streams.
143  ******************************************************************************/
144 
145 struct h2_stream *h2_mplx_stream_get(h2_mplx *m, int id);
146 
155 
161  struct apr_thread_cond_t *iowait);
162 
164 
165 /*******************************************************************************
166  * Stream processing.
167  ******************************************************************************/
168 
178 apr_status_t h2_mplx_process(h2_mplx *m, struct h2_stream *stream,
179  h2_stream_pri_cmp *cmp, void *ctx);
180 
189 
190 typedef apr_status_t stream_ev_callback(void *ctx, struct h2_stream *stream);
191 
197 
205  stream_ev_callback *on_resume,
206  void *ctx);
207 
209 
210 typedef int h2_mplx_stream_cb(struct h2_stream *s, void *ctx);
211 
213 
214 /*******************************************************************************
215  * Output handling of streams.
216  ******************************************************************************/
217 
221 apr_status_t h2_mplx_out_open(h2_mplx *mplx, int stream_id,
222  struct h2_bucket_beam *beam);
223 
224 /*******************************************************************************
225  * h2_mplx list Manipulation.
226  ******************************************************************************/
227 
233 #define H2_MPLX_LIST_SENTINEL(b) APR_RING_SENTINEL((b), h2_mplx, link)
234 
240 #define H2_MPLX_LIST_EMPTY(b) APR_RING_EMPTY((b), h2_mplx, link)
241 
247 #define H2_MPLX_LIST_FIRST(b) APR_RING_FIRST(b)
248 
254 #define H2_MPLX_LIST_LAST(b) APR_RING_LAST(b)
255 
261 #define H2_MPLX_LIST_INSERT_HEAD(b, e) do { \
262 h2_mplx *ap__b = (e); \
263 APR_RING_INSERT_HEAD((b), ap__b, h2_mplx, link); \
264 } while (0)
265 
271 #define H2_MPLX_LIST_INSERT_TAIL(b, e) do { \
272 h2_mplx *ap__b = (e); \
273 APR_RING_INSERT_TAIL((b), ap__b, h2_mplx, link); \
274 } while (0)
275 
281 #define H2_MPLX_NEXT(e) APR_RING_NEXT((e), link)
282 
287 #define H2_MPLX_PREV(e) APR_RING_PREV((e), link)
288 
293 #define H2_MPLX_REMOVE(e) APR_RING_REMOVE((e), link)
294 
295 /*******************************************************************************
296  * h2_mplx DoS protection
297  ******************************************************************************/
298 
305 
306 /*******************************************************************************
307  * h2_req_engine handling
308  ******************************************************************************/
309 
310 typedef void h2_output_consumed(void *ctx, conn_rec *c, apr_off_t consumed);
312  const char *id,
313  const char *type,
314  apr_pool_t *pool,
315  apr_size_t req_buffer_size,
316  request_rec *r,
317  h2_output_consumed **pconsumed,
318  void **pbaton);
319 
320 apr_status_t h2_mplx_req_engine_push(const char *ngn_type,
321  request_rec *r,
322  h2_mplx_req_engine_init *einit);
324  apr_read_type_e block,
325  int capacity,
326  request_rec **pr);
327 void h2_mplx_req_engine_done(struct h2_req_engine *ngn, conn_rec *r_conn,
329 
330 #endif /* defined(__mod_h2__h2_mplx__) */
struct apr_thread_cond_t * join_wait
Definition: h2_mplx.h:90
int h2_mplx_shutdown(h2_mplx *m)
size_t apr_size_t
Definition: apr.h:375
struct h2_req_engine h2_req_engine
Definition: mod_http2.h:38
struct h2_ihash_t * spurge
Definition: h2_mplx.h:70
apr_array_header_t * spare_slaves
Definition: h2_mplx.h:95
apr_status_t stream_ev_callback(void *ctx, struct h2_stream *stream)
Definition: h2_mplx.h:190
apr_status_t h2_mplx_process(h2_mplx *m, struct h2_stream *stream, h2_stream_pri_cmp *cmp, void *ctx)
Definition: h2_task.h:53
Definition: h2_mplx.h:57
Definition: apr_arch_thread_mutex.h:28
Definition: apr_tables.h:62
conn_rec * c
Definition: h2_ngn_shed.h:25
apr_time_t last_idle_block
Definition: h2_mplx.h:82
apr_pool_t * spare_io_pool
Definition: h2_mplx.h:94
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:552
apr_size_t stream_max_mem
Definition: h2_mplx.h:92
int max_stream_started
Definition: h2_mplx.h:78
unsigned int aborted
Definition: h2_mplx.h:64
Definition: h2.h:133
Thread Safe FIFO bounded queue.
Definition: h2_bucket_beam.h:164
void h2_mplx_task_done(h2_mplx *m, struct h2_task *task, struct h2_task **ptask)
void h2_mplx_req_engine_done(struct h2_req_engine *ngn, conn_rec *r_conn, apr_status_t status)
struct h2_ififo h2_ififo
Definition: h2_util.h:267
struct h2_ihash_t * sredo
Definition: h2_mplx.h:68
Definition: h2_config.h:57
apr_status_t h2_mplx_out_open(h2_mplx *mplx, int stream_id, struct h2_bucket_beam *beam)
apr_status_t h2_mplx_idle(h2_mplx *m)
apr_int64_t apr_interval_time_t
Definition: apr_time.h:55
int h2_mplx_awaits_data(h2_mplx *m)
struct h2_workers * workers
Definition: h2_mplx.h:97
apr_thread_mutex_t * lock
Definition: h2_mplx.h:87
Structure to store things which are per connection.
Definition: httpd.h:1123
struct h2_ihash_t * shold
Definition: h2_mplx.h:69
void h2_output_consumed(void *ctx, conn_rec *c, apr_off_t consumed)
Definition: h2_mplx.h:310
struct h2_stream * h2_mplx_stream_get(h2_mplx *m, int id)
apr_status_t h2_mplx_keep_active(h2_mplx *m, struct h2_stream *stream)
apr_status_t h2_mplx_reprioritize(h2_mplx *m, h2_stream_pri_cmp *cmp, void *ctx)
apr_int64_t apr_time_t
Definition: apr_time.h:45
apr_status_t h2_mplx_child_init(apr_pool_t *pool, server_rec *s)
apr_pool_t * pool
Definition: h2_mplx.h:60
unsigned int is_registered
Definition: h2_mplx.h:65
apr_status_t h2_mplx_dispatch_master_events(h2_mplx *m, stream_ev_callback *on_resume, void *ctx)
A structure to store information for each virtual server.
Definition: httpd.h:1310
apr_status_t h2_mplx_out_trywait(h2_mplx *m, apr_interval_time_t timeout, struct apr_thread_cond_t *iowait)
apr_status_t h2_mplx_stream_do(h2_mplx *m, h2_mplx_stream_cb *cb, void *ctx)
int tasks_active
Definition: h2_mplx.h:79
apr_status_t h2_mplx_pop_task(h2_mplx *m, struct h2_task **ptask)
Definition: h2_ngn_shed.h:24
int max_active
Definition: h2_mplx.h:81
struct h2_ihash_t h2_ihash_t
Definition: h2_util.h:42
Definition: h2_stream.h:65
struct apr_thread_cond_t * added_output
Definition: h2_mplx.h:88
apr_status_t h2_mplx_stream_cleanup(h2_mplx *m, struct h2_stream *stream)
apr_status_t h2_mplx_req_engine_push(const char *ngn_type, request_rec *r, h2_mplx_req_engine_init *einit)
h2_mplx * h2_mplx_create(conn_rec *c, apr_pool_t *master, const struct h2_config *conf, struct h2_workers *workers)
int limit_active
Definition: h2_mplx.h:80
struct h2_ngn_shed * ngn_shed
Definition: h2_mplx.h:99
unsigned int event_pending
Definition: h2_mplx.h:63
int h2_stream_pri_cmp(int stream_id1, int stream_id2, void *ctx)
Definition: h2.h:157
apr_read_type_e
Definition: apr_buckets.h:57
struct h2_iqueue * q
Definition: h2_mplx.h:72
struct h2_ihash_t * redo_tasks
Definition: h2_mplx.h:75
A structure that represents the current request.
Definition: httpd.h:810
apr_interval_time_t limit_change_interval
Definition: h2_mplx.h:85
struct h2_ihash_t * streams
Definition: h2_mplx.h:67
apr_status_t h2_mplx_req_engine_init(struct h2_req_engine *engine, const char *id, const char *type, apr_pool_t *pool, apr_size_t req_buffer_size, request_rec *r, h2_output_consumed **pconsumed, void **pbaton)
Definition: h2_mplx.h:311
int status
Definition: mod_dav.h:141
struct apr_thread_cond_t * task_thawed
Definition: h2_mplx.h:89
conn_rec * c
Definition: h2_mplx.h:59
long id
Definition: h2_mplx.h:58
struct h2_ififo * readyq
Definition: h2_mplx.h:73
Definition: h2_util.h:76
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
int apr_status_t
Definition: apr_errno.h:44
request_rec * r
Definition: mod_dav.h:515
int h2_mplx_stream_cb(struct h2_stream *s, void *ctx)
Definition: h2_mplx.h:210
int h2_mplx_is_busy(h2_mplx *m)
int h2_mplx_has_master_events(h2_mplx *m)
int max_streams
Definition: h2_mplx.h:77
Definition: apr_arch_thread_cond.h:34
proxy_worker proxy_server_conf * conf
Definition: mod_proxy.h:611
Definition: h2_workers.h:36
apr_time_t last_limit_change
Definition: h2_mplx.h:84
void h2_mplx_release_and_join(h2_mplx *m, struct apr_thread_cond_t *wait)
off_t apr_off_t
Definition: apr.h:377
server_rec * s
Definition: h2_mplx.h:61
apr_status_t h2_mplx_req_engine_pull(struct h2_req_engine *ngn, apr_read_type_e block, int capacity, request_rec **pr)