X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fnixio%2Fsrc%2Fsplice.c;h=38a45c22abc5cbbb6228ceae5e4684b4de0ef43d;hb=6ea063dc11d38fa1f2b7c57eb8193fd8034d736e;hp=c7aa817af7c7abaed92713c9084b742e513a4147;hpb=04eb9de74e06b8532fcb54986442ef8a5497c0ec;p=project%2Fluci.git diff --git a/libs/nixio/src/splice.c b/libs/nixio/src/splice.c index c7aa817af..38a45c22a 100644 --- a/libs/nixio/src/splice.c +++ b/libs/nixio/src/splice.c @@ -25,6 +25,10 @@ #include #include #include +#include + + +#ifndef __WINNT__ #ifndef BSD #include @@ -35,11 +39,13 @@ #endif #ifdef _GNU_SOURCE +#ifdef SPLICE_F_MOVE /* guess what sucks... */ #ifdef __UCLIBC__ #include #include + ssize_t splice(int __fdin, __off64_t *__offin, int __fdout, __off64_t *__offout, size_t __len, unsigned int __flags) { #ifdef __NR_splice @@ -55,6 +61,15 @@ ssize_t splice(int __fdin, __off64_t *__offin, int __fdout, return -1; #endif } + +#undef SPLICE_F_MOVE +#undef SPLICE_F_NONBLOCK +#undef SPLICE_F_MORE + +#define SPLICE_F_MOVE 1 +#define SPLICE_F_NONBLOCK 2 +#define SPLICE_F_MORE 4 + #endif /* __UCLIBC__ */ /** @@ -75,7 +90,7 @@ static int nixio_splice(lua_State *L) { return nixio__perror(L); } - lua_pushnumber(L, spliced); + lua_pushinteger(L, spliced); return 1; } @@ -103,6 +118,7 @@ static int nixio_splice_flags(lua_State *L) { return 1; } +#endif /* SPLICE_F_MOVE */ #endif /* _GNU_SOURCE */ /** @@ -127,7 +143,11 @@ static int nixio_sendfile(lua_State *L) { const off_t offset = lseek(infd, 0, SEEK_CUR); do { +#ifdef __DARWIN__ + r = sendfile(infd, sock, offset, (off_t *)&len, NULL, 0); +#else r = sendfile(infd, sock, offset, len, NULL, &spliced, 0); +#endif } while (r == -1 && errno == EINTR); if (r == -1) { @@ -135,20 +155,30 @@ static int nixio_sendfile(lua_State *L) { } #endif - lua_pushnumber(L, spliced); + lua_pushinteger(L, spliced); return 1; } /* module table */ static const luaL_reg R[] = { #ifdef _GNU_SOURCE +#ifdef SPLICE_F_MOVE {"splice", nixio_splice}, {"splice_flags", nixio_splice_flags}, #endif +#endif {"sendfile", nixio_sendfile}, {NULL, NULL} }; + void nixio_open_splice(lua_State *L) { luaL_register(L, NULL, R); } + +#else /* __WINNT__ */ + +void nixio_open_splice(lua_State *L) { +} + +#endif /* !__WINNT__ */