From 3d163f7044d986cb90e79870b03f41d55968c72a Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Mon, 23 Nov 2015 01:14:17 -0800 Subject: [PATCH] Patch for Node.js -- accept() bug --- netcon/Intercept.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/netcon/Intercept.c b/netcon/Intercept.c index 9c84ed147..bf25feb7b 100755 --- a/netcon/Intercept.c +++ b/netcon/Intercept.c @@ -25,7 +25,6 @@ * LLC. Start here: http://www.zerotier.com/ */ - #ifdef USE_GNU_SOURCE #define _GNU_SOURCE #endif @@ -834,10 +833,10 @@ int accept(ACCEPT_SIG) handle_error("accept", "Unresolved symbol [accept]", -1); return -1; } - /* - if(opt & O_NONBLOCK) - fcntl(sockfd, F_SETFL, O_NONBLOCK); - */ + + // if(opt & O_NONBLOCK) + fcntl(sockfd, F_SETFL, O_NONBLOCK); /* required by libuv in nodejs */ + char c[1]; int new_conn_socket; @@ -874,9 +873,17 @@ int accept(ACCEPT_SIG) return -1; } } + + errno = EAGAIN; /* necessary? */ + handle_error("accept", "EAGAIN - Error reading signal byte from service", -1); + return -EAGAIN; + +/* Prevents libuv in nodejs from accepting properly (it looks for a -EAGAIN) */ +/* errno = EBADF; handle_error("accept", "EBADF - Error reading signal byte from service", -1); - return -1; + return -1; +*/ } @@ -1080,12 +1087,10 @@ long syscall(SYSCALL_SIG){ int flags = d; int old_errno = errno; int err = accept4(sockfd, addr, addrlen, flags); + errno = old_errno; - - if(err == -EBADF) { - err = -EAGAIN; /* For hysterical raisins */ - } - + if(err == -EBADF) + err = -EAGAIN; return err; } #endif