summaryrefslogtreecommitdiffhomepage
path: root/libs/nixio
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2009-02-28 21:21:52 +0000
committerSteven Barth <steven@midlink.org>2009-02-28 21:21:52 +0000
commit33fe5b57d76b287bad42de085e63fe2130ba2be3 (patch)
tree7246c66763386b8c92b12c8c0bfb6d71d003a68a /libs/nixio
parent0a224c5ca8ecb5d342e01acd1b3591cbb81c7512 (diff)
More splicing stuff
Diffstat (limited to 'libs/nixio')
-rw-r--r--libs/nixio/src/nixio.c6
-rw-r--r--libs/nixio/src/splice.c16
2 files changed, 19 insertions, 3 deletions
diff --git a/libs/nixio/src/nixio.c b/libs/nixio/src/nixio.c
index 383fc0af9..ae1af7a16 100644
--- a/libs/nixio/src/nixio.c
+++ b/libs/nixio/src/nixio.c
@@ -88,8 +88,14 @@ int nixio__tofd(lua_State *L, int ud) {
return fd;
}
+static int nixio_strerror(lua_State *L) {
+ lua_pushstring(L, strerror(luaL_checkinteger(L, 1)));
+ return 1;
+}
+
/* object table */
static const luaL_reg R[] = {
+ {"strerror", nixio_strerror},
{NULL, NULL}
};
diff --git a/libs/nixio/src/splice.c b/libs/nixio/src/splice.c
index 556b4d7da..cbfc67499 100644
--- a/libs/nixio/src/splice.c
+++ b/libs/nixio/src/splice.c
@@ -21,12 +21,13 @@
#include "nixio.h"
#include <fcntl.h>
#include <string.h>
+#include <errno.h>
+#include <unistd.h>
#include <sys/sendfile.h>
/* guess what sucks... */
#ifdef __UCLIBC__
#include <unistd.h>
-#include <errno.h>
#include <sys/syscall.h>
ssize_t splice(int __fdin, __off64_t *__offin, int __fdout,
__off64_t *__offout, size_t __len, unsigned int __flags) {
@@ -77,9 +78,11 @@ static int nixio_splice(lua_State *L) {
int fd_out = nixio__checkfd(L, 2);
size_t len = luaL_checkinteger(L, 3);
int flags = luaL_optinteger(L, 4, 0);
+ long spliced;
-
- long spliced = splice(fd_in, NULL, fd_out, NULL, len, flags);
+ do {
+ spliced = splice(fd_in, NULL, fd_out, NULL, len, flags);
+ } while (spliced == -1 && errno == EINTR);
if (spliced < 0) {
return nixio__perror(L);
@@ -89,6 +92,12 @@ static int nixio_splice(lua_State *L) {
return 1;
}
+static int nixio_splice_avail(lua_State *L) {
+ splice(-1, 0, -1, 0, 0, 0);
+ lua_pushboolean(L, errno != ENOSYS);
+ return 1;
+}
+
/**
* sendfile(outfd, infd, length)
*/
@@ -111,6 +120,7 @@ static int nixio_sendfile(lua_State *L) {
static const luaL_reg R[] = {
{"splice", nixio_splice},
{"splice_flags", nixio_splice_flags},
+ {"splice_avail", nixio_splice_avail},
{"sendfile", nixio_sendfile},
{NULL, NULL}
};