work around broken Linux sendfile API (offset 64-bit but count 32-bit)

master
leitner 21 years ago
parent ed1558cd3d
commit 11f0616cf3

@ -1,5 +1,6 @@
0.20:
add errmsg API
work around broken Linux sendfile API (offset 64-bit but count 32-bit)
0.19.2:
for some reason, a botched dependency slipped in the the Makefile

@ -86,15 +86,28 @@ _syscall4(int,sendfile,int,out,int,in,long *,offset,unsigned long,count)
int64 io_sendfile(int64 s,int64 fd,uint64 off,uint64 n) {
off_t o=off;
io_entry* e=array_get(&io_fds,sizeof(io_entry),s);
off_t i=sendfile(s,fd,&o,n);
if (i==-1) {
if (e) {
e->canwrite=0;
e->next_write=-1;
}
if (errno!=EAGAIN) i=-3;
off_t i;
uint64 done=0;
/* What a spectacularly broken design for sendfile64.
* The offset is 64-bit for sendfile64, but the count is not. */
while (n) {
off_t todo=n>0x7fffffff?0x7fffffff:n;
i=sendfile(s,fd,&o,todo);
if (i==todo) {
done+=todo;
n-=todo;
if (n==0) return done;
continue;
} else if (i==-1) {
if (e) {
e->canwrite=0;
e->next_write=-1;
}
return (errno==EAGAIN?-1:-3);
} else
return done+i;
}
return i;
return 0;
}
#endif

Loading…
Cancel
Save