make iob_send return aggregate total
This commit is contained in:
parent
3c4f34b95e
commit
8fd1875041
@ -15,7 +15,7 @@
|
|||||||
int64 iob_send(int64 s,io_batch* b) {
|
int64 iob_send(int64 s,io_batch* b) {
|
||||||
io_entry* e,* last;
|
io_entry* e,* last;
|
||||||
struct iovec* v;
|
struct iovec* v;
|
||||||
int64 sent;
|
int64 total,sent;
|
||||||
long i;
|
long i;
|
||||||
long headers;
|
long headers;
|
||||||
#ifdef BSD_SENDFILE
|
#ifdef BSD_SENDFILE
|
||||||
@ -25,6 +25,7 @@ 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));
|
v=alloca(b->bufs*sizeof(struct iovec));
|
||||||
|
total=0;
|
||||||
for (;;) {
|
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 */
|
||||||
@ -67,6 +68,10 @@ 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>0)
|
||||||
|
total+=sent;
|
||||||
|
else
|
||||||
|
if (!total) return -1;
|
||||||
if (sent==b->bytesleft) {
|
if (sent==b->bytesleft) {
|
||||||
b->bytesleft=0;
|
b->bytesleft=0;
|
||||||
break;
|
break;
|
||||||
@ -86,5 +91,5 @@ int64 iob_send(int64 s,io_batch* b) {
|
|||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
abort:
|
abort:
|
||||||
return sent;
|
return total;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "iob.h"
|
#include "iob.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
int64 fd;
|
int64 fd;
|
||||||
@ -9,5 +10,7 @@ main() {
|
|||||||
assert(iob_addbuf(b,"Huhu",4));
|
assert(iob_addbuf(b,"Huhu",4));
|
||||||
assert(iob_addbuf(b," fnord\n",7));
|
assert(iob_addbuf(b," fnord\n",7));
|
||||||
assert(iob_addfile(b,fd,10,10));
|
assert(iob_addfile(b,fd,10,10));
|
||||||
iob_send(1,b);
|
buffer_puts(buffer_2,"iob_send returned ");
|
||||||
|
buffer_putlong(buffer_2,iob_send(1,b));
|
||||||
|
buffer_putsflush(buffer_2,".\n");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user