summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_conn_read.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2018-10-22 16:01:10 +0300
committerValentin Bartenev <vbart@nginx.com>2018-10-22 16:01:10 +0300
commita4aaf906794d9f82710614ba368a36500e8a8254 (patch)
tree3ce7fb87345badc3ae86f2b4822ce7464f10111d /src/nxt_conn_read.c
parent161e1839a5e3d9d906c047c2464a239a632d42c2 (diff)
downloadunit-a4aaf906794d9f82710614ba368a36500e8a8254.tar.gz
unit-a4aaf906794d9f82710614ba368a36500e8a8254.tar.bz2
Re-engineered timers.
To optimize rbtree operations, all changes are stored in array and later processed in batches. The previous implementation of this mechanics had a number of design flaws. Each change was saved in a new array entry; until the changes were applied, the timer remained in an intermediate state (NXT_TIMER_CHANGING). This intermediate state didn't allow to identify if time was going to be disabled or enabled. However, the nxt_conn_io_read() function relied on this information; as a result, in some cases the read timeout wasn't set. Also, the nxt_timer_delete() function did not reliably track whether a timer was added to the work queue. It checked the NXT_TIMER_ENQUEUED state of a timer, but this state could be reset to NXT_TIMER_DISABLED by a nxt_timer_disable() call or another nxt_timer_delete() call. Now, instead of keeping the whole history of the timer's changes, the new implementation updates the timer state immediately, and only one operation is added to the array to add or delete timer in the rbtree according to its final state.
Diffstat (limited to 'src/nxt_conn_read.c')
-rw-r--r--src/nxt_conn_read.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/nxt_conn_read.c b/src/nxt_conn_read.c
index 21086233..e458bf81 100644
--- a/src/nxt_conn_read.c
+++ b/src/nxt_conn_read.c
@@ -105,7 +105,7 @@ nxt_conn_io_read(nxt_task_t *task, void *obj, void *data)
* occured during read operation, it toggled write event
* internally so only read timer should be set.
*/
- if (c->read_timer.state == NXT_TIMER_DISABLED) {
+ if (!c->read_timer.enabled) {
nxt_conn_timer(engine, c, state, &c->read_timer);
}
@@ -117,7 +117,7 @@ nxt_conn_io_read(nxt_task_t *task, void *obj, void *data)
nxt_fd_event_enable_read(engine, &c->socket);
}
- if (state->timer_autoreset || c->read_timer.state == NXT_TIMER_DISABLED) {
+ if (state->timer_autoreset || !c->read_timer.enabled) {
nxt_conn_timer(engine, c, state, &c->read_timer);
}
}