remove socket_sendfile now that we have io_sendfile
make Makefile should also work with a BSD make ;)master
parent
0f60bacb89
commit
0bae11b63e
@ -1,35 +0,0 @@
|
||||
.TH socket_sendfile 3
|
||||
.SH NAME
|
||||
socket_sendfile \- send a file over a TCP socket
|
||||
.SH SYNTAX
|
||||
.B #include <socket.h>
|
||||
|
||||
int \fBsocket_sendfile\fP(int \fIout\fR, int \fIin\fR, uint32 \fIoffset\fR,
|
||||
uint32 \fIbytes\fR);
|
||||
.SH DESCRIPTION
|
||||
socket_sendfile sends \fIbytes\fR bytes starting at \fIoffset\fR in the
|
||||
file \fIin\fR to the socket connected to file descriptor \fIout\fR.
|
||||
|
||||
The socket must be connected.
|
||||
|
||||
Note that the underlying sendfile system call is system specific and
|
||||
currently only implemented on Linux. On other operating systems, it is
|
||||
emulated with a read/write loop.
|
||||
.SH RETURN VALUE
|
||||
socket_sendfile returns 0 if the data was sent successfully. If not,
|
||||
it returns -1 and sets errno appropriately.
|
||||
.SH EXAMPLE
|
||||
#include <socket.h>
|
||||
#include <open.h>
|
||||
|
||||
int \fIs\fR;
|
||||
char \fIip\fR[4];
|
||||
uint16 \fIp\fR;
|
||||
int \fIfd\fR = open_read("/etc/passwd");
|
||||
|
||||
\fIs\fR = socket_tcp4();
|
||||
socket_connect4(s,ip,p);
|
||||
socket_sendfile(s,fd,0,23);
|
||||
|
||||
.SH "SEE ALSO"
|
||||
socket_send6(3)
|
@ -1,60 +0,0 @@
|
||||
#include <unistd.h>
|
||||
#include "socket.h"
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#include <sys/sendfile.h>
|
||||
#else
|
||||
#ifdef __dietlibc__
|
||||
#include <sys/sendfile.h>
|
||||
#else
|
||||
#include <linux/unistd.h>
|
||||
_syscall4(int,sendfile,int,out,int,in,long *,offset,unsigned long,count)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int socket_sendfile(int out,int in,uint32 offset,uint32 bytes) {
|
||||
off_t tmp=offset;
|
||||
return sendfile(out,in,&tmp,bytes);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#ifdef _HPUX_SOURCE
|
||||
|
||||
/* http://www.devresource.hp.com/STK/man/10.30/sendfile_2.html */
|
||||
#include <sys/socket.h>
|
||||
int socket_sendfile(int out,int in,uint32 offset,uint32 bytes) {
|
||||
return sendfile(out,in,offset,bytes,0,0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define BUFSIZE 16384
|
||||
|
||||
int socket_sendfile(int out,int in,uint32 offset,uint32 bytes) {
|
||||
char buf[BUFSIZE];
|
||||
int n,m;
|
||||
uint32 sent=0;
|
||||
if (lseek(in,offset,SEEK_SET) != offset)
|
||||
return -1;
|
||||
while (bytes>0) {
|
||||
char* tmp=buf;
|
||||
if ((n=read(in,tmp,(bytes<BUFSIZE)?bytes:BUFSIZE))<=0)
|
||||
return (sent?sent:-1);
|
||||
while (n>0) {
|
||||
if ((m=write(out,tmp,n))<0)
|
||||
goto abort;
|
||||
sent+=m;
|
||||
n-=m;
|
||||
tmp+=m;
|
||||
}
|
||||
}
|
||||
abort:
|
||||
return sent;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue