Commit 7d94af49 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

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
parent a490961b
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -330,6 +330,7 @@ static void state(struct connectdata *conn, sshstate nowstate)
  /* for debug purposes */
  static const char * const names[] = {
    "SSH_STOP",
    "SSH_INIT",
    "SSH_S_STARTUP",
    "SSH_HOSTKEY",
    "SSH_AUTHLIST",
@@ -653,11 +654,19 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
  do {

    switch(sshc->state) {
    case SSH_S_STARTUP:
    case SSH_INIT:
      sshc->secondCreateDirs = 0;
      sshc->nextstate = SSH_NO_STATE;
      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);
      if(rc == LIBSSH2_ERROR_EAGAIN) {
        break;
@@ -669,10 +678,6 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
        break;
      }

      /* Set libssh2 to non-blocking, since everything internally is
         non-blocking */
      libssh2_session_set_blocking(sshc->ssh_session, 0);

      state(conn, SSH_HOSTKEY);

      /* fall-through */
@@ -2654,7 +2659,7 @@ static CURLcode ssh_connect(struct connectdata *conn, bool *done)
  infof(data, "SSH socket: %d\n", (int)sock);
#endif /* CURL_LIBSSH2_DEBUG */

  state(conn, SSH_S_STARTUP);
  state(conn, SSH_INIT);

  if(data->state.used_interface == Curl_if_multi)
    result = ssh_multi_statemach(conn, done);
+3 −2
Original line number Diff line number Diff line
@@ -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
 * 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_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_AUTHLIST,
  SSH_AUTH_PKEY_INIT,