Subject: [libssh2] going non-blocking

[libssh2] going non-blocking

From: Daniel Stenberg <>
Date: Wed, 13 Dec 2006 16:37:44 +0100 (CET)


I'm now starting to get somewhere with my rewrite of some libssh2 internals to
start working in a non-blocking manner.

Currently, I have changed how libssh2_packet_read() works and it now returns a
libssh2packet_t type which can be:

- a positive number like before meaning packet type since it returns after
   each packet so while returning a positive number it should be called again
- zero meaning no packet
- a negative number which means error _or_
   EAGAIN - which means that a full package could not be read from the network
   and that the function should be called again when there is likely to be
   more data to read.

My next step will be to propagate the return code knowledge to the callers of
this function, to make them capable of returning "EAGAIN" to upper layers and
then eventually end up in the application.

So, does anyone have any particular thoughts on how this info is best passed
back to the application? I mean, should we have a way to enforce the current
behaviour? I guess we should. At least if the socket is not set non-blocking,
and we could do the new way if set non-blocking.

Should we introduce a particular typedef for the return type or should we be
satisfied with #defines to let -1 remain "error" and -2 (for example) be
EAGAIN? There's no real point in a typedef other than it makes it more visible
that all the functions that return the same type are somehow expected to
follow the same rules/pattern while the current 'int' is more open-ended.

My goal with this whole non-blocking work is to allow an application to do
poll() (or equivalent) on the socket and then have it call libssh2 that would
deal with what it can deal with and return back without hanging waiting for
further data, to allow the application to go back to wait in the poll().
Nothing within libssh2 should ever hang waiting for network traffic in either
direction if the socket is set non-blocking.

Take Surveys. Earn Cash. Influence the Future of IT
Join's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
libssh2-devel mailing list
Received on 2006-12-13