summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_conn_read.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2018-09-20 15:05:37 +0300
committerIgor Sysoev <igor@sysoev.ru>2018-09-20 15:05:37 +0300
commit96cd68b34037f8b6d9a1d43f67b8fe7c1df2ef9e (patch)
tree8e648712993012fbe815cc92e6debab20449fe8f /src/nxt_conn_read.c
parente964e982fd64505fb8644f91e5c57a869038cd18 (diff)
downloadunit-96cd68b34037f8b6d9a1d43f67b8fe7c1df2ef9e.tar.gz
unit-96cd68b34037f8b6d9a1d43f67b8fe7c1df2ef9e.tar.bz2
Added SSL/TLS support on connection level.
Diffstat (limited to '')
-rw-r--r--src/nxt_conn_read.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/nxt_conn_read.c b/src/nxt_conn_read.c
index 7f738de5..21086233 100644
--- a/src/nxt_conn_read.c
+++ b/src/nxt_conn_read.c
@@ -39,7 +39,6 @@ nxt_conn_io_read(nxt_task_t *task, void *obj, void *data)
{
ssize_t n;
nxt_conn_t *c;
- nxt_work_queue_t *wq;
nxt_event_engine_t *engine;
nxt_work_handler_t handler;
const nxt_conn_state_t *state;
@@ -51,7 +50,13 @@ nxt_conn_io_read(nxt_task_t *task, void *obj, void *data)
engine = task->thread->engine;
+ /*
+ * Here c->io->read() is assigned instead of direct nxt_conn_io_read()
+ * because the function can be called by nxt_kqueue_conn_io_read().
+ */
+ c->socket.read_handler = c->io->read;
state = c->read_state;
+ c->socket.error_handler = state->error_handler;
if (c->socket.read_ready) {
@@ -75,35 +80,39 @@ nxt_conn_io_read(nxt_task_t *task, void *obj, void *data)
nxt_timer_disable(engine, &c->read_timer);
}
- wq = c->read_work_queue;
- handler = state->ready_handler;
-
- nxt_work_queue_add(wq, handler, task, c, data);
-
+ nxt_work_queue_add(c->read_work_queue,
+ state->ready_handler, task, c, data);
return;
}
if (n != NXT_AGAIN) {
+ /* n == 0 or n == NXT_ERROR. */
+ handler = (n == 0) ? state->close_handler : state->error_handler;
+
nxt_fd_event_block_read(engine, &c->socket);
nxt_timer_disable(engine, &c->read_timer);
- wq = &engine->fast_work_queue;
+ nxt_work_queue_add(&engine->fast_work_queue,
+ handler, task, c, data);
+ return;
+ }
- handler = (n == 0) ? state->close_handler : state->error_handler;
+ /* n == NXT_AGAIN. */
- nxt_work_queue_add(wq, handler, task, c, data);
+ if (c->socket.read_ready) {
+ /*
+ * SSL/TLS library can return NXT_AGAIN if renegotiation
+ * occured during read operation, it toggled write event
+ * internally so only read timer should be set.
+ */
+ if (c->read_timer.state == NXT_TIMER_DISABLED) {
+ nxt_conn_timer(engine, c, state, &c->read_timer);
+ }
return;
}
}
- /*
- * Here c->io->read() is assigned instead of direct nxt_conn_io_read()
- * because the function can be called by nxt_kqueue_conn_io_read().
- */
- c->socket.read_handler = c->io->read;
- c->socket.error_handler = state->error_handler;
-
if (nxt_fd_event_is_disabled(c->socket.read)) {
nxt_fd_event_enable_read(engine, &c->socket);
}
@@ -195,7 +204,7 @@ nxt_conn_io_recv(nxt_conn_t *c, void *buf, size_t size, nxt_uint_t flags)
c->socket.fd, buf, size, flags, n);
if (n > 0) {
- if ((size_t) n < size) {
+ if ((size_t) n < size && (flags & MSG_PEEK) == 0) {
c->socket.read_ready = 0;
}
@@ -204,7 +213,10 @@ nxt_conn_io_recv(nxt_conn_t *c, void *buf, size_t size, nxt_uint_t flags)
if (n == 0) {
c->socket.closed = 1;
- c->socket.read_ready = 0;
+
+ if ((flags & MSG_PEEK) == 0) {
+ c->socket.read_ready = 0;
+ }
return n;
}