Subject: [libssh2] Time for review of the NonBlocking code

[libssh2] Time for review of the NonBlocking code

From: James Housley <>
Date: Wed, 23 May 2007 13:33:04 -0400

Before I continue on this path I would feel better if my methodology
was reviewed. I started with the functions that call send(2) and recv
(2). Then worked up to the functions that call them directly and
made them reentrant for non-blocking. Some functions I added a
variable to the argument list the stores the state and others I put
the state in LIBSSH2_SESSION *session. When I was positive of the
calling sources it went in to *session. Some that didn't go in yet
probably can and will go in later. There are two text files in the
root of the source that I have been using to help track my progress,
I believe they are up to date.

Right now libssh2_session_startup() is the only fully reentrant non-
blocking function I have done.

I have some concerns about this style, but I don't know a different
method. Some of the functions allocate memory from the heap, which I
had to add to the state so they could be maintained across calls. In
blocking mode there are not problems. In non-blocking mode there are
no problems if the library function, libssh2_session_startup() for
example, is called again when LIBSSH2_ERROR_EAGAIN is returned until
an error is encountered or success. Both an error and success will
properly free all memory. However, if the users program decides to
stop retrying the function because it has been taking too long two
things happen. First, all the active states won't be returned to
idle. Secondly, if there was memory allocated it won't be freed.

My current code is available for download at http://

I have been doing testing with examples/simple/ and
examples/simple/ , those two have been updated
to meet some new requirements.


/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------     The Power to Serve
Q: Because it reverses the logical flow of conversation.
A: Why is putting a reply at the top of the message frowned upon?
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-05-23