comparison src/os/unix/ngx_recv.c @ 6506:dc1ae0056a1e

Fixed small inconsistency in handling EOF among receive functions. Now all functions always drop the ready flag in this case.
author Valentin Bartenev <vbart@nginx.com>
date Fri, 08 Apr 2016 16:39:49 +0300
parents f01ab2dbcfdc
children 8ee94ecd3a50
comparison
equal deleted inserted replaced
6505:5ad379eab6fa 6506:dc1ae0056a1e
52 n = recv(c->fd, buf, size, 0); 52 n = recv(c->fd, buf, size, 0);
53 53
54 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, 54 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
55 "recv: fd:%d %z of %uz", c->fd, n, size); 55 "recv: fd:%d %z of %uz", c->fd, n, size);
56 56
57 if (n >= 0) { 57 if (n == 0) {
58 rev->ready = 0;
59 rev->eof = 1;
60
61 /*
62 * on FreeBSD recv() may return 0 on closed socket
63 * even if kqueue reported about available data
64 */
65
66 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
67 rev->available = 0;
68 }
69
70 return 0;
71 }
72
73 if (n > 0) {
74
58 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { 75 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
59 rev->available -= n; 76 rev->available -= n;
60 77
61 /* 78 /*
62 * rev->available may be negative here because some additional 79 * rev->available may be negative here because some additional
71 if (rev->available < 0) { 88 if (rev->available < 0) {
72 rev->available = 0; 89 rev->available = 0;
73 } 90 }
74 } 91 }
75 92
76 if (n == 0) {
77
78 /*
79 * on FreeBSD recv() may return 0 on closed socket
80 * even if kqueue reported about available data
81 */
82
83 rev->ready = 0;
84 rev->eof = 1;
85 rev->available = 0;
86 }
87
88 return n; 93 return n;
89 } 94 }
90 95
91 if ((size_t) n < size 96 if ((size_t) n < size
92 && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) 97 && !(ngx_event_flags & NGX_USE_GREEDY_EVENT))
93 { 98 {
94 rev->ready = 0; 99 rev->ready = 0;
95 }
96
97 if (n == 0) {
98 rev->eof = 1;
99 } 100 }
100 101
101 return n; 102 return n;
102 } 103 }
103 104