integrate Linux sendfile into trysendfile.c infrastructure

first stab at AIX 5 sendfile support
master
leitner 21 years ago
parent 2f8d7b149a
commit cae1a561fd

@ -548,7 +548,7 @@ clean:
rm -f *.o *.a *.da *.bbg *.bb core t haveip6.h haven2i.h \
havesl.h haveinline.h iopause.h select.h havekqueue.h haveepoll.h \
libepoll havesigio.h havebsdsf.h havesendfile.h havescope.h havedevpoll.h \
Makefile dep
Makefile dep libsocket
INCLUDES=buffer.h byte.h fmt.h ip4.h ip6.h mmap.h scan.h socket.h str.h stralloc.h \
uint16.h uint32.h uint64.h open.h textcode.h tai.h taia.h dns.h iopause.h case.h \

@ -17,30 +17,6 @@ int64 io_sendfile(int64 s,int64 fd,uint64 off,uint64 n) {
return (errno==EAGAIN?(sbytes?sbytes:-1):-3);
return n;
}
#elif defined(__linux__)
#if defined(__GLIBC__)
#include <sys/sendfile.h>
#elif defined(__dietlibc__)
#include <sys/sendfile.h>
#else
#include <linux/unistd.h>
_syscall4(int,sendfile,int,out,int,in,long *,offset,unsigned long,count)
#endif
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;
}
return i;
}
#elif defined(HAVE_SENDFILE)
@ -67,6 +43,30 @@ int64 io_sendfile(int64 out,int64 in,uint64 off,uint64 bytes) {
return sendfile64(out,in,&o,bytes);
}
#elif defined(__linux__)
#if defined(__GLIBC__)
#include <sys/sendfile.h>
#elif defined(__dietlibc__)
#include <sys/sendfile.h>
#else
#include <linux/unistd.h>
_syscall4(int,sendfile,int,out,int,in,long *,offset,unsigned long,count)
#endif
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;
}
return i;
}
#endif
#else

@ -34,6 +34,48 @@ int main() {
perror("sendfile");
return 0;
}
#elif defined (_AIX)
#define _FILE_OFFSET_BITS 64
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdio.h>
int main() {
int fd=open("havesendfile.c",0);
struct sf_parms p;
int destfd=1;
p.header_data="header";
p.header_length=6;
p.file_descriptor=fd;
p.file_offset=0;
p.file_bytes=23;
p.trailer_data="footer";
p.trailer_length=6;
if (send_file(&destfd,&p,0)>=0)
printf("sent %lu bytes.\n",p.bytes_sent);
}
#elif defined(__linux__)
#define _FILE_OFFSET_BITS 64
#if defined(__GLIBC__)
#include <sys/sendfile.h>
#elif defined(__dietlibc__)
#include <sys/sendfile.h>
#else
#include <linux/unistd.h>
_syscall4(int,sendfile,int,out,int,in,long *,offset,unsigned long,count)
#endif
int main() {
int fd=open("havesendfile.c",0);
off_t o=0;
off_t r=sendfile(1,fd,&o,23);
if (r!=-1)
printf("sent %llu bytes.\n",r);
}
#else
#error unsupported architecture
#endif

Loading…
Cancel
Save