Mercurial > hg > nginx
comparison src/os/unix/ngx_readv_chain.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 | 151fd02a4317 |
comparison
equal
deleted
inserted
replaced
6505:5ad379eab6fa | 6506:dc1ae0056a1e |
---|---|
104 "readv: %ui, last:%uz", vec.nelts, iov->iov_len); | 104 "readv: %ui, last:%uz", vec.nelts, iov->iov_len); |
105 | 105 |
106 do { | 106 do { |
107 n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts); | 107 n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts); |
108 | 108 |
109 if (n >= 0) { | 109 if (n == 0) { |
110 rev->ready = 0; | |
111 rev->eof = 1; | |
112 | |
113 #if (NGX_HAVE_KQUEUE) | |
114 | |
115 /* | |
116 * on FreeBSD readv() may return 0 on closed socket | |
117 * even if kqueue reported about available data | |
118 */ | |
119 | |
120 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | |
121 rev->available = 0; | |
122 } | |
123 | |
124 #endif | |
125 | |
126 return 0; | |
127 } | |
128 | |
129 if (n > 0) { | |
110 | 130 |
111 #if (NGX_HAVE_KQUEUE) | 131 #if (NGX_HAVE_KQUEUE) |
112 | 132 |
113 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | 133 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
114 rev->available -= n; | 134 rev->available -= n; |
115 | 135 |
116 /* | 136 /* |
117 * rev->available may be negative here because some additional | 137 * rev->available may be negative here because some additional |
118 * bytes may be received between kevent() and recv() | 138 * bytes may be received between kevent() and readv() |
119 */ | 139 */ |
120 | 140 |
121 if (rev->available <= 0) { | 141 if (rev->available <= 0) { |
122 if (!rev->pending_eof) { | 142 if (!rev->pending_eof) { |
123 rev->ready = 0; | 143 rev->ready = 0; |
126 if (rev->available < 0) { | 146 if (rev->available < 0) { |
127 rev->available = 0; | 147 rev->available = 0; |
128 } | 148 } |
129 } | 149 } |
130 | 150 |
131 if (n == 0) { | |
132 | |
133 /* | |
134 * on FreeBSD recv() may return 0 on closed socket | |
135 * even if kqueue reported about available data | |
136 */ | |
137 | |
138 #if 0 | |
139 ngx_log_error(NGX_LOG_ALERT, c->log, 0, | |
140 "readv() returned 0 while kevent() reported " | |
141 "%d available bytes", rev->available); | |
142 #endif | |
143 | |
144 rev->ready = 0; | |
145 rev->eof = 1; | |
146 rev->available = 0; | |
147 } | |
148 | |
149 return n; | 151 return n; |
150 } | 152 } |
151 | 153 |
152 #endif /* NGX_HAVE_KQUEUE */ | 154 #endif |
153 | 155 |
154 if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) { | 156 if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) { |
155 rev->ready = 0; | 157 rev->ready = 0; |
156 } | |
157 | |
158 if (n == 0) { | |
159 rev->eof = 1; | |
160 } | 158 } |
161 | 159 |
162 return n; | 160 return n; |
163 } | 161 } |
164 | 162 |