diff options
author | Igor Sysoev <igor@sysoev.ru> | 2018-04-11 17:33:18 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2018-04-11 17:33:18 +0300 |
commit | c7e575d5c61c2b301207c751ae73186d7568857e (patch) | |
tree | 378c0a86a6dd256c239d7992134c0faeb2a4304a /src/nxt_h1proto.c | |
parent | 0be4f1f6938bf34c8ff5dacaf31716572404a10d (diff) | |
download | unit-c7e575d5c61c2b301207c751ae73186d7568857e.tar.gz unit-c7e575d5c61c2b301207c751ae73186d7568857e.tar.bz2 |
Introducing connection state io_read_handler.
Diffstat (limited to 'src/nxt_h1proto.c')
-rw-r--r-- | src/nxt_h1proto.c | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c index 38766c31..5a27c3d8 100644 --- a/src/nxt_h1proto.c +++ b/src/nxt_h1proto.c @@ -13,7 +13,7 @@ * nxt_h1p_request_ prefix is used for HTTP/1 protocol request methods. */ -static void nxt_h1p_conn_read_header(nxt_task_t *task, void *obj, void *data); +static ssize_t nxt_h1p_conn_io_read_handler(nxt_conn_t *c); static void nxt_h1p_conn_proto_init(nxt_task_t *task, void *obj, void *data); static void nxt_h1p_conn_request_init(nxt_task_t *task, void *obj, void *data); static void nxt_h1p_conn_header_parse(nxt_task_t *task, void *obj, void *data); @@ -53,7 +53,6 @@ static nxt_msec_t nxt_h1p_conn_timeout_value(nxt_conn_t *c, uintptr_t data); static const nxt_conn_state_t nxt_h1p_idle_state; -static const nxt_conn_state_t nxt_h1p_proto_init_state; static const nxt_conn_state_t nxt_h1p_header_parse_state; static const nxt_conn_state_t nxt_h1p_read_body_state; static const nxt_conn_state_t nxt_h1p_send_state; @@ -151,60 +150,53 @@ nxt_http_conn_init(nxt_task_t *task, void *obj, void *data) c->read_state = &nxt_h1p_idle_state; - nxt_conn_wait(c); + nxt_conn_read(task->thread->engine, c); } static const nxt_conn_state_t nxt_h1p_idle_state nxt_aligned(64) = { - .ready_handler = nxt_h1p_conn_read_header, + .ready_handler = nxt_h1p_conn_proto_init, .close_handler = nxt_h1p_conn_error, .error_handler = nxt_h1p_conn_error, + .io_read_handler = nxt_h1p_conn_io_read_handler, + .timer_handler = nxt_h1p_conn_timeout, .timer_value = nxt_h1p_conn_timeout_value, - .timer_data = offsetof(nxt_socket_conf_t, idle_timeout), + .timer_data = offsetof(nxt_socket_conf_t, header_read_timeout), }; -static void -nxt_h1p_conn_read_header(nxt_task_t *task, void *obj, void *data) +static ssize_t +nxt_h1p_conn_io_read_handler(nxt_conn_t *c) { size_t size; - nxt_conn_t *c; + ssize_t n; + nxt_buf_t *b; nxt_socket_conf_joint_t *joint; - c = obj; - - nxt_debug(task, "h1p conn read header"); - joint = c->joint; size = joint->socket_conf->header_buffer_size; - c->read = nxt_buf_mem_alloc(c->mem_pool, size, 0); - if (nxt_slow_path(c->read == NULL)) { - nxt_h1p_conn_error(task, c, c->socket.data); - return; + b = nxt_buf_mem_alloc(c->mem_pool, size, 0); + if (nxt_slow_path(b == NULL)) { + c->socket.error = NXT_ENOMEM; + return NXT_ERROR; } - c->read_state = &nxt_h1p_proto_init_state; - - nxt_conn_read(task->thread->engine, c); -} + n = c->io->recvbuf(c, b); + if (n > 0) { + c->read = b; -static const nxt_conn_state_t nxt_h1p_proto_init_state - nxt_aligned(64) = -{ - .ready_handler = nxt_h1p_conn_proto_init, - .close_handler = nxt_h1p_conn_error, - .error_handler = nxt_h1p_conn_error, + } else { + nxt_mp_free(c->mem_pool, b); + } - .timer_handler = nxt_h1p_conn_timeout, - .timer_value = nxt_h1p_conn_timeout_value, - .timer_data = offsetof(nxt_socket_conf_t, header_read_timeout), -}; + return n; +} static void @@ -1021,9 +1013,9 @@ nxt_h1p_keepalive(nxt_task_t *task, nxt_h1proto_t *h1p, nxt_conn_t *c) size = nxt_buf_mem_used_size(&in->mem); if (size == 0) { - in->mem.pos = in->mem.start; - in->mem.free = in->mem.start; + nxt_mp_free(c->mem_pool, in); + c->read = NULL; c->read_state = &nxt_h1p_keepalive_state; nxt_conn_read(task->thread->engine, c); @@ -1048,6 +1040,8 @@ static const nxt_conn_state_t nxt_h1p_keepalive_state .close_handler = nxt_h1p_conn_error, .error_handler = nxt_h1p_conn_error, + .io_read_handler = nxt_h1p_conn_io_read_handler, + .timer_handler = nxt_h1p_conn_timeout, .timer_value = nxt_h1p_conn_timeout_value, .timer_data = offsetof(nxt_socket_conf_t, idle_timeout), |