mirror of
https://github.com/nginx/nginx.git
synced 2025-02-25 18:55:26 -06:00
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.
This commit is contained in:
@@ -51,6 +51,20 @@ ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if (NGX_HAVE_EPOLLRDHUP)
|
||||
|
||||
if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"readv: eof:%d, avail:%d",
|
||||
rev->pending_eof, rev->available);
|
||||
|
||||
if (!rev->available && !rev->pending_eof) {
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
prev = NULL;
|
||||
@@ -149,6 +163,24 @@ ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit)
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if (NGX_HAVE_EPOLLRDHUP)
|
||||
|
||||
if ((ngx_event_flags & NGX_USE_EPOLL_EVENT)
|
||||
&& ngx_use_epoll_rdhup)
|
||||
{
|
||||
if (n < size) {
|
||||
if (!rev->pending_eof) {
|
||||
rev->ready = 0;
|
||||
}
|
||||
|
||||
rev->available = 0;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) {
|
||||
|
||||
@@ -48,6 +48,21 @@ ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if (NGX_HAVE_EPOLLRDHUP)
|
||||
|
||||
if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||
"recv: eof:%d, avail:%d",
|
||||
rev->pending_eof, rev->available);
|
||||
|
||||
if (!rev->available && !rev->pending_eof) {
|
||||
rev->ready = 0;
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
do {
|
||||
@@ -99,6 +114,24 @@ ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size)
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if (NGX_HAVE_EPOLLRDHUP)
|
||||
|
||||
if ((ngx_event_flags & NGX_USE_EPOLL_EVENT)
|
||||
&& ngx_use_epoll_rdhup)
|
||||
{
|
||||
if ((size_t) n < size) {
|
||||
if (!rev->pending_eof) {
|
||||
rev->ready = 0;
|
||||
}
|
||||
|
||||
rev->available = 0;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if ((size_t) n < size
|
||||
|
||||
Reference in New Issue
Block a user