#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
+#include <netinet/in.h>
#include <sys/un.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
-#include "nixio.h"
+#include <errno.h>
/**
* connect()/bind() shortcut
/* create socket object */
nixio_sock *sock = lua_newuserdata(L, sizeof(nixio_sock));
- int status = -1;
+ int status = -1, clstat;
for (rp = result; rp != NULL; rp = rp->ai_next) {
sock->fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (do_bind) {
status = bind(sock->fd, rp->ai_addr, rp->ai_addrlen);
} else {
- status = connect(sock->fd, rp->ai_addr, rp->ai_addrlen);
+ do {
+ status = connect(sock->fd, rp->ai_addr, rp->ai_addrlen);
+ } while (status == -1 && errno == EINTR);
}
/* on success */
break;
}
- close(sock->fd);
+ do {
+ clstat = close(sock->fd);
+ } while (clstat == -1 && errno == EINTR);
}
freeaddrinfo(result);
if (do_bind) {
status = bind(sock->fd, rp->ai_addr, rp->ai_addrlen);
} else {
- status = connect(sock->fd, rp->ai_addr, rp->ai_addrlen);
+ do {
+ status = connect(sock->fd, rp->ai_addr, rp->ai_addrlen);
+ } while (status == -1 && errno == EINTR);
}
/* on success */
if (do_bind) {
status = bind(sock->fd, (struct sockaddr*)&addr, sizeof(addr));
} else {
- status = connect(sock->fd, (struct sockaddr*)&addr, sizeof(addr));
+ do {
+ status = connect(sock->fd, (struct sockaddr*)&addr,
+ sizeof(addr));
+ } while (status == -1 && errno == EINTR);
}
} else {
return luaL_error(L, "not supported");
char ipaddr[INET6_ADDRSTRLEN];
void *binaddr;
uint16_t port;
+ int newfd;
- int newfd = accept(sock->fd, (struct sockaddr *)&addr, &addrlen);
+ do {
+ newfd = accept(sock->fd, (struct sockaddr *)&addr, &addrlen);
+ } while (newfd == -1 && errno == EINTR);
if (newfd < 0) {
return nixio__perror(L);
}