mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 14:13:33 -06:00
Fixed small inconsistency in handling EOF among receive functions.
Now all functions always drop the ready flag in this case.
This commit is contained in:
parent
8e7d8757c6
commit
900ef17c47
@ -106,7 +106,27 @@ ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit)
|
|||||||
do {
|
do {
|
||||||
n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts);
|
n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts);
|
||||||
|
|
||||||
if (n >= 0) {
|
if (n == 0) {
|
||||||
|
rev->ready = 0;
|
||||||
|
rev->eof = 1;
|
||||||
|
|
||||||
|
#if (NGX_HAVE_KQUEUE)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* on FreeBSD readv() may return 0 on closed socket
|
||||||
|
* even if kqueue reported about available data
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
|
||||||
|
rev->available = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n > 0) {
|
||||||
|
|
||||||
#if (NGX_HAVE_KQUEUE)
|
#if (NGX_HAVE_KQUEUE)
|
||||||
|
|
||||||
@ -115,7 +135,7 @@ ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* rev->available may be negative here because some additional
|
* rev->available may be negative here because some additional
|
||||||
* bytes may be received between kevent() and recv()
|
* bytes may be received between kevent() and readv()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (rev->available <= 0) {
|
if (rev->available <= 0) {
|
||||||
@ -128,37 +148,15 @@ ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == 0) {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* on FreeBSD recv() may return 0 on closed socket
|
|
||||||
* even if kqueue reported about available data
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
ngx_log_error(NGX_LOG_ALERT, c->log, 0,
|
|
||||||
"readv() returned 0 while kevent() reported "
|
|
||||||
"%d available bytes", rev->available);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rev->ready = 0;
|
|
||||||
rev->eof = 1;
|
|
||||||
rev->available = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* NGX_HAVE_KQUEUE */
|
#endif
|
||||||
|
|
||||||
if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) {
|
if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) {
|
||||||
rev->ready = 0;
|
rev->ready = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == 0) {
|
|
||||||
rev->eof = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,24 @@ ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size)
|
|||||||
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
||||||
"recv: fd:%d %z of %uz", c->fd, n, size);
|
"recv: fd:%d %z of %uz", c->fd, n, size);
|
||||||
|
|
||||||
if (n >= 0) {
|
if (n == 0) {
|
||||||
|
rev->ready = 0;
|
||||||
|
rev->eof = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* on FreeBSD recv() may return 0 on closed socket
|
||||||
|
* even if kqueue reported about available data
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
|
||||||
|
rev->available = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n > 0) {
|
||||||
|
|
||||||
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
|
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
|
||||||
rev->available -= n;
|
rev->available -= n;
|
||||||
|
|
||||||
@ -73,18 +90,6 @@ ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == 0) {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* on FreeBSD recv() may return 0 on closed socket
|
|
||||||
* even if kqueue reported about available data
|
|
||||||
*/
|
|
||||||
|
|
||||||
rev->ready = 0;
|
|
||||||
rev->eof = 1;
|
|
||||||
rev->available = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,10 +99,6 @@ ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size)
|
|||||||
rev->ready = 0;
|
rev->ready = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == 0) {
|
|
||||||
rev->eof = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user