1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

SSH: set non-blocking earlier

Introduce an INIT state for the SSH state machine and set libssh2
non-blocking in that so that it is set properly before
libssh2_session_startup() is called.

Bug: http://curl.haxx.se/mail/archive-2011-05/0001.html
This commit is contained in:
Daniel Stenberg 2011-05-01 23:01:31 +02:00
parent a490961b10
commit 7d94af497d
2 changed files with 14 additions and 8 deletions

View File

@ -330,6 +330,7 @@ static void state(struct connectdata *conn, sshstate nowstate)
/* for debug purposes */ /* for debug purposes */
static const char * const names[] = { static const char * const names[] = {
"SSH_STOP", "SSH_STOP",
"SSH_INIT",
"SSH_S_STARTUP", "SSH_S_STARTUP",
"SSH_HOSTKEY", "SSH_HOSTKEY",
"SSH_AUTHLIST", "SSH_AUTHLIST",
@ -653,11 +654,19 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
do { do {
switch(sshc->state) { switch(sshc->state) {
case SSH_S_STARTUP: case SSH_INIT:
sshc->secondCreateDirs = 0; sshc->secondCreateDirs = 0;
sshc->nextstate = SSH_NO_STATE; sshc->nextstate = SSH_NO_STATE;
sshc->actualcode = CURLE_OK; sshc->actualcode = CURLE_OK;
/* Set libssh2 to non-blocking, since everything internally is
non-blocking */
libssh2_session_set_blocking(sshc->ssh_session, 0);
state(conn, SSH_S_STARTUP);
/* fall-through */
case SSH_S_STARTUP:
rc = libssh2_session_startup(sshc->ssh_session, sock); rc = libssh2_session_startup(sshc->ssh_session, sock);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
@ -669,10 +678,6 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break; break;
} }
/* Set libssh2 to non-blocking, since everything internally is
non-blocking */
libssh2_session_set_blocking(sshc->ssh_session, 0);
state(conn, SSH_HOSTKEY); state(conn, SSH_HOSTKEY);
/* fall-through */ /* fall-through */
@ -2654,7 +2659,7 @@ static CURLcode ssh_connect(struct connectdata *conn, bool *done)
infof(data, "SSH socket: %d\n", (int)sock); infof(data, "SSH socket: %d\n", (int)sock);
#endif /* CURL_LIBSSH2_DEBUG */ #endif /* CURL_LIBSSH2_DEBUG */
state(conn, SSH_S_STARTUP); state(conn, SSH_INIT);
if(data->state.used_interface == Curl_if_multi) if(data->state.used_interface == Curl_if_multi)
result = ssh_multi_statemach(conn, done); result = ssh_multi_statemach(conn, done);

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -36,7 +36,8 @@ typedef enum {
SSH_NO_STATE = -1, /* Used for "nextState" so say there is none */ SSH_NO_STATE = -1, /* Used for "nextState" so say there is none */
SSH_STOP = 0, /* do nothing state, stops the state machine */ SSH_STOP = 0, /* do nothing state, stops the state machine */
SSH_S_STARTUP, /* Session startup, First state in SSH-CONNECT */ SSH_INIT, /* First state in SSH-CONNECT */
SSH_S_STARTUP, /* Session startup */
SSH_HOSTKEY, /* verify hostkey */ SSH_HOSTKEY, /* verify hostkey */
SSH_AUTHLIST, SSH_AUTHLIST,
SSH_AUTH_PKEY_INIT, SSH_AUTH_PKEY_INIT,