Index: trunk/willow/src/willow/flowio.cc |
— | — | @@ -118,7 +118,10 @@ |
119 | 119 | /* _off was increased by the previous send, reduce _saved |
120 | 120 | * appropriately |
121 | 121 | */ |
122 | | - _saved -= _off; |
| 122 | + if (_off >= _saved) |
| 123 | + _saved = _off = 0; |
| 124 | + else |
| 125 | + _saved -= _off; |
123 | 126 | |
124 | 127 | if (_saved) { |
125 | 128 | switch (this->_maybe_dio_send(_off, _savebuf, _saved, _off)) { |
— | — | @@ -139,7 +142,7 @@ |
140 | 143 | if (_off >= _saved) |
141 | 144 | _off = _saved = 0; |
142 | 145 | |
143 | | - read = s->read(_savebuf + _off + _saved, DIOBUFSZ); |
| 146 | + read = s->read(_savebuf + _off + _saved, DIOBUFSZ - (_off + _saved)); |
144 | 147 | if (read == 0) { |
145 | 148 | sp_cork(); |
146 | 149 | switch (this->_sp_data_empty()) { |
— | — | @@ -189,59 +192,69 @@ |
190 | 193 | sink_result |
191 | 194 | socket_sink::data_ready(char const *buf, size_t len, ssize_t &discard) |
192 | 195 | { |
193 | | -ssize_t off = 0; |
194 | | - |
195 | | - while (off < len) { |
196 | | - ssize_t wrote; |
197 | | - switch (wrote = _socket->write(buf + off, len - off)) { |
198 | | - case -1: |
199 | | - if (errno == EAGAIN) { |
200 | | - _sink_spigot->sp_cork(); |
201 | | - if (!_reg) { |
202 | | - _socket->writeback(polycaller<wsocket *, int>( |
203 | | - *this, &socket_sink::_socketcall), 0); |
204 | | - _reg = true; |
205 | | - } |
206 | | - return sink_result_blocked; |
| 196 | +ssize_t wrote; |
| 197 | + if ((wrote = _socket->write(buf + off, len - off)) == -1) { |
| 198 | + if (errno == EAGAIN) { |
| 199 | + _sink_spigot->sp_cork(); |
| 200 | + if (!_reg) { |
| 201 | + _socket->writeback(polycaller<wsocket *, int>( |
| 202 | + *this, &socket_sink::_socketcall), 0); |
| 203 | + _reg = true; |
207 | 204 | } |
208 | | - _sink_spigot->sp_cork(); |
209 | | - return sink_result_error; |
210 | | - break; |
| 205 | + return sink_result_blocked; |
211 | 206 | } |
212 | | - discard += wrote; |
213 | | - _counter += wrote; |
214 | | - off += wrote; |
| 207 | + _sink_spigot->sp_cork(); |
| 208 | + return sink_result_error; |
215 | 209 | } |
216 | | - return sink_result_okay; |
| 210 | + |
| 211 | + discard += wrote; |
| 212 | + _counter += wrote; |
| 213 | + |
| 214 | + if (len == wrote) { |
| 215 | + return sink_result_okay; |
| 216 | + } else { |
| 217 | + _sink_spigot->sp_cork(); |
| 218 | + if (!_reg) { |
| 219 | + _socket->writeback(polycaller<wsocket *, int>( |
| 220 | + *this, &socket_sink::_socketcall), 0); |
| 221 | + _reg = true; |
| 222 | + } |
| 223 | + return sink_result_blocked; |
| 224 | + } |
217 | 225 | } |
218 | 226 | |
219 | 227 | sink_result |
220 | 228 | socket_sink::dio_ready(int fd, off_t off, size_t len, ssize_t &discard) |
221 | 229 | { |
222 | | -ssize_t got = 0; |
223 | | - |
224 | | - while (got < len) { |
225 | | - ssize_t wrote; |
226 | | - switch (wrote = _socket->sendfile(fd, &off, len)) { |
227 | | - case -1: |
228 | | - if (errno == EAGAIN) { |
229 | | - _sink_spigot->sp_cork(); |
230 | | - if (!_reg) { |
231 | | - _socket->writeback(polycaller<wsocket *, int>( |
232 | | - *this, &socket_sink::_socketcall), 0); |
233 | | - _reg = true; |
234 | | - } |
235 | | - return sink_result_blocked; |
| 230 | +ssize_t wrote; |
| 231 | + if ((wrote = _socket->sendfile(fd, &off, len)) == -1) { |
| 232 | + if (errno == EAGAIN) { |
| 233 | + _sink_spigot->sp_cork(); |
| 234 | + if (!_reg) { |
| 235 | + _socket->writeback(polycaller<wsocket *, int>( |
| 236 | + *this, &socket_sink::_socketcall), 0); |
| 237 | + _reg = true; |
236 | 238 | } |
237 | | - _sink_spigot->sp_cork(); |
238 | | - return sink_result_error; |
239 | | - break; |
| 239 | + return sink_result_blocked; |
240 | 240 | } |
241 | | - discard += wrote; |
242 | | - _counter += wrote; |
243 | | - got += wrote; |
| 241 | + _sink_spigot->sp_cork(); |
| 242 | + return sink_result_error; |
| 243 | + break; |
244 | 244 | } |
245 | | - return sink_result_okay; |
| 245 | + discard += wrote; |
| 246 | + _counter += wrote; |
| 247 | + |
| 248 | + if (len == wrote) { |
| 249 | + return sink_result_okay; |
| 250 | + } else { |
| 251 | + _sink_spigot->sp_cork(); |
| 252 | + if (!_reg) { |
| 253 | + _socket->writeback(polycaller<wsocket *, int>( |
| 254 | + *this, &socket_sink::_socketcall), 0); |
| 255 | + _reg = true; |
| 256 | + } |
| 257 | + return sink_result_blocked; |
| 258 | + } |
246 | 259 | } |
247 | 260 | |
248 | 261 | tss<file_spigot::cache_map> file_spigot::_cache; |