Index: trunk/willow/src/lib/wnet/wnet.c |
— | — | @@ -176,6 +176,7 @@ |
177 | 177 | fde->fde_epflags = 0; |
178 | 178 | bzero(&fde->fde_readbuf, sizeof(fde->fde_readbuf)); |
179 | 179 | fde->fde_flags.open = 0; |
| 180 | + bzero(&fde->fde_ev, sizeof(fde->fde_ev)); |
180 | 181 | } |
181 | 182 | |
182 | 183 | int |
— | — | @@ -219,7 +220,6 @@ |
220 | 221 | int fd; |
221 | 222 | { |
222 | 223 | struct fde *e = &fde_table[fd]; |
223 | | - |
224 | 224 | wnet_register(fd, FDE_READ | FDE_WRITE, NULL, NULL); |
225 | 225 | (void)close(e->fde_fd); |
226 | 226 | if (e->fde_cdata) |
— | — | @@ -256,8 +256,7 @@ |
257 | 257 | wb->wb_off = off; |
258 | 258 | |
259 | 259 | e->fde_wdata = wb; |
260 | | - if (!(flags & WNET_IMMED)) |
261 | | - wnet_register(e->fde_fd, FDE_WRITE, wnet_sendfile_do, e); |
| 260 | + wnet_register(e->fde_fd, FDE_WRITE, wnet_sendfile_do, e); |
262 | 261 | wnet_sendfile_do(e); |
263 | 262 | return 0; |
264 | 263 | } |
— | — | @@ -286,8 +285,7 @@ |
287 | 286 | |
288 | 287 | e->fde_wdata = wb; |
289 | 288 | |
290 | | - if (!(flags & WNET_IMMED)) |
291 | | - wnet_register(e->fde_fd, FDE_WRITE, wnet_write_do, e); |
| 289 | + wnet_register(e->fde_fd, FDE_WRITE, wnet_write_do, e); |
292 | 290 | wnet_write_do(e); |
293 | 291 | } |
294 | 292 | |
— | — | @@ -361,7 +359,24 @@ |
362 | 360 | #else |
363 | 361 | # error i dont know how to invoke sendfile on this system |
364 | 362 | #endif |
| 363 | + |
| 364 | +#ifdef __linux |
| 365 | + /* |
| 366 | + * The Linux sendfile() manual page says: |
| 367 | + * |
| 368 | + * When sendfile() returns, this variable will be set to the offset of the byte following the |
| 369 | + * last byte that was read. |
| 370 | + * |
| 371 | + * However, this is not true on x86-64 when we are compiled as a 32-bit binary; the correct |
| 372 | + * number of bytes is returned, but off is _not_ updated. So, we fudge it into working as we |
| 373 | + * expect. |
| 374 | + */ |
| 375 | + if (i > 0) |
| 376 | + buf->wb_off += i; |
| 377 | +#endif |
| 378 | + |
365 | 379 | buf->wb_size -= (buf->wb_off - origoff); |
| 380 | + WDEBUG((WLOG_DEBUG, "sent %d bytes i=%d", (int)(buf->wb_off - origoff), i)); |
366 | 381 | |
367 | 382 | if (buf->wb_size == 0) { |
368 | 383 | wnet_register(e->fde_fd, FDE_WRITE, NULL, NULL); |