comparison src/os/unix/ngx_recv.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
43 43
44 } else { 44 } else {
45 rev->ready = 0; 45 rev->ready = 0;
46 return NGX_AGAIN; 46 return NGX_AGAIN;
47 } 47 }
48 }
49 }
50
51 #endif
52
53 #if (NGX_HAVE_EPOLLRDHUP)
54
55 if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
56 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
57 "recv: eof:%d, avail:%d",
58 rev->pending_eof, rev->available);
59
60 if (!rev->available && !rev->pending_eof) {
61 rev->ready = 0;
62 return NGX_AGAIN;
48 } 63 }
49 } 64 }
50 65
51 #endif 66 #endif
52 67
99 return n; 114 return n;
100 } 115 }
101 116
102 #endif 117 #endif
103 118
119 #if (NGX_HAVE_EPOLLRDHUP)
120
121 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT)
122 && ngx_use_epoll_rdhup)
123 {
124 if ((size_t) n < size) {
125 if (!rev->pending_eof) {
126 rev->ready = 0;
127 }
128
129 rev->available = 0;
130 }
131
132 return n;
133 }
134
135 #endif
136
104 if ((size_t) n < size 137 if ((size_t) n < size
105 && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) 138 && !(ngx_event_flags & NGX_USE_GREEDY_EVENT))
106 { 139 {
107 rev->ready = 0; 140 rev->ready = 0;
108 } 141 }