moonbridge

changeset 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
files moonbridge.c moonbridge_io.c
line diff
     1.1 --- a/moonbridge.c	Mon Jun 22 22:26:55 2015 +0200
     1.2 +++ b/moonbridge.c	Mon Jun 22 22:36:18 2015 +0200
     1.3 @@ -1435,8 +1435,7 @@
     1.4    } else {
     1.5      int peerfd;
     1.6      do {
     1.7 -      /* peerfd = accept4(listener->listenfd, NULL, NULL, SOCK_CLOEXEC); */
     1.8 -      /* use accept() instead of accept4() to avoid _GNU_SOURCE on GNU/Linux */
     1.9 +#if defined(__linux__) && !defined(_GNU_SOURCE)
    1.10        peerfd = accept(listener->listenfd, NULL, NULL);
    1.11        if (peerfd != -1) {
    1.12          if (fcntl(peerfd, F_SETFD, FD_CLOEXEC) == -1) {
    1.13 @@ -1444,6 +1443,9 @@
    1.14            moonbr_terminate_error();
    1.15          }
    1.16        }
    1.17 +#else
    1.18 +      peerfd = accept4(listener->listenfd, NULL, NULL, SOCK_CLOEXEC);
    1.19 +#endif
    1.20        if (peerfd == -1) {
    1.21          if (errno == EWOULDBLOCK) {
    1.22            break;
     2.1 --- a/moonbridge_io.c	Mon Jun 22 22:26:55 2015 +0200
     2.2 +++ b/moonbridge_io.c	Mon Jun 22 22:36:18 2015 +0200
     2.3 @@ -1183,7 +1183,20 @@
     2.4      listener->nonblocking = nonblocking;
     2.5    }
     2.6    while (1) {
     2.7 +#if defined(__linux__) && !defined(_GNU_SOURCE)
     2.8 +    fd = accept(listener->listenfd, NULL, NULL);
     2.9 +    if (fd != -1) {
    2.10 +      if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
    2.11 +        moonbr_io_errmsg();
    2.12 +        close(listener->fd);
    2.13 +        listener->fd = -1;
    2.14 +        close(fd);
    2.15 +        luaL_error(L, "Unexpected error in fcntl call: %s", errmsg);
    2.16 +      }
    2.17 +    }
    2.18 +#else
    2.19      fd = accept4(listener->fd, NULL, NULL, SOCK_CLOEXEC);
    2.20 +#endif
    2.21      if (fd < 0) {
    2.22        if (nonblocking && (errno == EAGAIN || errno == EWOULDBLOCK)) {
    2.23          lua_pushboolean(L, 0);

Impressum / About Us