Browse Source

Fix #648

pull/652/head
Max Lv 9 years ago
parent
commit
0cfae045e8
7 changed files with 21 additions and 6 deletions
  1. 3
      config.h.in
  2. 9
      configure
  3. 3
      configure.ac
  4. 4
      src/local.c
  5. 2
      src/redir.c
  6. 4
      src/server.c
  7. 2
      src/tunnel.c

3
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

9
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

3
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

4
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);

2
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);

4
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;

2
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);

Loading…
Cancel
Save