Skip to content

Commit c909ade

Browse files
author
Stefan Eissing
committed
Further dismemberments of h2_task into the h2_conn_ctx_t.
* placed all task input chunking related items in the context of the filter handling function.
1 parent 03571d2 commit c909ade

16 files changed

Lines changed: 371 additions & 361 deletions

mod_http2/h2_config.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,11 @@ static void h2_config_seti64(h2_dir_config *dconf, h2_config *conf, h2_config_va
423423

424424
static const h2_config *h2_config_get(conn_rec *c)
425425
{
426-
h2_conn_ctx_t *ctx = h2_conn_ctx_get(c);
426+
h2_conn_ctx_t *conn_ctx = h2_conn_ctx_get(c);
427427

428-
if (ctx) {
429-
if (ctx->config) {
430-
return ctx->config;
431-
}
432-
else if (ctx->server) {
433-
ctx->config = h2_config_sget(ctx->server);
434-
return ctx->config;
435-
}
428+
if (conn_ctx && conn_ctx->server) {
429+
return h2_config_sget(conn_ctx->server);
436430
}
437-
438431
return h2_config_sget(c->base_server);
439432
}
440433

mod_http2/h2_ctx.c

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,67 @@
2020
#include <httpd.h>
2121
#include <http_core.h>
2222
#include <http_config.h>
23+
#include <http_log.h>
2324

2425
#include "h2_private.h"
2526
#include "h2_session.h"
27+
#include "h2_bucket_beam.h"
2628
#include "h2_task.h"
2729
#include "h2_stream.h"
2830
#include "h2_ctx.h"
2931

3032

31-
static h2_conn_ctx_t *ctx_create(const conn_rec *c, const char *id)
33+
void h2_conn_ctx_detach(conn_rec *c)
3234
{
33-
h2_conn_ctx_t *ctx = apr_pcalloc(c->pool, sizeof(*ctx));
34-
ctx->id = id;
35-
ctx->server = c->base_server;
36-
ap_set_module_config(c->conn_config, &http2_module, ctx);
37-
return ctx;
35+
h2_conn_ctx_t *conn_ctx = h2_conn_ctx_get(c);
36+
37+
if (conn_ctx && conn_ctx->task && conn_ctx->task->output.beam) {
38+
h2_beam_log(conn_ctx->task->output.beam, c, APLOG_TRACE2, "task_destroy");
39+
h2_beam_destroy(conn_ctx->task->output.beam);
40+
conn_ctx->task->output.beam = NULL;
41+
}
42+
ap_set_module_config(c->conn_config, &http2_module, NULL);
43+
}
44+
45+
static h2_conn_ctx_t *ctx_create(apr_pool_t *pool, conn_rec *c, const char *id)
46+
{
47+
h2_conn_ctx_t *conn_ctx = apr_pcalloc(pool, sizeof(*conn_ctx));
48+
conn_ctx->id = id;
49+
conn_ctx->pool = pool;
50+
conn_ctx->server = c->base_server;
51+
conn_ctx->started_at = apr_time_now();
52+
ap_set_module_config(c->conn_config, &http2_module, conn_ctx);
53+
return conn_ctx;
3854
}
3955

40-
h2_conn_ctx_t *h2_conn_ctx_create(const conn_rec *c)
56+
void h2_conn_ctx_destroy(h2_conn_ctx_t *conn_ctx)
4157
{
42-
return ctx_create(c, apr_psprintf(c->pool, "%ld", c->id));
58+
apr_pool_destroy(conn_ctx->pool);
4359
}
4460

45-
h2_conn_ctx_t *h2_conn_ctx_create_secondary(const conn_rec *c, struct h2_stream *stream)
61+
h2_conn_ctx_t *h2_conn_ctx_create(conn_rec *c)
4662
{
63+
return ctx_create(c->pool, c, apr_psprintf(c->pool, "%ld", c->id));
64+
}
65+
66+
h2_conn_ctx_t *h2_conn_ctx_create_secondary(conn_rec *c, struct h2_stream *stream)
67+
{
68+
const char *id;
69+
h2_conn_ctx_t *ctx;
70+
apr_pool_t *pool;
71+
4772
/* there is sth fishy going on in some mpms that change the id of
4873
* a connection when they process it in another thread. stick to
4974
* the id the session was initialized with. */
50-
h2_conn_ctx_t *ctx = ctx_create(c, apr_psprintf(
51-
c->pool, "%ld-%d", stream->session->id, stream->id));
75+
apr_pool_create(&pool, c->pool);
76+
apr_pool_tag(pool, "h2_secondary");
77+
id = apr_psprintf(pool, "%ld-%d", stream->session->id, stream->id);
78+
ctx = ctx_create(pool, c, id);
5279
ctx->mplx = stream->session->mplx;
53-
return ctx;
54-
}
80+
ctx->stream_id = stream->id;
81+
ctx->request = stream->request;
5582

56-
void h2_conn_ctx_clear(const conn_rec *c)
57-
{
58-
ap_assert(c);
59-
ap_set_module_config(c->conn_config, &http2_module, NULL);
83+
return ctx;
6084
}
6185

6286
h2_session *h2_conn_ctx_get_session(conn_rec *c)

mod_http2/h2_ctx.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ struct h2_session;
2121
struct h2_stream;
2222
struct h2_mplx;
2323
struct h2_task;
24-
struct h2_config;
2524

2625
/**
2726
* The h2 module context associated with a connection.
@@ -33,12 +32,20 @@ struct h2_config;
3332
*/
3433
struct h2_conn_ctx_t {
3534
const char *id; /* our identifier of this connection */
36-
const char *protocol; /* the protocol negotiated */
35+
apr_pool_t *pool; /* main: session pool, secondary: task pool */
3736
server_rec *server; /* httpd server selected. */
37+
const char *protocol; /* the protocol negotiated */
3838
struct h2_session *session; /* on main: the session established */
39+
3940
struct h2_mplx *mplx; /* on secondary: the multiplexer */
41+
int stream_id; /* on main: 0, on secondary: stream id */
42+
const struct h2_request *request; /* on secondary: the request to process */
4043
struct h2_task *task; /* on secondary: the task processed */
41-
const struct h2_config *config; /* effective config in this context */
44+
int filters_set; /* protocol filters have been set up */
45+
46+
volatile int done; /* processing has finished */
47+
apr_time_t started_at; /* when processing started */
48+
apr_time_t done_at; /* when processing was done */
4249
};
4350
typedef struct h2_conn_ctx_t h2_conn_ctx_t;
4451

@@ -48,18 +55,23 @@ typedef struct h2_conn_ctx_t h2_conn_ctx_t;
4855
* @return h2 context of this connection
4956
*/
5057
#define h2_conn_ctx_get(c) \
51-
((h2_conn_ctx_t*)ap_get_module_config((c)->conn_config, &http2_module))
58+
((c)? (h2_conn_ctx_t*)ap_get_module_config((c)->conn_config, &http2_module) : NULL)
5259

5360
/**
5461
* Create the h2 connection context.
5562
* @param c the connection to create it at
5663
* @return created h2 context of this connection
5764
*/
58-
h2_conn_ctx_t *h2_conn_ctx_create(const conn_rec *c);
65+
h2_conn_ctx_t *h2_conn_ctx_create(conn_rec *c);
5966

60-
h2_conn_ctx_t *h2_conn_ctx_create_secondary(const conn_rec *c, struct h2_stream *stream);
67+
h2_conn_ctx_t *h2_conn_ctx_create_secondary(conn_rec *c, struct h2_stream *stream);
6168

62-
void h2_conn_ctx_clear(const conn_rec *c);
69+
void h2_conn_ctx_detach(conn_rec *c);
70+
71+
/**
72+
* Distach from the connection and destroy all resources, e.g. the pool.
73+
*/
74+
void h2_conn_ctx_destroy(h2_conn_ctx_t *conn_ctx);
6375

6476
/**
6577
* Get the session instance if `c` is a HTTP/2 master connection.

mod_http2/h2_filter.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,10 @@ static void add_stats(apr_bucket_brigade *bb, h2_session *s,
430430
bbout(bb, " }%s\n", last? "" : ",");
431431
}
432432

433-
static apr_status_t h2_status_insert(h2_task *task, apr_bucket *b)
433+
static apr_status_t h2_status_insert(h2_conn_ctx_t *conn_ctx, apr_bucket *b)
434434
{
435-
h2_mplx *m = task->mplx;
436-
h2_stream *stream = h2_mplx_t_stream_get(m, task);
435+
h2_mplx *m = conn_ctx->mplx;
436+
h2_stream *stream = h2_mplx_t_stream_get(m, conn_ctx->stream_id);
437437
h2_session *s;
438438
conn_rec *c;
439439

@@ -487,7 +487,7 @@ static apr_status_t status_event(void *userdata, h2_bucket_event event,
487487
"status_event(%s): %d", ctx->id, event);
488488
switch (event) {
489489
case H2_BUCKET_EV_BEFORE_MASTER_SEND:
490-
h2_status_insert(ctx->task, b);
490+
h2_status_insert(ctx, b);
491491
break;
492492
default:
493493
break;
@@ -545,7 +545,7 @@ static apr_status_t discard_body(request_rec *r, apr_off_t maxlen)
545545
int h2_filter_h2_status_handler(request_rec *r)
546546
{
547547
conn_rec *c = r->connection;
548-
h2_task *task;
548+
h2_conn_ctx_t *conn_ctx = h2_conn_ctx_get(c);
549549
apr_bucket_brigade *bb;
550550
apr_bucket *b;
551551
apr_status_t status;
@@ -557,8 +557,7 @@ int h2_filter_h2_status_handler(request_rec *r)
557557
return DECLINED;
558558
}
559559

560-
task = h2_conn_ctx_get_task(r->connection);
561-
if (task) {
560+
if (conn_ctx && conn_ctx->stream_id) {
562561
/* In this handler, we do some special sauce to send footers back,
563562
* IFF we received footers in the request. This is used in our test
564563
* cases, since CGI has no way of handling those. */
@@ -588,11 +587,11 @@ int h2_filter_h2_status_handler(request_rec *r)
588587

589588
ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
590589
"status_handler(%s): checking for incoming trailers",
591-
task->id);
590+
conn_ctx->id);
592591
if (r->trailers_in && !apr_is_empty_table(r->trailers_in)) {
593592
ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
594593
"status_handler(%s): seeing incoming trailers",
595-
task->id);
594+
conn_ctx->id);
596595
apr_table_setn(r->trailers_out, "h2-trailers-in",
597596
apr_itoa(r->pool, 1));
598597
}
@@ -607,7 +606,7 @@ int h2_filter_h2_status_handler(request_rec *r)
607606
/* no way to know what type of error occurred */
608607
ap_log_rerror(APLOG_MARK, APLOG_TRACE1, status, r,
609608
"status_handler(%s): ap_pass_brigade failed",
610-
task->id);
609+
conn_ctx->id);
611610
return AP_FILTER_ERROR;
612611
}
613612
}

0 commit comments

Comments
 (0)