moonbridge

diff moonbridge_io.c @ 214:45a425c75643

Use accept() only on Linux and only if _GNU_SOURCE is not set
author jbe
date Mon Jun 22 22:36:18 2015 +0200 (2015-06-22)
parents 43a077f2ab49
children b124f8f3ca79
line diff
     1.1 --- a/moonbridge_io.c	Mon Jun 22 22:26:55 2015 +0200
     1.2 +++ b/moonbridge_io.c	Mon Jun 22 22:36:18 2015 +0200
     1.3 @@ -1183,7 +1183,20 @@
     1.4      listener->nonblocking = nonblocking;
     1.5    }
     1.6    while (1) {
     1.7 +#if defined(__linux__) && !defined(_GNU_SOURCE)
     1.8 +    fd = accept(listener->listenfd, NULL, NULL);
     1.9 +    if (fd != -1) {
    1.10 +      if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
    1.11 +        moonbr_io_errmsg();
    1.12 +        close(listener->fd);
    1.13 +        listener->fd = -1;
    1.14 +        close(fd);
    1.15 +        luaL_error(L, "Unexpected error in fcntl call: %s", errmsg);
    1.16 +      }
    1.17 +    }
    1.18 +#else
    1.19      fd = accept4(listener->fd, NULL, NULL, SOCK_CLOEXEC);
    1.20 +#endif
    1.21      if (fd < 0) {
    1.22        if (nonblocking && (errno == EAGAIN || errno == EWOULDBLOCK)) {
    1.23          lua_pushboolean(L, 0);

Impressum / About Us