[nginx] svn commit: r5106 - trunk/src/http
vbart at nginx.com
vbart at nginx.com
Thu Mar 7 18:14:27 UTC 2013
Author: vbart
Date: 2013-03-07 18:14:27 +0000 (Thu, 07 Mar 2013)
New Revision: 5106
URL: http://trac.nginx.org/nginx/changeset/5106/nginx
Log:
Refactored ngx_http_init_request().
Now it can be used as the request object factory with minimal impact on the
connection object. Therefore it was renamed to ngx_http_create_request().
Modified:
trunk/src/http/ngx_http_request.c
trunk/src/http/ngx_http_request.h
Modified: trunk/src/http/ngx_http_request.c
===================================================================
--- trunk/src/http/ngx_http_request.c 2013-03-07 18:07:16 UTC (rev 5105)
+++ trunk/src/http/ngx_http_request.c 2013-03-07 18:14:27 UTC (rev 5106)
@@ -11,7 +11,7 @@
static void ngx_http_wait_request_handler(ngx_event_t *ev);
-static void ngx_http_init_request(ngx_event_t *ev);
+static ngx_http_request_t *ngx_http_create_request(ngx_connection_t *c);
static void ngx_http_process_request_line(ngx_event_t *rev);
static void ngx_http_process_request_headers(ngx_event_t *rev);
static ssize_t ngx_http_read_request_header(ngx_http_request_t *r);
@@ -466,16 +466,22 @@
c->log->action = "reading client request line";
- ngx_http_init_request(rev);
+ c->data = ngx_http_create_request(c);
+ if (c->data == NULL) {
+ ngx_http_close_connection(c);
+ return;
+ }
+
+ rev->handler = ngx_http_process_request_line;
+ ngx_http_process_request_line(rev);
}
-static void
-ngx_http_init_request(ngx_event_t *rev)
+static ngx_http_request_t *
+ngx_http_create_request(ngx_connection_t *c)
{
ngx_pool_t *pool;
ngx_time_t *tp;
- ngx_connection_t *c;
ngx_http_request_t *r;
ngx_http_log_ctx_t *ctx;
ngx_http_connection_t *hc;
@@ -483,8 +489,6 @@
ngx_http_core_loc_conf_t *clcf;
ngx_http_core_main_conf_t *cmcf;
- c = rev->data;
-
c->requests++;
hc = c->data;
@@ -493,27 +497,19 @@
pool = ngx_create_pool(cscf->request_pool_size, c->log);
if (pool == NULL) {
- ngx_http_close_connection(c);
- return;
+ return NULL;
}
r = ngx_pcalloc(pool, sizeof(ngx_http_request_t));
if (r == NULL) {
ngx_destroy_pool(pool);
- ngx_http_close_connection(c);
- return;
+ return NULL;
}
r->pool = pool;
- r->pipeline = hc->pipeline;
-
- c->data = r;
r->http_connection = hc;
-
- c->sent = 0;
r->signature = NGX_HTTP_MODULE;
-
r->connection = c;
r->main_conf = hc->conf_ctx->main_conf;
@@ -533,15 +529,13 @@
!= NGX_OK)
{
ngx_destroy_pool(r->pool);
- ngx_http_close_connection(c);
- return;
+ return NULL;
}
r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
if (r->ctx == NULL) {
ngx_destroy_pool(r->pool);
- ngx_http_close_connection(c);
- return;
+ return NULL;
}
cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
@@ -550,12 +544,9 @@
* sizeof(ngx_http_variable_value_t));
if (r->variables == NULL) {
ngx_destroy_pool(r->pool);
- ngx_http_close_connection(c);
- return;
+ return NULL;
}
- c->destroyed = 0;
-
#if (NGX_HTTP_SSL)
if (c->ssl) {
r->main_filter_need_in_memory = 1;
@@ -592,8 +583,7 @@
(void) ngx_atomic_fetch_add(ngx_stat_requests, 1);
#endif
- rev->handler = ngx_http_process_request_line;
- ngx_http_process_request_line(rev);
+ return r;
}
@@ -2722,7 +2712,7 @@
/*
* If the large header buffers were allocated while the previous
* request processing then we do not use c->buffer for
- * the pipelined request (see ngx_http_init_request()).
+ * the pipelined request (see ngx_http_create_request()).
*
* Now we would move the large header buffers to the free list.
*/
@@ -2770,20 +2760,30 @@
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request");
- hc->pipeline = 1;
c->log->action = "reading client pipelined request line";
+ r = ngx_http_create_request(c);
+ if (r == NULL) {
+ ngx_http_close_connection(c);
+ return;
+ }
+
+ r->pipeline = 1;
+
+ c->data = r;
+
+ c->sent = 0;
+ c->destroyed = 0;
+
if (rev->timer_set) {
ngx_del_timer(rev);
}
- rev->handler = ngx_http_init_request;
+ rev->handler = ngx_http_process_request_line;
ngx_post_event(rev, &ngx_posted_events);
return;
}
- hc->pipeline = 0;
-
/*
* To keep a memory footprint as small as possible for an idle keepalive
* connection we try to free c->buffer's memory if it was allocated outside
@@ -3019,9 +3019,19 @@
c->idle = 0;
ngx_reusable_connection(c, 0);
+ c->data = ngx_http_create_request(c);
+ if (c->data == NULL) {
+ ngx_http_close_connection(c);
+ return;
+ }
+
+ c->sent = 0;
+ c->destroyed = 0;
+
ngx_del_timer(rev);
- ngx_http_init_request(rev);
+ rev->handler = ngx_http_process_request_line;
+ ngx_http_process_request_line(rev);
}
Modified: trunk/src/http/ngx_http_request.h
===================================================================
--- trunk/src/http/ngx_http_request.h 2013-03-07 18:07:16 UTC (rev 5105)
+++ trunk/src/http/ngx_http_request.h 2013-03-07 18:14:27 UTC (rev 5106)
@@ -308,8 +308,9 @@
ngx_buf_t **free;
ngx_int_t nfree;
- unsigned pipeline:1;
- unsigned ssl:1;
+#if (NGX_HTTP_SSL)
+ ngx_uint_t ssl; /* unsigned ssl:1; */
+#endif
} ngx_http_connection_t;
More information about the nginx-devel
mailing list