From f484ecdc5f838f87b89d4fec343c1f753b04212f Mon Sep 17 00:00:00 2001 From: leitner Date: Thu, 8 Jan 2004 15:07:40 +0000 Subject: [PATCH] support HP-UX sendfile (thanks Rolf Eike Beer) --- CHANGES | 1 + GNUmakefile | 12 +++++++++--- io/io_sendfile.c | 14 ++++++++++++++ trysendfile.c | 24 ++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 trysendfile.c diff --git a/CHANGES b/CHANGES index f3e85ae..4a62c64 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,7 @@ apending 0 bytes to an empty array would fail it remove socket_sendfile now that we have io_sendfile break out alloca #include dependency into havealloca.h + support HP-UX sendfile64 (thanks to Rolf Eike Beer) 0.16: add buffer_fromsa (make buffer from stralloc) diff --git a/GNUmakefile b/GNUmakefile index 928301f..e7f8533 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -80,7 +80,7 @@ $(DNS_OBJS): dns.h stralloc.h taia.h tai.h uint64.h iopause.h $(CASE_OBJS): case.h $(ARRAY_OBJS): uint64.h array.h $(MULT_OBJS): uint64.h uint32.h uint16.h safemult.h -$(IO_OBJS): uint64.h array.h io.h io_internal.h taia.h tai.h haveepoll.h havekqueue.h havesigio.h havebsdsf.h havedevpoll.h +$(IO_OBJS): uint64.h array.h io.h io_internal.h taia.h tai.h haveepoll.h havekqueue.h havesigio.h havebsdsf.h havedevpoll.h havesendfile.h iob_addbuf.o iob_addfile.o iob_new.o iob_reset.o iob_send.o: iob_internal.h iob.h @@ -137,11 +137,12 @@ t: t.o libowfat.a 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 havescope.h havedevpoll.h Makefile dep +libepoll havesigio.h havebsdsf.h havesendfile.h havescope.h havedevpoll.h \ +Makefile dep 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 \ -openreadclose.h readclose.h ndelay.h array.h io.h safemult.h iob.h +openreadclose.h readclose.h ndelay.h array.h io.h safemult.h iob.h havealloca.h install: libowfat.a install -d $(INCLUDEDIR) $(MAN3DIR) $(LIBDIR) @@ -199,6 +200,11 @@ havebsdsf.h: trybsdsf.c if $(DIET) $(CC) $(CFLAGS) -c trybsdsf.c >/dev/null 2>&1; then echo "#define HAVE_BSDSENDFILE"; fi > $@ -rm -f trybsdsf.o +havesendfile.h: trysendfile.c + -rm -f $@ + if $(DIET) $(CC) $(CFLAGS) -c trysendfile.c >/dev/null 2>&1; then echo "#define HAVE_SENDFILE"; fi > $@ + -rm -f trysendfile.o + haveepoll.h: tryepoll.c -rm -f $@ if $(DIET) $(CC) $(CFLAGS) -o tryepoll tryepoll.c >/dev/null 2>&1; then echo "#define HAVE_EPOLL 1"; else \ diff --git a/io/io_sendfile.c b/io/io_sendfile.c index defc33a..1f6a1d8 100644 --- a/io/io_sendfile.c +++ b/io/io_sendfile.c @@ -2,6 +2,7 @@ #define _FILE_OFFSET_BITS 64 #include "io_internal.h" #include "havebsdsf.h" +#include "havesendfile.h" #if defined(HAVE_BSDSENDFILE) #include @@ -40,6 +41,19 @@ int64 io_sendfile(int64 s,int64 fd,uint64 off,uint64 n) { return i; } +#elif defined(HAVE_SENDFILE) + +#ifdef __hpux__ + +#include +#include +#include + +int64 io_sendfile(int64 out,int64 in,uint64 off,uint64 bytes) { + return sendfile64(out,in,off,bytes,0,0); +} +#endif + #else #include diff --git a/trysendfile.c b/trysendfile.c new file mode 100644 index 0000000..13c3e86 --- /dev/null +++ b/trysendfile.c @@ -0,0 +1,24 @@ +#ifdef __hpux__ +#include +#include +#include + +int main() { +/* + sbsize_t sendfile(int s, int fd, off_t offset, bsize_t nbytes, + const struct iovec *hdtrl, int flags); +*/ + struct iovec x[2]; + int fd=open("havesendfile.c",0); + x[0].iov_base="header"; + x[0].iov_len=6; + x[1].iov_base="footer"; + x[1].iov_len=6; + sendfile(1 /* dest socket */,fd /* src file */, + 0 /* offset */, 23 /* nbytes */, + x, 0); + perror("sendfile"); +} +#else +#error unsupported architecture +#endif