[core] request_acquire(), request_release()
continue code abstraction for (request_st *)
This commit is contained in:
parent
0905b6f7f9
commit
550609c8ae
|
@ -94,24 +94,6 @@ static void connection_del(server *srv, connection *con) {
|
|||
#endif
|
||||
}
|
||||
|
||||
#if 0 /* DEBUG_DEV */
|
||||
__attribute_cold__
|
||||
static void connection_plugin_ctx_check(server * const srv, request_st * const r) {
|
||||
/* plugins should have cleaned themselves up */
|
||||
for (uint32_t i = 0; i < srv->plugins.used; ++i) {
|
||||
plugin *p = ((plugin **)(srv->plugins.ptr))[i];
|
||||
plugin_data_base *pd = p->data;
|
||||
if (!pd) continue;
|
||||
if (NULL == r->plugin_ctx[pd->id]
|
||||
&& NULL == r->con->plugin_ctx[pd->id]) continue;
|
||||
log_error(r->conf.errh, __FILE__, __LINE__,
|
||||
"missing cleanup in %s", p->name);
|
||||
r->plugin_ctx[pd->id] = NULL;
|
||||
r->con->plugin_ctx[pd->id] = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void connection_close(connection *con) {
|
||||
if (con->fd < 0) con->fd = -con->fd;
|
||||
|
||||
|
@ -119,24 +101,8 @@ static void connection_close(connection *con) {
|
|||
|
||||
server * const srv = con->srv;
|
||||
request_st * const r = &con->request;
|
||||
|
||||
#if 0 /* DEBUG_DEV */
|
||||
/* plugins should have cleaned themselves up (id range: [1,used]) */
|
||||
for (uint32_t i = 1; i <= srv->plugins.used; ++i) {
|
||||
if (NULL != r->plugin_ctx[i] || NULL != con->plugin_ctx[i]) {
|
||||
connection_plugin_ctx_check(srv, r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
request_reset_ex(r); /*(r->conf.* is still valid below)*/
|
||||
connection_set_state(r, CON_STATE_CONNECT);
|
||||
buffer_clear(&r->uri.authority);
|
||||
buffer_reset(&r->uri.path);
|
||||
buffer_reset(&r->uri.query);
|
||||
buffer_reset(&r->target_orig);
|
||||
buffer_reset(&r->target); /*(see comments in request_reset())*/
|
||||
buffer_reset(&r->pathinfo); /*(see comments in request_reset())*/
|
||||
|
||||
chunkqueue_reset(con->read_queue);
|
||||
con->request_count = 0;
|
||||
|
@ -711,10 +677,7 @@ static int connection_handle_read_state(connection * const con) {
|
|||
|
||||
/* clear buffers which may have been kept for reporting on keep-alive,
|
||||
* (e.g. mod_status) */
|
||||
buffer_clear(&r->uri.authority);
|
||||
buffer_reset(&r->uri.path);
|
||||
buffer_reset(&r->uri.query);
|
||||
buffer_reset(&r->target_orig);
|
||||
request_reset_ex(r);
|
||||
}
|
||||
/* RFC7540 3.5 HTTP/2 Connection Preface
|
||||
* "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
|
||||
|
|
12
src/h2.c
12
src/h2.c
|
@ -2084,18 +2084,16 @@ h2_init_stream (request_st * const h2r, connection * const con)
|
|||
++con->request_count;
|
||||
force_assert(h2c->rused < sizeof(h2c->r)/sizeof(*h2c->r));
|
||||
/* initialize stream as subrequest (request_st *) */
|
||||
request_st * const r = calloc(1, sizeof(request_st));
|
||||
force_assert(r);
|
||||
request_st * const r = request_acquire(con);
|
||||
/* XXX: TODO: assign default priority, etc.
|
||||
* Perhaps store stream id and priority in separate table */
|
||||
h2c->r[h2c->rused++] = r;
|
||||
server * const srv = con->srv;
|
||||
request_init(r, con, srv);
|
||||
r->h2_rwin = h2c->s_initial_window_size;
|
||||
r->h2_swin = h2c->s_initial_window_size;
|
||||
r->http_version = HTTP_VERSION_2;
|
||||
|
||||
/* copy config state from h2r */
|
||||
server * const srv = con->srv;
|
||||
const uint32_t used = srv->config_context->used;
|
||||
r->conditional_is_valid = h2r->conditional_is_valid;
|
||||
memcpy(r->cond_cache, h2r->cond_cache, used * sizeof(cond_cache_t));
|
||||
|
@ -2103,6 +2101,7 @@ h2_init_stream (request_st * const h2r, connection * const con)
|
|||
if (used > 1) /*(save 128b per con if no conditions)*/
|
||||
memcpy(r->cond_match, h2r->cond_match, used * sizeof(cond_match_t));
|
||||
#endif
|
||||
/*(see config_reset_config())*/
|
||||
r->server_name = h2r->server_name;
|
||||
memcpy(&r->conf, &h2r->conf, sizeof(request_config));
|
||||
|
||||
|
@ -2133,10 +2132,7 @@ h2_release_stream (request_st * const r, connection * const con)
|
|||
#endif
|
||||
}
|
||||
|
||||
request_reset(r);
|
||||
/* future: might keep a pool of reusable (request_st *) */
|
||||
request_free(r);
|
||||
free(r);
|
||||
request_release(r);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -280,6 +280,7 @@ void http_response_reset (request_st * const r) {
|
|||
buffer_reset(&r->physical.rel_path);
|
||||
}
|
||||
r->resp_htags = 0;
|
||||
r->resp_header_len = 0;
|
||||
r->resp_header_repeated = 0;
|
||||
array_reset_data_strings(&r->resp_headers);
|
||||
http_response_body_clear(r, 0);
|
||||
|
|
|
@ -56,7 +56,6 @@ request_reset (request_st * const r)
|
|||
|
||||
http_response_reset(r);
|
||||
|
||||
r->resp_header_len = 0;
|
||||
r->loops_per_request = 0;
|
||||
|
||||
r->h2state = 0; /* H2_STATE_IDLE */
|
||||
|
@ -109,12 +108,63 @@ request_reset (request_st * const r)
|
|||
array_reset_data_strings(&r->env);
|
||||
|
||||
chunkqueue_reset(r->reqbody_queue);
|
||||
/* r->read_queue, r->write_queue are shared with con for HTTP/1.1
|
||||
* but are different than con->read_queue, con->write_queue for HTTP/2
|
||||
* For HTTP/1.1, when r->read_queue == con->read_queue, r->read_queue
|
||||
* is not cleared between requests since it might contain subsequent
|
||||
* requests. (see also request_release()) */
|
||||
|
||||
/* The cond_cache gets reset in response.c */
|
||||
/* config_cond_cache_reset(r); */
|
||||
}
|
||||
|
||||
|
||||
#if 0 /* DEBUG_DEV */
|
||||
__attribute_cold__
|
||||
static void request_plugin_ctx_check(request_st * const r, server * const srv) {
|
||||
/* plugins should have cleaned themselves up */
|
||||
for (uint32_t i = 0, used = srv->plugins.used; i < used; ++i) {
|
||||
plugin *p = ((plugin **)(srv->plugins.ptr))[i];
|
||||
plugin_data_base *pd = p->data;
|
||||
if (!pd) continue;
|
||||
if (NULL == r->plugin_ctx[pd->id]
|
||||
&& NULL == r->con->plugin_ctx[pd->id]) continue;
|
||||
log_error(r->conf.errh, __FILE__, __LINE__,
|
||||
"missing cleanup in %s", p->name);
|
||||
r->plugin_ctx[pd->id] = NULL;
|
||||
r->con->plugin_ctx[pd->id] = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
request_reset_ex (request_st * const r)
|
||||
{
|
||||
#if 0 /* DEBUG_DEV */
|
||||
/* plugins should have cleaned themselves up (id range: [1,used]) */
|
||||
connection * const con = r->con;
|
||||
server * const srv = con->srv;
|
||||
for (uint32_t i = 1; i <= srv->plugins.used; ++i) {
|
||||
if (NULL != r->plugin_ctx[i] || NULL != con->plugin_ctx[i]) {
|
||||
request_plugin_ctx_check(r, srv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
buffer_clear(&r->uri.authority);
|
||||
buffer_reset(&r->uri.path);
|
||||
buffer_reset(&r->uri.query);
|
||||
buffer_reset(&r->target_orig);
|
||||
buffer_reset(&r->target); /*(see comments in request_reset())*/
|
||||
buffer_reset(&r->pathinfo); /*(see comments in request_reset())*/
|
||||
|
||||
/* preserve; callers must handle changes */
|
||||
/*r->state = CON_STATE_CONNECT;*/
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
request_free (request_st * const r)
|
||||
{
|
||||
|
@ -148,3 +198,40 @@ request_free (request_st * const r)
|
|||
|
||||
/* note: r is not zeroed here and r is not freed here */
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
request_release (request_st * const r)
|
||||
{
|
||||
/* (For HTTP/1.1, r == &con->request, and so request_release() not called)
|
||||
* r->read_queue, r->write_queue are shared with con for HTTP/1.1
|
||||
* but are different than con->read_queue, con->write_queue for HTTP/2
|
||||
* For HTTP/1.1, when r->read_queue == con->read_queue, r->read_queue
|
||||
* is not cleared between requests since it might contain subsequent
|
||||
* requests. (see also request_reset()) */
|
||||
chunkqueue_reset(r->read_queue);
|
||||
|
||||
/*(r->cond_cache and r->cond_match are re-init in h2_init_stream())*/
|
||||
|
||||
request_reset(r);
|
||||
request_reset_ex(r);
|
||||
r->state = CON_STATE_CONNECT;
|
||||
|
||||
/* future: might keep a pool of reusable (request_st *) */
|
||||
request_free(r);
|
||||
free(r);
|
||||
}
|
||||
|
||||
|
||||
request_st *
|
||||
request_acquire (connection * const con)
|
||||
{
|
||||
/* future: might keep a pool of reusable (request_st *) */
|
||||
request_st * const r = calloc(1, sizeof(request_st));
|
||||
force_assert(r);
|
||||
request_init(r, con, con->srv);
|
||||
|
||||
r->con = con;
|
||||
r->tmp_buf = con->srv->tmp_buf;
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
void request_init (request_st *r, connection *con, server *srv);
|
||||
void request_reset (request_st *r);
|
||||
void request_reset_ex (request_st *r);
|
||||
void request_free (request_st *r);
|
||||
void request_release (request_st *r);
|
||||
request_st * request_acquire (connection *con);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue