From 04eb9de74e06b8532fcb54986442ef8a5497c0ec Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Thu, 12 Mar 2009 14:53:52 +0000 Subject: [PATCH] nixio: FreeBSD compatibility #2 --- libs/nixio/src/address.c | 1 + libs/nixio/src/bind.c | 2 +- libs/nixio/src/file.c | 5 +++++ libs/nixio/src/io.c | 3 +-- libs/nixio/src/splice.c | 29 ++++++++++++++++++++++++++--- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/libs/nixio/src/address.c b/libs/nixio/src/address.c index 3d779fbe7..8b9ae2807 100644 --- a/libs/nixio/src/address.c +++ b/libs/nixio/src/address.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/libs/nixio/src/bind.c b/libs/nixio/src/bind.c index b636c0a44..785a28d5a 100644 --- a/libs/nixio/src/bind.c +++ b/libs/nixio/src/bind.c @@ -20,12 +20,12 @@ #include #include #include +#include #include #include #include #include #include -#include "nixio.h" /** * connect()/bind() shortcut diff --git a/libs/nixio/src/file.c b/libs/nixio/src/file.c index 5229b4988..2fe00c2a8 100644 --- a/libs/nixio/src/file.c +++ b/libs/nixio/src/file.c @@ -25,6 +25,7 @@ #include #include #include +#include static int nixio_open(lua_State *L) { @@ -209,8 +210,12 @@ static int nixio_file_tell(lua_State *L) { static int nixio_file_sync(lua_State *L) { int fd = nixio__checkfd(L, 1); +#ifndef BSD int meta = lua_toboolean(L, 2); return nixio__pstatus(L, (meta) ? !fsync(fd) : !fdatasync(fd)); +#else + return nixio__pstatus(L, !fsync(fd)); +#endif } static int nixio_file_lock(lua_State *L) { diff --git a/libs/nixio/src/io.c b/libs/nixio/src/io.c index 3727f8c02..0ce4fcc3a 100644 --- a/libs/nixio/src/io.c +++ b/libs/nixio/src/io.c @@ -23,8 +23,7 @@ #include #include #include -#include "nixio.h" - +#include /** diff --git a/libs/nixio/src/splice.c b/libs/nixio/src/splice.c index 0519f719a..c7aa817af 100644 --- a/libs/nixio/src/splice.c +++ b/libs/nixio/src/splice.c @@ -25,7 +25,14 @@ #include #include #include + +#ifndef BSD #include +#else +#include +#include +#include +#endif #ifdef _GNU_SOURCE @@ -102,15 +109,31 @@ static int nixio_splice_flags(lua_State *L) { * sendfile(outfd, infd, length) */ static int nixio_sendfile(lua_State *L) { - int sockfd = nixio__checksockfd(L); + int sock = nixio__checksockfd(L); int infd = nixio__checkfd(L, 2); size_t len = luaL_checkinteger(L, 3); + off_t spliced; - long spliced = sendfile(sockfd, infd, NULL, len); +#ifndef BSD + do { + spliced = sendfile(sock, infd, NULL, len); + } while (spliced == -1 && errno == EINTR); - if (spliced < 0) { + if (spliced == -1) { return nixio__perror(L); } +#else + int r; + const off_t offset = lseek(infd, 0, SEEK_CUR); + + do { + r = sendfile(infd, sock, offset, len, NULL, &spliced, 0); + } while (r == -1 && errno == EINTR); + + if (r == -1) { + return nixio__perror(L); + } +#endif lua_pushnumber(L, spliced); return 1; -- 2.25.1