cURL / Mailing Lists / curl-library / Single Mail


Proper way to convert ssh.c to non-blocking

From: James Housley <>
Date: Sun, 10 Jun 2007 10:25:55 -0400

I know from pervious discussions that once libssh2 works in non-
blocking mode that ssh.c will need to be converted to run in a state
machine to "play nice" with the rest of libcurl. I also remember
being told that ftp.c is not the ideal way it should be done, but I
don't remember what was the best example of how it should be done.

If I am right for the actual transfers Curl_setup_transfer() would be
called and then the state machine would run from withing the read and
write call backs. Would the same be done for connect? Below is a
highly edited version of the connect only showing the routines that
can block. Do I just do an initial transfer setup with unknown size
for connect? Then do the real one to transfer the file? If yes,
what would that do to the users progress bars?

CURLcode Curl_ssh_connect(struct connectdata *conn, bool *done)
   libssh2_session_set_blocking(ssh->ssh_session, 0);

   while ((i = libssh2_session_startup(ssh->ssh_session, sock)) ==

   do {
     authlist = libssh2_userauth_list(ssh->ssh_session, ssh->user,
   } while (!authlist);

   while ((i = libssh2_userauth_publickey_fromfile(ssh->ssh_session,
ssh->user, rsa_pub, rsa, passphrase)) == LIBSSH2_ERROR_EAGAIN);

   if (conn->protocol == PROT_SFTP) {
     do {
       ssh->sftp_session = libssh2_sftp_init(ssh->ssh_session);
     } while (!ssh->sftp_session);

     while ((i = libssh2_sftp_realpath(ssh->sftp_session, ".",

   *done = TRUE;
   return CURLE_OK;


/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------     The Power to Serve
"Eagles may soar, but weasels don't get sucked into jet engines"
     -- Anon
Received on 2007-06-10