On Fri, 2007-01-26 at 12:40 +0100, Daniel Stenberg wrote:
> 2 - for LOTS of functions we need to change the prototypes to allow them to
> return a "EAGAIN" error code (instead of blocking) until they are done
> and
> can return ok. A few examples are libssh2_sftp_init(),
> libssh2_sftp_open(), libssh2_scp_recv(). I would really appreciate some
> input on how to proceed on that. I figure we should make them all return
> an 'int' and have them get handles passed back in a pointer pointer
> argument. Or does anyone have any other thoughts on this?
How about an approach that won't require changing the API? E.g., right
now we have blocking functions:
LIBSSH2_API LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session)
LIBSSH2_API LIBSSH2_SFTP_HANDLE *libssh2_sftp_open_ex(LIBSSH2_SFTP
*sftp, ...)
...
You could write a non-blocking version of those functions and calling
them:
int libssh2_async_sftp_init(..., LIBSSH2_SFTP **sftp)
int libssh2_async_sftp_open(..., LIBSSH2_SFTP_HANDLE *sftph)
...
Alternatively, if ssh only support one concurrent sftp session, the
LIBSSH2_SFTP_HANDLE could be stored inside the LIBSSH2_SESSION object,
but I assume this isn't the case.
Of course, change the names to something more appropriate if you want.
Perhaps 'libssh2_sftp_init_nb' and 'libssh2_sftp_open_nb' etc?
Then the blocking versions can be implemented using the non-blocking
functions, roughly as follows:
LIBSSH2_API LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session)
{
int ret;
LIBSSH2_SFTP *sftph;
do {
ret = libssh2_async_sftp_init (session, &sftph);
} while (ret == EAGAIN);
return sftph;
}
And so on.
I'm not familiar with the libssh2 API or what the non-blocking
requirements really are, so these are just my generic API design
thoughts.
/Simon
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
libssh2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libssh2-devel