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