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: 0.20:
add errmsg API add errmsg API
work around broken Linux sendfile API (offset 64-bit but count 32-bit)
0.19.2: 0.19.2:
for some reason, a botched dependency slipped in the the Makefile 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) { int64 io_sendfile(int64 s,int64 fd,uint64 off,uint64 n) {
off_t o=off; off_t o=off;
io_entry* e=array_get(&io_fds,sizeof(io_entry),s); io_entry* e=array_get(&io_fds,sizeof(io_entry),s);
off_t i=sendfile(s,fd,&o,n); off_t i;
if (i==-1) { uint64 done=0;
if (e) { /* What a spectacularly broken design for sendfile64.
e->canwrite=0; * The offset is 64-bit for sendfile64, but the count is not. */
e->next_write=-1; while (n) {
} off_t todo=n>0x7fffffff?0x7fffffff:n;
if (errno!=EAGAIN) i=-3; 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 #endif

Loading…
Cancel
Save