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 /* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8 
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __mod_h2__h2_mplx__
17 #define __mod_h2__h2_mplx__
18 
37 struct apr_pool_t;
38 struct apr_thread_mutex_t;
39 struct apr_thread_cond_t;
40 struct h2_bucket_beam;
41 struct h2_config;
42 struct h2_ihash_t;
43 struct h2_task;
44 struct h2_stream;
45 struct h2_request;
46 struct apr_thread_cond_t;
47 struct h2_workers;
48 struct h2_iqueue;
49 struct h2_ngn_shed;
50 struct h2_req_engine;
51 
52 #include <apr_queue.h>
53 
54 typedef struct h2_mplx h2_mplx;
55 
60 typedef void h2_mplx_consumed_cb(void *ctx, int stream_id, apr_off_t consumed);
61 
62 struct h2_mplx {
63  long id;
67 
68  APR_RING_ENTRY(h2_mplx) link;
69 
70  unsigned int aborted : 1;
71  unsigned int need_registration : 1;
72 
73  struct h2_ihash_t *streams; /* all streams currently processing */
74  struct h2_ihash_t *shold; /* all streams done with task ongoing */
75  struct h2_ihash_t *spurge; /* all streams done, ready for destroy */
76 
77  struct h2_iqueue *q; /* all stream ids that need to be started */
78  struct h2_iqueue *readyq; /* all stream ids ready for output */
79 
80  struct h2_ihash_t *tasks; /* all tasks started and not destroyed */
81  struct h2_ihash_t *redo_tasks; /* all tasks that need to be redone */
82 
83  int max_streams; /* max # of concurrent streams */
84  int max_stream_started; /* highest stream id that started processing */
85  int workers_busy; /* # of workers processing on this mplx */
86  int workers_limit; /* current # of workers limit, dynamic */
87  int workers_max; /* max, hard limit # of workers in a process */
88  apr_time_t last_idle_block; /* last time, this mplx entered IDLE while
89  * streams were ready */
90  apr_time_t last_limit_change; /* last time, worker limit changed */
92 
97 
100 
102  apr_array_header_t *spare_slaves; /* spare slave connections */
103 
107 
110 
112 };
113 
114 
115 
116 /*******************************************************************************
117  * Object lifecycle and information.
118  ******************************************************************************/
119 
121 
127  const struct h2_config *conf,
128  apr_interval_time_t stream_timeout,
129  struct h2_workers *workers);
130 
140 
145 void h2_mplx_abort(h2_mplx *mplx);
146 
147 struct h2_task *h2_mplx_pop_task(h2_mplx *mplx, int *has_more);
148 
149 void h2_mplx_task_done(h2_mplx *m, struct h2_task *task, struct h2_task **ptask);
150 
156 int h2_mplx_shutdown(h2_mplx *m);
157 
158 int h2_mplx_is_busy(h2_mplx *m);
159 
160 /*******************************************************************************
161  * IO lifetime of streams.
162  ******************************************************************************/
163 
164 struct h2_stream *h2_mplx_stream_get(h2_mplx *m, int id);
165 
175 
181  struct apr_thread_cond_t *iowait);
182 
183 apr_status_t h2_mplx_keep_active(h2_mplx *m, int stream_id);
184 
185 /*******************************************************************************
186  * Stream processing.
187  ******************************************************************************/
188 
198 apr_status_t h2_mplx_process(h2_mplx *m, struct h2_stream *stream,
199  h2_stream_pri_cmp *cmp, void *ctx);
200 
209 
219 void h2_mplx_set_consumed_cb(h2_mplx *m, h2_mplx_consumed_cb *cb, void *ctx);
220 
221 
222 typedef apr_status_t stream_ev_callback(void *ctx, struct h2_stream *stream);
223 
231  stream_ev_callback *on_resume,
232  void *ctx);
233 
235 
236 typedef int h2_mplx_stream_cb(struct h2_stream *s, void *ctx);
237 
239 
240 /*******************************************************************************
241  * Output handling of streams.
242  ******************************************************************************/
243 
247 apr_status_t h2_mplx_out_open(h2_mplx *mplx, int stream_id,
248  struct h2_bucket_beam *beam);
249 
250 /*******************************************************************************
251  * h2_mplx list Manipulation.
252  ******************************************************************************/
253 
259 #define H2_MPLX_LIST_SENTINEL(b) APR_RING_SENTINEL((b), h2_mplx, link)
260 
266 #define H2_MPLX_LIST_EMPTY(b) APR_RING_EMPTY((b), h2_mplx, link)
267 
273 #define H2_MPLX_LIST_FIRST(b) APR_RING_FIRST(b)
274 
280 #define H2_MPLX_LIST_LAST(b) APR_RING_LAST(b)
281 
287 #define H2_MPLX_LIST_INSERT_HEAD(b, e) do { \
288 h2_mplx *ap__b = (e); \
289 APR_RING_INSERT_HEAD((b), ap__b, h2_mplx, link); \
290 } while (0)
291 
297 #define H2_MPLX_LIST_INSERT_TAIL(b, e) do { \
298 h2_mplx *ap__b = (e); \
299 APR_RING_INSERT_TAIL((b), ap__b, h2_mplx, link); \
300 } while (0)
301 
307 #define H2_MPLX_NEXT(e) APR_RING_NEXT((e), link)
308 
313 #define H2_MPLX_PREV(e) APR_RING_PREV((e), link)
314 
319 #define H2_MPLX_REMOVE(e) APR_RING_REMOVE((e), link)
320 
321 /*******************************************************************************
322  * h2_mplx DoS protection
323  ******************************************************************************/
324 
331 
332 /*******************************************************************************
333  * h2_req_engine handling
334  ******************************************************************************/
335 
336 typedef void h2_output_consumed(void *ctx, conn_rec *c, apr_off_t consumed);
338  const char *id,
339  const char *type,
340  apr_pool_t *pool,
341  apr_size_t req_buffer_size,
342  request_rec *r,
343  h2_output_consumed **pconsumed,
344  void **pbaton);
345 
346 apr_status_t h2_mplx_req_engine_push(const char *ngn_type,
347  request_rec *r,
348  h2_mplx_req_engine_init *einit);
350  apr_read_type_e block,
351  int capacity,
352  request_rec **pr);
353 void h2_mplx_req_engine_done(struct h2_req_engine *ngn, conn_rec *r_conn,
355 
356 #endif /* defined(__mod_h2__h2_mplx__) */
struct apr_thread_cond_t * join_wait
Definition: h2_mplx.h:96
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:37
struct h2_ihash_t * spurge
Definition: h2_mplx.h:75
apr_array_header_t * spare_slaves
Definition: h2_mplx.h:102
apr_status_t stream_ev_callback(void *ctx, struct h2_stream *stream)
Definition: h2_mplx.h:222
apr_status_t h2_mplx_process(h2_mplx *m, struct h2_stream *stream, h2_stream_pri_cmp *cmp, void *ctx)
Definition: h2_task.h:52
Definition: h2_mplx.h:62
Definition: apr_arch_thread_mutex.h:28
Definition: apr_tables.h:62
apr_time_t last_idle_block
Definition: h2_mplx.h:88
int workers_busy
Definition: h2_mplx.h:85
apr_pool_t * spare_io_pool
Definition: h2_mplx.h:101
struct apr_bucket_alloc_t apr_bucket_alloc_t
Definition: apr_buckets.h:123
struct h2_task * h2_mplx_pop_task(h2_mplx *mplx, int *has_more)
apr_status_t h2_mplx_release_and_join(h2_mplx *m, struct apr_thread_cond_t *wait)
apr_size_t stream_max_mem
Definition: h2_mplx.h:98
int tx_chunk_size
Definition: h2_mplx.h:106
int max_stream_started
Definition: h2_mplx.h:84
apr_status_t h2_mplx_stream_done(h2_mplx *m, struct h2_stream *stream)
unsigned int aborted
Definition: h2_mplx.h:70
Definition: h2.h:118
Thread Safe FIFO bounded queue.
apr_bucket_alloc_t * bucket_alloc
Definition: h2_mplx.h:66
apr_interval_time_t stream_timeout
Definition: h2_mplx.h:99
Definition: h2_bucket_beam.h:177
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)
void h2_mplx_consumed_cb(void *ctx, int stream_id, apr_off_t consumed)
Definition: h2_mplx.h:60
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:104
apr_thread_mutex_t * lock
Definition: h2_mplx.h:93
Structure to store things which are per connection.
Definition: httpd.h:1110
struct h2_ihash_t * shold
Definition: h2_mplx.h:74
void h2_output_consumed(void *ctx, conn_rec *c, apr_off_t consumed)
Definition: h2_mplx.h:336
struct h2_stream * h2_mplx_stream_get(h2_mplx *m, int id)
apr_status_t h2_mplx_reprioritize(h2_mplx *m, h2_stream_pri_cmp *cmp, void *ctx)
apr_status_t h2_mplx_keep_active(h2_mplx *m, int stream_id)
unsigned int need_registration
Definition: h2_mplx.h:71
apr_int64_t apr_time_t
Definition: apr_time.h:45
int tx_handles_reserved
Definition: h2_mplx.h:105
apr_status_t h2_mplx_child_init(apr_pool_t *pool, server_rec *s)
apr_pool_t * pool
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:1302
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)
h2_mplx_consumed_cb * input_consumed
Definition: h2_mplx.h:108
Definition: h2_ngn_shed.h:23
struct h2_ihash_t h2_ihash_t
Definition: h2_util.h:41
void * input_consumed_ctx
Definition: h2_mplx.h:109
Definition: h2_stream.h:44
struct apr_thread_cond_t * added_output
Definition: h2_mplx.h:94
struct h2_ihash_t * tasks
Definition: h2_mplx.h:80
apr_status_t h2_mplx_req_engine_push(const char *ngn_type, request_rec *r, h2_mplx_req_engine_init *einit)
struct h2_ngn_shed * ngn_shed
Definition: h2_mplx.h:111
int h2_stream_pri_cmp(int stream_id1, int stream_id2, void *ctx)
Definition: h2.h:140
void h2_mplx_abort(h2_mplx *mplx)
apr_read_type_e
Definition: apr_buckets.h:57
struct h2_iqueue * q
Definition: h2_mplx.h:77
struct h2_ihash_t * redo_tasks
Definition: h2_mplx.h:81
A structure that represents the current request.
Definition: httpd.h:805
apr_interval_time_t limit_change_interval
Definition: h2_mplx.h:91
struct h2_ihash_t * streams
Definition: h2_mplx.h:73
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:337
int status
Definition: mod_dav.h:141
struct h2_iqueue * readyq
Definition: h2_mplx.h:78
struct apr_thread_cond_t * task_thawed
Definition: h2_mplx.h:95
h2_mplx * h2_mplx_create(conn_rec *c, apr_pool_t *master, const struct h2_config *conf, apr_interval_time_t stream_timeout, struct h2_workers *workers)
conn_rec * c
Definition: h2_mplx.h:64
long id
Definition: h2_mplx.h:63
APR_RING_ENTRY(h2_mplx) link
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
int workers_max
Definition: h2_mplx.h:87
request_rec * r
Definition: mod_dav.h:519
void h2_mplx_set_consumed_cb(h2_mplx *m, h2_mplx_consumed_cb *cb, void *ctx)
int h2_mplx_stream_cb(struct h2_stream *s, void *ctx)
Definition: h2_mplx.h:236
int h2_mplx_is_busy(h2_mplx *m)
int max_streams
Definition: h2_mplx.h:83
Definition: apr_arch_thread_cond.h:34
proxy_worker proxy_server_conf * conf
Definition: mod_proxy.h:602
Definition: h2_workers.h:33
apr_time_t last_limit_change
Definition: h2_mplx.h:90
int workers_limit
Definition: h2_mplx.h:86
off_t apr_off_t
Definition: apr.h:377
apr_status_t h2_mplx_req_engine_pull(struct h2_req_engine *ngn, apr_read_type_e block, int capacity, request_rec **pr)