diff options
author | Steven Barth <steven@midlink.org> | 2009-02-14 10:42:48 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2009-02-14 10:42:48 +0000 |
commit | aa0cee169fd72fd3c76495e89561598ab723de3c (patch) | |
tree | db8f90eff56639fe514541ad03fc8ba01233f017 /libs/nixio/src | |
parent | 5ff898e6248b668430f5f2e7d70de243f191eb04 (diff) |
nixio: added sendfile(), return false instead of nil for EWOULDBLOCK
Diffstat (limited to 'libs/nixio/src')
-rw-r--r-- | libs/nixio/src/nixio.c | 6 | ||||
-rw-r--r-- | libs/nixio/src/splice.c | 24 |
2 files changed, 27 insertions, 3 deletions
diff --git a/libs/nixio/src/nixio.c b/libs/nixio/src/nixio.c index 327f65098e..5f098be31b 100644 --- a/libs/nixio/src/nixio.c +++ b/libs/nixio/src/nixio.c @@ -26,7 +26,11 @@ /* pushes nil, error number and errstring on the stack */ int nixio__perror(lua_State *L) { - lua_pushnil(L); + if (errno == EAGAIN) { + lua_pushboolean(L, 0); + } else { + lua_pushnil(L); + } lua_pushinteger(L, errno); lua_pushstring(L, strerror(errno)); return 3; diff --git a/libs/nixio/src/splice.c b/libs/nixio/src/splice.c index 37849751a9..2b28370609 100644 --- a/libs/nixio/src/splice.c +++ b/libs/nixio/src/splice.c @@ -20,6 +20,7 @@ #include "nixio.h" #include <fcntl.h> +#include <sys/sendfile.h> /* guess what sucks... */ #ifdef __UCLIBC__ @@ -29,8 +30,7 @@ ssize_t splice(int __fdin, __off64_t *__offin, int __fdout, __off64_t *__offout, size_t __len, unsigned int __flags) { return syscall(__NR_splice, __fdin, __offin, __fdout, __offout, __len, __flags); } -#endif - +#endif /* __UCLIBC__ */ /** * Checks whether a flag is set in the table and translates it into a bitmap @@ -60,6 +60,9 @@ static int nixio_splice_flags(lua_State *L) { return 1; } +/** + * splice(fd_in, fd_out, length, flags) + */ static int nixio_splice(lua_State *L) { int fd_in = nixio__checkfd(L, 1); int fd_out = nixio__checkfd(L, 2); @@ -77,12 +80,29 @@ static int nixio_splice(lua_State *L) { return 1; } +/** + * sendfile(outfd, infd, length) + */ +static int nixio_sendfile(lua_State *L) { + int sockfd = nixio__checksockfd(L); + int infd = nixio__checkfd(L, 2); + size_t len = luaL_checkinteger(L, 3); + + long spliced = sendfile(sockfd, infd, NULL, len); + if (spliced < 0) { + return nixio__perror(L); + } + + lua_pushnumber(L, spliced); + return 1; +} /* module table */ static const luaL_reg R[] = { {"splice", nixio_splice}, {"splice_flags", nixio_splice_flags}, + {"sendfile", nixio_sendfile}, {NULL, NULL} }; |