diff options
author | Igor Sysoev <igor@sysoev.ru> | 2017-06-14 15:18:52 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2017-06-14 15:18:52 +0300 |
commit | 7574c64992b98d3dfbc3dd101bd0f7d78bad0823 (patch) | |
tree | 3a98c46e88d9023df34be3e6cce4f762d53aad36 /src/nxt_conn_write.c | |
parent | 3e2632688f53c4cb08e7ac03c61e71facd038df4 (diff) | |
download | unit-7574c64992b98d3dfbc3dd101bd0f7d78bad0823.tar.gz unit-7574c64992b98d3dfbc3dd101bd0f7d78bad0823.tar.bz2 |
nxt_event_conn_... functions and structures have been renamed
to nxt_conn_...
Diffstat (limited to '')
-rw-r--r-- | src/nxt_conn_write.c (renamed from src/nxt_event_conn_write.c) | 270 |
1 files changed, 136 insertions, 134 deletions
diff --git a/src/nxt_event_conn_write.c b/src/nxt_conn_write.c index fa5b9241..a2a5737b 100644 --- a/src/nxt_event_conn_write.c +++ b/src/nxt_conn_write.c @@ -7,7 +7,7 @@ #include <nxt_main.h> -static void nxt_event_conn_write_timer_handler(nxt_task_t *task, void *obj, +static void nxt_conn_write_timer_handler(nxt_task_t *task, void *obj, void *data); @@ -16,13 +16,13 @@ nxt_conn_io_write(nxt_task_t *task, void *obj, void *data) { ssize_t ret; nxt_buf_t *b; + nxt_conn_t *c; nxt_sendbuf_t sb; - nxt_event_conn_t *c; nxt_event_engine_t *engine; c = obj; - nxt_debug(task, "event conn write fd:%d", c->socket.fd); + nxt_debug(task, "conn write fd:%d", c->socket.fd); if (!c->socket.write_ready || c->write == NULL) { return; @@ -89,7 +89,7 @@ nxt_conn_io_write(nxt_task_t *task, void *obj, void *data) * Postpone writing until next event poll to allow to * process other recevied events and to get new events. */ - c->write_timer.handler = nxt_event_conn_write_timer_handler; + c->write_timer.handler = nxt_conn_write_timer_handler; nxt_timer_add(engine, &c->write_timer, 0); } else if (ret == NXT_AGAIN) { @@ -100,7 +100,7 @@ nxt_conn_io_write(nxt_task_t *task, void *obj, void *data) * can be set here because it should be set only for write * direction. */ - nxt_event_conn_timer(engine, c, c->write_state, &c->write_timer); + nxt_conn_timer(engine, c, c->write_state, &c->write_timer); if (nxt_fd_event_is_disabled(c->socket.write)) { nxt_fd_event_enable_write(engine, &c->socket); @@ -128,8 +128,133 @@ nxt_conn_io_write(nxt_task_t *task, void *obj, void *data) } +static void +nxt_conn_write_timer_handler(nxt_task_t *task, void *obj, void *data) +{ + nxt_conn_t *c; + nxt_timer_t *timer; + + timer = obj; + + nxt_debug(task, "event conn conn timer"); + + c = nxt_write_timer_conn(timer); + c->delayed = 0; + + c->io->write(task, c, c->socket.data); +} + + +ssize_t +nxt_conn_io_sendbuf(nxt_task_t *task, nxt_sendbuf_t *sb) +{ + nxt_uint_t niov; + struct iovec iov[NXT_IOBUF_MAX]; + + niov = nxt_sendbuf_mem_coalesce0(task, sb, iov, NXT_IOBUF_MAX); + + if (niov == 0 && sb->sync) { + return 0; + } + + return nxt_conn_io_writev(task, sb, iov, niov); +} + + +ssize_t +nxt_conn_io_writev(nxt_task_t *task, nxt_sendbuf_t *sb, struct iovec *iov, + nxt_uint_t niov) +{ + ssize_t n; + nxt_err_t err; + + if (niov == 1) { + /* Disposal of surplus kernel iovec copy-in operation. */ + return nxt_conn_io_send(task, sb, iov[0].iov_base, iov[0].iov_len); + } + + for ( ;; ) { + n = writev(sb->socket, iov, niov); + + err = (n == -1) ? nxt_socket_errno : 0; + + nxt_debug(task, "writev(%d, %ui): %d", sb->socket, niov, n); + + if (n > 0) { + return n; + } + + /* n == -1 */ + + switch (err) { + + case NXT_EAGAIN: + sb->ready = 0; + nxt_debug(task, "writev() %E", err); + + return NXT_AGAIN; + + case NXT_EINTR: + nxt_debug(task, "writev() %E", err); + continue; + + default: + sb->error = err; + nxt_log(task, nxt_socket_error_level(err), + "writev(%d, %ui) failed %E", sb->socket, niov, err); + + return NXT_ERROR; + } + } +} + + +ssize_t +nxt_conn_io_send(nxt_task_t *task, nxt_sendbuf_t *sb, void *buf, size_t size) +{ + ssize_t n; + nxt_err_t err; + + for ( ;; ) { + n = send(sb->socket, buf, size, 0); + + err = (n == -1) ? nxt_socket_errno : 0; + + nxt_debug(task, "send(%d, %p, %uz): %z", sb->socket, buf, size, n); + + if (n > 0) { + return n; + } + + /* n == -1 */ + + switch (err) { + + case NXT_EAGAIN: + sb->ready = 0; + nxt_debug(task, "send() %E", err); + + return NXT_AGAIN; + + case NXT_EINTR: + nxt_debug(task, "send() %E", err); + continue; + + default: + sb->error = err; + nxt_log(task, nxt_socket_error_level(err), + "send(%d, %p, %uz) failed %E", sb->socket, buf, size, err); + + return NXT_ERROR; + } + } +} + + +/* Obsolete interfaces. */ + size_t -nxt_event_conn_write_limit(nxt_event_conn_t *c) +nxt_event_conn_write_limit(nxt_conn_t *c) { ssize_t limit, correction; nxt_event_write_rate_t *rate; @@ -162,32 +287,15 @@ nxt_event_conn_write_limit(nxt_event_conn_t *c) nxt_bool_t -nxt_event_conn_write_delayed(nxt_event_engine_t *engine, nxt_event_conn_t *c, +nxt_event_conn_write_delayed(nxt_event_engine_t *engine, nxt_conn_t *c, size_t sent) { return 0; } -static void -nxt_event_conn_write_timer_handler(nxt_task_t *task, void *obj, void *data) -{ - nxt_timer_t *ev; - nxt_event_conn_t *c; - - ev = obj; - - nxt_debug(task, "event conn conn timer"); - - c = nxt_event_write_timer_conn(ev); - c->delayed = 0; - - c->io->write(task, c, c->socket.data); -} - - ssize_t -nxt_event_conn_io_write_chunk(nxt_event_conn_t *c, nxt_buf_t *b, size_t limit) +nxt_event_conn_io_write_chunk(nxt_conn_t *c, nxt_buf_t *b, size_t limit) { ssize_t ret; @@ -204,7 +312,7 @@ nxt_event_conn_io_write_chunk(nxt_event_conn_t *c, nxt_buf_t *b, size_t limit) ssize_t -nxt_event_conn_io_sendbuf(nxt_event_conn_t *c, nxt_buf_t *b, size_t limit) +nxt_event_conn_io_sendbuf(nxt_conn_t *c, nxt_buf_t *b, size_t limit) { nxt_uint_t niob; struct iovec iob[NXT_IOBUF_MAX]; @@ -228,7 +336,7 @@ nxt_event_conn_io_sendbuf(nxt_event_conn_t *c, nxt_buf_t *b, size_t limit) ssize_t -nxt_event_conn_io_writev(nxt_event_conn_t *c, nxt_iobuf_t *iob, nxt_uint_t niob) +nxt_event_conn_io_writev(nxt_conn_t *c, nxt_iobuf_t *iob, nxt_uint_t niob) { ssize_t n; nxt_err_t err; @@ -273,7 +381,7 @@ nxt_event_conn_io_writev(nxt_event_conn_t *c, nxt_iobuf_t *iob, nxt_uint_t niob) ssize_t -nxt_event_conn_io_send(nxt_event_conn_t *c, void *buf, size_t size) +nxt_event_conn_io_send(nxt_conn_t *c, void *buf, size_t size) { ssize_t n; nxt_err_t err; @@ -312,109 +420,3 @@ nxt_event_conn_io_send(nxt_event_conn_t *c, void *buf, size_t size) } } } - - -ssize_t -nxt_conn_io_sendbuf(nxt_task_t *task, nxt_sendbuf_t *sb) -{ - nxt_uint_t niov; - struct iovec iov[NXT_IOBUF_MAX]; - - niov = nxt_sendbuf_mem_coalesce0(task, sb, iov, NXT_IOBUF_MAX); - - if (niov == 0 && sb->sync) { - return 0; - } - - return nxt_conn_io_writev(task, sb, iov, niov); -} - - -ssize_t -nxt_conn_io_writev(nxt_task_t *task, nxt_sendbuf_t *sb, struct iovec *iov, - nxt_uint_t niov) -{ - ssize_t n; - nxt_err_t err; - - if (niov == 1) { - /* Disposal of surplus kernel iovec copy-in operation. */ - return nxt_conn_io_send(task, sb, iov[0].iov_base, iov[0].iov_len); - } - - for ( ;; ) { - n = writev(sb->socket, iov, niov); - - err = (n == -1) ? nxt_socket_errno : 0; - - nxt_debug(task, "writev(%d, %ui): %d", sb->socket, niov, n); - - if (n > 0) { - return n; - } - - /* n == -1 */ - - switch (err) { - - case NXT_EAGAIN: - sb->ready = 0; - nxt_debug(task, "writev() %E", err); - - return NXT_AGAIN; - - case NXT_EINTR: - nxt_debug(task, "writev() %E", err); - continue; - - default: - sb->error = err; - nxt_log(task, nxt_socket_error_level(err), - "writev(%d, %ui) failed %E", sb->socket, niov, err); - - return NXT_ERROR; - } - } -} - - -ssize_t -nxt_conn_io_send(nxt_task_t *task, nxt_sendbuf_t *sb, void *buf, size_t size) -{ - ssize_t n; - nxt_err_t err; - - for ( ;; ) { - n = send(sb->socket, buf, size, 0); - - err = (n == -1) ? nxt_socket_errno : 0; - - nxt_debug(task, "send(%d, %p, %uz): %z", sb->socket, buf, size, n); - - if (n > 0) { - return n; - } - - /* n == -1 */ - - switch (err) { - - case NXT_EAGAIN: - sb->ready = 0; - nxt_debug(task, "send() %E", err); - - return NXT_AGAIN; - - case NXT_EINTR: - nxt_debug(task, "send() %E", err); - continue; - - default: - sb->error = err; - nxt_log(task, nxt_socket_error_level(err), - "send(%d, %p, %uz) failed %E", sb->socket, buf, size, err); - - return NXT_ERROR; - } - } -} |