comparison src/os/unix/ngx_readv_chain.c @ 6536:f7849bfb6d21

Improved EPOLLRDHUP handling. When it's known that the kernel supports EPOLLRDHUP, there is no need in additional recv() call to get EOF or error when the flag is absent in the event generated by the kernel. A special runtime test is done at startup to detect if EPOLLRDHUP is actually supported by the kernel because epoll_ctl() silently ignores unknown flags. With this knowledge it's now possible to drop the "ready" flag for partial read. Previously, the "ready" flag was kept until the recv() returned EOF or error. In particular, this change allows the lingering close heuristics (which relies on the "ready" flag state) to actually work on Linux, and not wait for more data in most cases. The "available" flag is now used in the read event with the semantics similar to the corresponding counter in kqueue.
author Valentin Bartenev <vbart@nginx.com>
date Fri, 13 May 2016 17:19:23 +0300
parents 151fd02a4317
children efd71d49bde0
comparison
equal deleted inserted replaced
6535:db699978a33f 6536:f7849bfb6d21
51 } 51 }
52 } 52 }
53 53
54 #endif 54 #endif
55 55
56 #if (NGX_HAVE_EPOLLRDHUP)
57
58 if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
59 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
60 "readv: eof:%d, avail:%d",
61 rev->pending_eof, rev->available);
62
63 if (!rev->available && !rev->pending_eof) {
64 return NGX_AGAIN;
65 }
66 }
67
68 #endif
69
56 prev = NULL; 70 prev = NULL;
57 iov = NULL; 71 iov = NULL;
58 size = 0; 72 size = 0;
59 73
60 vec.elts = iovs; 74 vec.elts = iovs;
149 return n; 163 return n;
150 } 164 }
151 165
152 #endif 166 #endif
153 167
168 #if (NGX_HAVE_EPOLLRDHUP)
169
170 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT)
171 && ngx_use_epoll_rdhup)
172 {
173 if (n < size) {
174 if (!rev->pending_eof) {
175 rev->ready = 0;
176 }
177
178 rev->available = 0;
179 }
180
181 return n;
182 }
183
184 #endif
185
154 if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) { 186 if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) {
155 rev->ready = 0; 187 rev->ready = 0;
156 } 188 }
157 189
158 return n; 190 return n;