aboutsummaryrefslogtreecommitdiff
path: root/src/connect.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-06-17 13:18:55 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-06-17 13:18:55 +0200
commit2b68728552d125644a522e7548d02af9ffd71713 (patch)
tree5e63366af137bbe056f6fdb1cec06228e983f5d3 /src/connect.c
parent42c7bc5a21225b41292cd0e0ea8822b10366940e (diff)
downloadlibssh-2b68728552d125644a522e7548d02af9ffd71713.tar.gz
libssh-2b68728552d125644a522e7548d02af9ffd71713.tar.xz
libssh-2b68728552d125644a522e7548d02af9ffd71713.zip
socket: Check if socket (non)blocking is working.
Diffstat (limited to 'src/connect.c')
-rw-r--r--src/connect.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/connect.c b/src/connect.c
index 3517f265..d581e2c7 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -149,7 +149,13 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
*/
timeout_ms=timeout * 1000 + usec / 1000;
- ssh_socket_set_nonblocking(s);
+ rc = ssh_socket_set_nonblocking(s);
+ if (rc < 0) {
+ ssh_set_error(session, SSH_FATAL,
+ "Failed to set socket non-blocking for %s:%d", host, port);
+ ssh_connect_socket_close(s);
+ return -1;
+ }
ssh_log(session, SSH_LOG_RARE, "Trying to connect to host: %s:%d with "
"timeout %d ms", host, port, timeout_ms);
@@ -196,7 +202,14 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
/* s is connected ? */
ssh_log(session, SSH_LOG_PACKET, "Socket connected with timeout\n");
- ssh_socket_set_blocking(s);
+ ret = ssh_socket_set_blocking(s);
+ if (ret < 0) {
+ ssh_set_error(session, SSH_FATAL,
+ "Failed to set socket as blocking connecting to %s:%d failed: %s",
+ host, port, strerror(errno));
+ ssh_connect_socket_close(s);
+ return -1;
+ }
leave_function();
return s;
@@ -368,7 +381,13 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
continue;
}
}
- ssh_socket_set_nonblocking(s);
+
+ rc = ssh_socket_set_nonblocking(s);
+ if (rc < 0) {
+ ssh_set_error(session, SSH_FATAL,
+ "Failed to set socket non-blocking for %s:%d", host, port);
+ ssh_connect_socket_close(s);
+ }
connect(s, itr->ai_addr, itr->ai_addrlen);
break;