From aa0cee169fd72fd3c76495e89561598ab723de3c Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sat, 14 Feb 2009 10:42:48 +0000 Subject: [PATCH 1/1] nixio: added sendfile(), return false instead of nil for EWOULDBLOCK --- libs/nixio/src/nixio.c | 6 +++++- 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 327f65098..5f098be31 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 37849751a..2b2837060 100644 --- a/libs/nixio/src/splice.c +++ b/libs/nixio/src/splice.c @@ -20,6 +20,7 @@ #include "nixio.h" #include +#include /* 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} }; -- 2.11.0