From 9abcc7b909b6ff0f173405e73dc7c0c3d093e44a Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sat, 14 Feb 2015 09:56:11 +0800 Subject: [PATCH] connect_remote() is now always non-blocking --- cli-main.c | 3 +-- cli-tcpfwd.c | 2 +- dbutil.c | 13 +++++-------- dbutil.h | 3 +-- svr-tcpfwd.c | 2 +- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/cli-main.c b/cli-main.c index 20f19a4..a956721 100644 --- a/cli-main.c +++ b/cli-main.c @@ -72,8 +72,7 @@ int main(int argc, char ** argv) { } else #endif { - int sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, - 1, &error); + int sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, &error); sock_in = sock_out = sock; } diff --git a/cli-tcpfwd.c b/cli-tcpfwd.c index fa61d13..3894044 100644 --- a/cli-tcpfwd.c +++ b/cli-tcpfwd.c @@ -254,7 +254,7 @@ static int newtcpforwarded(struct Channel * channel) { } snprintf(portstring, sizeof(portstring), "%d", fwd->connectport); - sock = connect_remote(fwd->connectaddr, portstring, 1, NULL); + sock = connect_remote(fwd->connectaddr, portstring, NULL); if (sock < 0) { TRACE(("leave newtcpdirect: sock failed")) err = SSH_OPEN_CONNECT_FAILED; diff --git a/dbutil.c b/dbutil.c index 923327b..ec108bf 100644 --- a/dbutil.c +++ b/dbutil.c @@ -435,8 +435,7 @@ static void set_piggyback_ack(int sock) { * wasn't null, it will be a newly malloced error message */ /* TODO: maxfd */ -int connect_remote(const char* remotehost, const char* remoteport, - int nonblocking, char ** errstring) { +int connect_remote(const char* remotehost, const char* remoteport, char ** errstring) { struct addrinfo *res0 = NULL, *res = NULL, hints; int sock; @@ -475,16 +474,14 @@ int connect_remote(const char* remotehost, const char* remoteport, continue; } - if (nonblocking) { - setnonblocking(sock); + setnonblocking(sock); #if defined(__linux__) && defined(TCP_DEFER_ACCEPT) - set_piggyback_ack(sock); + set_piggyback_ack(sock); #endif - } if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) { - if (errno == EINPROGRESS && nonblocking) { + if (errno == EINPROGRESS) { TRACE(("Connect in progress")) break; } else { @@ -498,7 +495,7 @@ int connect_remote(const char* remotehost, const char* remoteport, break; /* Success */ } - if (sock < 0 && !(errno == EINPROGRESS && nonblocking)) { + if (sock < 0 && !(errno == EINPROGRESS)) { /* Failed */ if (errstring != NULL && *errstring == NULL) { int len; diff --git a/dbutil.h b/dbutil.h index a13c15f..9feec2d 100644 --- a/dbutil.h +++ b/dbutil.h @@ -83,8 +83,7 @@ void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell); #ifdef ENABLE_CONNECT_UNIX int connect_unix(const char* addr); #endif -int connect_remote(const char* remotehost, const char* remoteport, - int nonblocking, char ** errstring); +int connect_remote(const char* remotehost, const char* remoteport, char ** errstring); int buf_readfile(buffer* buf, const char* filename); int buf_getline(buffer * line, FILE * authfile); diff --git a/svr-tcpfwd.c b/svr-tcpfwd.c index e5f219e..f2c4b93 100644 --- a/svr-tcpfwd.c +++ b/svr-tcpfwd.c @@ -270,7 +270,7 @@ static int newtcpdirect(struct Channel * channel) { } snprintf(portstring, sizeof(portstring), "%d", destport); - sock = connect_remote(desthost, portstring, 1, NULL); + sock = connect_remote(desthost, portstring, NULL); if (sock < 0) { err = SSH_OPEN_CONNECT_FAILED; TRACE(("leave newtcpdirect: sock failed"))