aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Stöneberg <oliverst@online.de>2011-05-16 06:49:38 -0700
committerAndreas Schneider <asn@cryptomilk.org>2011-05-17 20:57:38 +0200
commit629cfbccc44da2a3eda66ec665d2f98ad93be0b6 (patch)
tree3b5582c9205429645f04f36edbdb9a5f827864c5
parentc5990791db48521f9e9271b65110eb6ebb2820eb (diff)
downloadlibssh-629cfbccc44da2a3eda66ec665d2f98ad93be0b6.tar.gz
libssh-629cfbccc44da2a3eda66ec665d2f98ad93be0b6.tar.xz
libssh-629cfbccc44da2a3eda66ec665d2f98ad93be0b6.zip
connect: Set timeout on connect
This also fixes error handling in ssh_poll_ctx_dopoll() and ssh_handle_packets(), so it won't loop forever on an actual timeout. (cherry picked from commit 671a9827394714cfc90d75c8a8fb2ccd86f80abf)
-rw-r--r--src/client.c10
-rw-r--r--src/poll.c4
-rw-r--r--src/session.c3
3 files changed, 9 insertions, 8 deletions
diff --git a/src/client.c b/src/client.c
index 66d4a9ae..fccbb701 100644
--- a/src/client.c
+++ b/src/client.c
@@ -673,8 +673,6 @@ int ssh_connect(ssh_session session) {
} else {
ret=ssh_socket_connect(session->socket, session->host, session->port,
session->bindaddr);
-
- /*, session->timeout * 1000 + session->timeout_usec); */
}
if (ret == SSH_ERROR) {
leave_function();
@@ -687,8 +685,12 @@ int ssh_connect(ssh_session session) {
ssh_log(session,SSH_LOG_PROTOCOL,"Socket connecting, now waiting for the callbacks to work");
pending:
session->pending_call_state=SSH_PENDING_CALL_CONNECT;
- if(ssh_is_blocking(session))
- ssh_handle_packets_termination(session,-1,ssh_connect_termination,session);
+ if(ssh_is_blocking(session)) {
+ int timeout = session->timeout * 1000 + session->timeout_usec;
+ if (timeout <= 0)
+ timeout = -1;
+ ssh_handle_packets_termination(session,timeout,ssh_connect_termination,session);
+ }
else
ssh_handle_packets_termination(session,0,ssh_connect_termination, session);
ssh_log(session,SSH_LOG_PACKET,"ssh_connect: Actual state : %d",session->session_state);
diff --git a/src/poll.c b/src/poll.c
index 07b0d531..e5a11d95 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -598,10 +598,8 @@ int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) {
return 0;
rc = ssh_poll(ctx->pollfds, ctx->polls_used, timeout);
- if(rc < 0)
- rc=SSH_ERROR;
if(rc <= 0)
- return rc;
+ return SSH_ERROR;
used = ctx->polls_used;
for (i = 0; i < used && rc > 0; ) {
if (!ctx->pollfds[i].revents) {
diff --git a/src/session.c b/src/session.c
index 18688c60..35fb0b28 100644
--- a/src/session.c
+++ b/src/session.c
@@ -429,7 +429,8 @@ int ssh_handle_packets(ssh_session session, int timeout) {
if(spoll_in != spoll_out)
ssh_poll_ctx_add(ctx,spoll_out);
}
- ssh_poll_ctx_dopoll(ctx,timeout);
+ if( ssh_poll_ctx_dopoll(ctx,timeout) )
+ session->session_state = SSH_SESSION_STATE_ERROR;
leave_function();
if (session->session_state != SSH_SESSION_STATE_ERROR)
return SSH_OK;