diff --git a/src/xpdev/sockwrap.c b/src/xpdev/sockwrap.c index 6a919d436f5d6f7f2c4a01d0c675836898708083..de742f69341faf28bdabbdb42ba10102adc238b9 100644 --- a/src/xpdev/sockwrap.c +++ b/src/xpdev/sockwrap.c @@ -48,6 +48,26 @@ int sendfilesocket(int sock, int file, long *offset, long count) { +/* sendfile() on Linux may or may not work with non-blocking sockets ToDo */ +#if defined(__FreeBSD__) + off_t total=0; + off_t wr=0; + int i; + long len; + + len=filelength(file); + if(count<1 || count>len) { + count=len; + count-=offset==NULL?0:*offset; + } + while((i=sendfile(file,sock,(offset==NULL?0:*offset)+total,count-total,NULL,&wr,0))==-1 && errno==EAGAIN) { + total+=wr; + SLEEP(1); + } + if(i==0) + return((int)count); + return(i); +#else char* buf; long len; int rd; @@ -97,6 +117,7 @@ int sendfilesocket(int sock, int file, long *offset, long count) return(wr); return(total); +#endif } int recvfilesocket(int sock, int file, long *offset, long count)