nixio: FreeBSD compatibility #2
This commit is contained in:
parent
35f40376c3
commit
04eb9de74e
5 changed files with 34 additions and 6 deletions
|
@ -20,6 +20,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "nixio.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* connect()/bind() shortcut
|
* connect()/bind() shortcut
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
|
||||||
static int nixio_open(lua_State *L) {
|
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) {
|
static int nixio_file_sync(lua_State *L) {
|
||||||
int fd = nixio__checkfd(L, 1);
|
int fd = nixio__checkfd(L, 1);
|
||||||
|
#ifndef BSD
|
||||||
int meta = lua_toboolean(L, 2);
|
int meta = lua_toboolean(L, 2);
|
||||||
return nixio__pstatus(L, (meta) ? !fsync(fd) : !fdatasync(fd));
|
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) {
|
static int nixio_file_lock(lua_State *L) {
|
||||||
|
|
|
@ -23,8 +23,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include "nixio.h"
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,7 +25,14 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifndef BSD
|
||||||
#include <sys/sendfile.h>
|
#include <sys/sendfile.h>
|
||||||
|
#else
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _GNU_SOURCE
|
#ifdef _GNU_SOURCE
|
||||||
|
|
||||||
|
@ -102,15 +109,31 @@ static int nixio_splice_flags(lua_State *L) {
|
||||||
* sendfile(outfd, infd, length)
|
* sendfile(outfd, infd, length)
|
||||||
*/
|
*/
|
||||||
static int nixio_sendfile(lua_State *L) {
|
static int nixio_sendfile(lua_State *L) {
|
||||||
int sockfd = nixio__checksockfd(L);
|
int sock = nixio__checksockfd(L);
|
||||||
int infd = nixio__checkfd(L, 2);
|
int infd = nixio__checkfd(L, 2);
|
||||||
size_t len = luaL_checkinteger(L, 3);
|
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);
|
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);
|
lua_pushnumber(L, spliced);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue