master
leitner 22 years ago
parent 63ba06c763
commit 3c4f34b95e

@ -24,9 +24,10 @@ int64 iob_send(int64 s,io_batch* b) {
if (b->bytesleft==0) return 0; if (b->bytesleft==0) return 0;
last=array_start(&b->b)+array_bytes(&b->b); last=array_start(&b->b)+array_bytes(&b->b);
v=alloca(b->bufs*sizeof(struct iovec));
for (;;) {
if (!(e=array_get(&b->b,sizeof(io_entry),b->next))) if (!(e=array_get(&b->b,sizeof(io_entry),b->next)))
return -1; /* can't happen error */ return -1; /* can't happen error */
v=alloca(b->bufs*sizeof(struct iovec));
#ifdef BSD_SENDFILE #ifdef BSD_SENDFILE
/* BSD sendfile can send headers and trailers. If we run on BSD, we /* BSD sendfile can send headers and trailers. If we run on BSD, we
* should try to exploit this. */ * should try to exploit this. */
@ -66,20 +67,24 @@ int64 iob_send(int64 s,io_batch* b) {
else else
sent=io_sendfile(s,e->fd,e->offset,e->n); sent=io_sendfile(s,e->fd,e->offset,e->n);
#endif #endif
if (sent==b->bytesleft) if (sent==b->bytesleft) {
b->bytesleft=0; b->bytesleft=0;
else if (sent>0) { break;
} else if (sent>0) {
int64 rest=sent; int64 rest=sent;
b->bytesleft-=rest; b->bytesleft-=rest;
for (i=0; e+i<last; ++i) { for (i=0; e+i<last; ++i) {
if (e[i].n-e[i].offset<rest) { if (e[i].n-e[i].offset<=rest) {
rest-=e[i].n-e[i].offset; rest-=e[i].n-e[i].offset;
++b->next; ++b->next;
if (!rest) break;
} else { } else {
e[i].offset+=rest; e[i].offset+=rest;
break; goto abort;
} }
} }
} else break;
} }
abort:
return sent; return sent;
} }

Loading…
Cancel
Save