summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_request.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2018-04-03 16:28:26 +0300
committerIgor Sysoev <igor@sysoev.ru>2018-04-03 16:28:26 +0300
commitfa04c05aa0e67e6964ab006935f939c6b27754a3 (patch)
tree969d3dac0bda996a487dc6e58e3b1e2ef7f91946 /src/nxt_http_request.c
parent151160c1103166810daddf1e9cc7135cb6ccc321 (diff)
downloadunit-fa04c05aa0e67e6964ab006935f939c6b27754a3.tar.gz
unit-fa04c05aa0e67e6964ab006935f939c6b27754a3.tar.bz2
HTTP: using r->mem_pool retention counter for response buffers.
Diffstat (limited to 'src/nxt_http_request.c')
-rw-r--r--src/nxt_http_request.c69
1 files changed, 58 insertions, 11 deletions
diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c
index 40cbaf40..b1d52dd5 100644
--- a/src/nxt_http_request.c
+++ b/src/nxt_http_request.c
@@ -10,6 +10,8 @@
static void nxt_http_request_start(nxt_task_t *task, void *obj, void *data);
static void nxt_http_app_request(nxt_task_t *task, void *obj, void *data);
+static void nxt_http_request_mem_buf_completion(nxt_task_t *task, void *obj,
+ void *data);
static void nxt_http_request_done(nxt_task_t *task, void *obj, void *data);
static u_char *nxt_http_date(u_char *buf, nxt_realtime_t *now, struct tm *tm,
@@ -82,6 +84,7 @@ nxt_http_request_t *
nxt_http_request_create(nxt_task_t *task)
{
nxt_mp_t *mp;
+ nxt_buf_t *last;
nxt_http_request_t *r;
mp = nxt_mp_create(1024, 128, 256, 32);
@@ -99,6 +102,17 @@ nxt_http_request_create(nxt_task_t *task)
goto fail;
}
+ last = nxt_mp_zget(mp, NXT_BUF_SYNC_SIZE);
+ if (nxt_slow_path(last == NULL)) {
+ goto fail;
+ }
+
+ nxt_buf_set_sync(last);
+ nxt_buf_set_last(last);
+ last->completion_handler = nxt_http_request_done;
+ last->parent = r;
+ r->last = last;
+
r->mem_pool = mp;
r->content_length_n = -1;
r->resp.content_length_n = -1;
@@ -109,6 +123,7 @@ nxt_http_request_create(nxt_task_t *task)
fail:
nxt_mp_release(mp);
+
return NULL;
}
@@ -349,20 +364,18 @@ nxt_http_request_send(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out)
nxt_buf_t *
-nxt_http_request_last_buffer(nxt_task_t *task, nxt_http_request_t *r)
+nxt_http_buf_mem(nxt_task_t *task, nxt_http_request_t *r, size_t size)
{
nxt_buf_t *b;
- b = nxt_buf_mem_alloc(r->mem_pool, 0, 0);
-
+ b = nxt_buf_mem_alloc(r->mem_pool, size, 0);
if (nxt_fast_path(b != NULL)) {
- nxt_buf_set_sync(b);
- nxt_buf_set_last(b);
- b->completion_handler = nxt_http_request_done;
+ b->completion_handler = nxt_http_request_mem_buf_completion;
b->parent = r;
+ nxt_mp_retain(r->mem_pool);
} else {
- nxt_http_request_release(task, r);
+ nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR);
}
return b;
@@ -370,6 +383,33 @@ nxt_http_request_last_buffer(nxt_task_t *task, nxt_http_request_t *r)
static void
+nxt_http_request_mem_buf_completion(nxt_task_t *task, void *obj, void *data)
+{
+ nxt_buf_t *b;
+ nxt_http_request_t *r;
+
+ b = obj;
+ r = data;
+
+ nxt_mp_free(r->mem_pool, b);
+
+ nxt_mp_release(r->mem_pool);
+}
+
+
+nxt_buf_t *
+nxt_http_buf_last(nxt_http_request_t *r)
+{
+ nxt_buf_t *last;
+
+ last = r->last;
+ r->last = NULL;
+
+ return last;
+}
+
+
+static void
nxt_http_request_done(nxt_task_t *task, void *obj, void *data)
{
nxt_http_request_t *r;
@@ -383,12 +423,19 @@ nxt_http_request_done(nxt_task_t *task, void *obj, void *data)
void
-nxt_http_request_release(nxt_task_t *task, nxt_http_request_t *r)
+nxt_http_request_error_handler(nxt_task_t *task, void *obj, void *data)
{
- nxt_debug(task, "http request release");
+ nxt_http_proto_t proto;
+ nxt_http_request_t *r;
+
+ r = obj;
+ proto.any = data;
+
+ nxt_debug(task, "http request error handler");
- nxt_work_queue_add(&task->thread->engine->fast_work_queue,
- nxt_http_request_close_handler, task, r, r->proto.any);
+ if (proto.any != NULL) {
+ nxt_http_proto_discard[r->protocol](task, r, nxt_http_buf_last(r));
+ }
}