From 0cfae045e816804d5d35ef06cb21c0f8313a8a61 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 26 May 2016 14:35:02 +0800 Subject: [PATCH] Fix #648 --- config.h.in | 3 +++ configure | 9 +++++++++ configure.ac | 3 +++ src/local.c | 4 ++-- src/redir.c | 2 +- src/server.c | 4 ++-- src/tunnel.c | 2 +- 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/config.h.in b/config.h.in index d17335cb..cad04cc9 100644 --- a/config.h.in +++ b/config.h.in @@ -3,6 +3,9 @@ /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD +/* errno for incomplete non-blocking connect(2) */ +#undef CONNECT_IN_PROGRESS + /* Override libev default fd conversion macro. */ #undef EV_FD_TO_WIN32_HANDLE diff --git a/configure b/configure index d4e2daa1..fcce9929 100755 --- a/configure +++ b/configure @@ -14438,6 +14438,9 @@ done case $host in *-mingw*) + +$as_echo "#define CONNECT_IN_PROGRESS WSAEWOULDBLOCK" >>confdefs.h + for ac_header in windows.h winsock2.h ws2tcpip.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` @@ -14455,6 +14458,9 @@ done ;; *-linux*) + +$as_echo "#define CONNECT_IN_PROGRESS EINPROGRESS" >>confdefs.h + for ac_header in linux/if.h linux/netfilter_ipv4.h linux/netfilter_ipv6/ip6_tables.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` @@ -14488,6 +14494,9 @@ done ;; *) # These are POSIX-like systems using BSD-like sockets API. + +$as_echo "#define CONNECT_IN_PROGRESS EINPROGRESS" >>confdefs.h + ;; esac diff --git a/configure.ac b/configure.ac index 86a43c10..a9d4573e 100755 --- a/configure.ac +++ b/configure.ac @@ -192,9 +192,11 @@ AC_CHECK_HEADERS([net/if.h], [], [], case $host in *-mingw*) + AC_DEFINE([CONNECT_IN_PROGRESS], [WSAEWOULDBLOCK], [errno for incomplete non-blocking connect(2)]) AC_CHECK_HEADERS([windows.h winsock2.h ws2tcpip.h], [], [AC_MSG_ERROR([Missing MinGW headers])], []) ;; *-linux*) + AC_DEFINE([CONNECT_IN_PROGRESS], [EINPROGRESS], [errno for incomplete non-blocking connect(2)]) dnl Checks for netfilter headers AC_CHECK_HEADERS([linux/if.h linux/netfilter_ipv4.h linux/netfilter_ipv6/ip6_tables.h], [], [AC_MSG_ERROR([Missing netfilter headers])], @@ -216,6 +218,7 @@ case $host in ;; *) # These are POSIX-like systems using BSD-like sockets API. + AC_DEFINE([CONNECT_IN_PROGRESS], [EINPROGRESS], [errno for incomplete non-blocking connect(2)]) ;; esac diff --git a/src/local.c b/src/local.c index bfeb56fa..66dfe05c 100644 --- a/src/local.c +++ b/src/local.c @@ -278,7 +278,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) // connecting, wait until connected int r = connect(remote->fd, (struct sockaddr *)&(remote->addr), remote->addr_len); - if (r < 0 && errno != EINPROGRESS) { + if (r < 0 && errno != CONNECT_IN_PROGRESS) { ERROR("connect"); close_and_free_remote(EV_A_ remote); close_and_free_server(EV_A_ server); @@ -315,7 +315,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) (struct sockaddr *)&(remote->addr), remote->addr_len); #endif if (s == -1) { - if (errno == EINPROGRESS) { + if (errno == CONNECT_IN_PROGRESS) { // in progress, wait until connected remote->buf->idx = 0; ev_io_stop(EV_A_ & server_recv_ctx->io); diff --git a/src/redir.c b/src/redir.c index 552603d7..6b8633ca 100644 --- a/src/redir.c +++ b/src/redir.c @@ -650,7 +650,7 @@ static void accept_cb(EV_P_ ev_io *w, int revents) int r = connect(remotefd, remote_addr, get_sockaddr_len(remote_addr)); - if (r < 0 && errno != EINPROGRESS) { + if (r < 0 && errno != CONNECT_IN_PROGRESS) { ERROR("connect"); close_and_free_remote(EV_A_ remote); close_and_free_server(EV_A_ server); diff --git a/src/server.c b/src/server.c index 94f7420c..2cb2ae2b 100644 --- a/src/server.c +++ b/src/server.c @@ -457,7 +457,7 @@ static remote_t *connect_to_remote(struct addrinfo *res, res->ai_addrlen); #endif if (s == -1) { - if (errno == EINPROGRESS || errno == EAGAIN + if (errno == CONNECT_IN_PROGRESS || errno == EAGAIN || errno == EWOULDBLOCK) { // The remote server doesn't support tfo or it's the first connection to the server. // It will automatically fall back to conventional TCP. @@ -482,7 +482,7 @@ static remote_t *connect_to_remote(struct addrinfo *res, if (!fast_open) { int r = connect(sockfd, res->ai_addr, res->ai_addrlen); - if (r < 0 && errno != EINPROGRESS) { + if (r < 0 && errno != CONNECT_IN_PROGRESS) { ERROR("connect"); close(sockfd); return NULL; diff --git a/src/tunnel.c b/src/tunnel.c index a6df7e05..352f8f27 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -660,7 +660,7 @@ static void accept_cb(EV_P_ ev_io *w, int revents) int r = connect(remotefd, remote_addr, get_sockaddr_len(remote_addr)); - if (r < 0 && errno != EINPROGRESS) { + if (r < 0 && errno != CONNECT_IN_PROGRESS) { ERROR("connect"); close_and_free_remote(EV_A_ remote); close_and_free_server(EV_A_ server);