Subject: [libssh2] More progress in converting to nonblocking

[libssh2] More progress in converting to nonblocking

From: James Housley <>
Date: Mon, 4 Jun 2007 10:09:58 -0400

The current code is available at

I am nearly done with the code. Right now, as far as I know, all the
routines in session, packet, kex, userauth, publickey and scp
routines are fully non-blocking capable. All the channel routines
except for libssh2_channel_read_ex() are done. That one is a little
complex and I keep looking at it and putting it off. In a couple of
routings I found that "goto" was the best solution.

There have been no significant changes to the API yet. I added:
LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL
*channel, int ignore_mode)
LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session)

libssh2_channel_handle_extended_data2() is a non-blocking version of

libssh2_session_last_errno() make it much easier to check the last
error if you only care about the error number. This is needed for
calls like libssh2_channel_open_ex() that return a channel
structure. libssh2_channel_open_ex() no set the error to
LIBSSH2_ERROR_EAGAIN and return NULL. So in non-blocking a code
segment like this could be used:

channel = libssh2_channel_open_ex(session, ......);
if (!channel) {
     if (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) {
         /* previous call set libssh2_session_last_error(), pass it
through */
         LIBSSH2_FREE(session, session->scpSend_command);
         return NULL;
     else if (libssh2_session_last_errno(session) ==
         libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block
starting up channel", 0);
         return NULL;

Still to do is libssh2_channel_read_ex() and the sftp subsystem. The
last part will be the documentation


/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------     The Power to Serve
In theory there is no difference between theory and practice.
In practice there is no similarity.
       -- From the "I wish I'd said that" archives.
This email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
libssh2-devel mailing list
Received on 2007-06-04