Klaus Demo nginx / 900ef17
Fixed small inconsistency in handling EOF among receive functions. Now all functions always drop the ready flag in this case. Valentin Bartenev 6 years ago
2 changed file(s) with 41 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
105105 do {
106106 n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts);
107107
108 if (n >= 0) {
108 if (n == 0) {
109 rev->ready = 0;
110 rev->eof = 1;
111
112 #if (NGX_HAVE_KQUEUE)
113
114 /*
115 * on FreeBSD readv() may return 0 on closed socket
116 * even if kqueue reported about available data
117 */
118
119 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
120 rev->available = 0;
121 }
122
123 #endif
124
125 return 0;
126 }
127
128 if (n > 0) {
109129
110130 #if (NGX_HAVE_KQUEUE)
111131
114134
115135 /*
116136 * rev->available may be negative here because some additional
117 * bytes may be received between kevent() and recv()
137 * bytes may be received between kevent() and readv()
118138 */
119139
120140 if (rev->available <= 0) {
127147 }
128148 }
129149
130 if (n == 0) {
131
132 /*
133 * on FreeBSD recv() may return 0 on closed socket
134 * even if kqueue reported about available data
135 */
136
137 #if 0
138 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
139 "readv() returned 0 while kevent() reported "
140 "%d available bytes", rev->available);
141 #endif
142
143 rev->ready = 0;
144 rev->eof = 1;
145 rev->available = 0;
146 }
147
148150 return n;
149151 }
150152
151 #endif /* NGX_HAVE_KQUEUE */
153 #endif
152154
153155 if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) {
154156 rev->ready = 0;
155 }
156
157 if (n == 0) {
158 rev->eof = 1;
159157 }
160158
161159 return n;
5353 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
5454 "recv: fd:%d %z of %uz", c->fd, n, size);
5555
56 if (n >= 0) {
56 if (n == 0) {
57 rev->ready = 0;
58 rev->eof = 1;
59
60 /*
61 * on FreeBSD recv() may return 0 on closed socket
62 * even if kqueue reported about available data
63 */
64
65 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
66 rev->available = 0;
67 }
68
69 return 0;
70 }
71
72 if (n > 0) {
73
5774 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
5875 rev->available -= n;
5976
7289 }
7390 }
7491
75 if (n == 0) {
76
77 /*
78 * on FreeBSD recv() may return 0 on closed socket
79 * even if kqueue reported about available data
80 */
81
82 rev->ready = 0;
83 rev->eof = 1;
84 rev->available = 0;
85 }
86
8792 return n;
8893 }
8994
9196 && !(ngx_event_flags & NGX_USE_GREEDY_EVENT))
9297 {
9398 rev->ready = 0;
94 }
95
96 if (n == 0) {
97 rev->eof = 1;
9899 }
99100
100101 return n;