From d89782d99f9405af9a4f5c70c1c89aee87b8ef5d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 13 Mar 2009 22:14:47 +0000 Subject: [PATCH] improved non-blocking behavior for some of the initing stuff before the actual data transfer begins --- example/simple/sftp_nonblock.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/example/simple/sftp_nonblock.c b/example/simple/sftp_nonblock.c index 3637eab..f1dd575 100644 --- a/example/simple/sftp_nonblock.c +++ b/example/simple/sftp_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_nonblock.c,v 1.16 2009/03/13 12:35:13 bagder Exp $ + * $Id: sftp_nonblock.c,v 1.17 2009/03/13 22:14:47 bagder Exp $ * * Sample showing how to do SFTP non-blocking transfers. * @@ -205,15 +205,23 @@ int main(int argc, char *argv[]) goto shutdown; } } - +#if 0 + libssh2_trace(session, LIBSSH2_TRACE_CONN); +#endif fprintf(stderr, "libssh2_sftp_init()!\n"); do { sftp_session = libssh2_sftp_init(session); - if ((!sftp_session) && (libssh2_session_last_errno(session) != - LIBSSH2_ERROR_EAGAIN)) { - fprintf(stderr, "Unable to init SFTP session\n"); - goto shutdown; + if(!sftp_session) { + if(libssh2_session_last_errno(session) == + LIBSSH2_ERROR_EAGAIN) { + fprintf(stderr, "non-blocking init\n"); + waitsocket(sock, session); /* now we wait */ + } + else { + fprintf(stderr, "Unable to init SFTP session\n"); + goto shutdown; + } } } while (!sftp_session); @@ -223,10 +231,15 @@ int main(int argc, char *argv[]) sftp_handle = libssh2_sftp_open(sftp_session, sftppath, LIBSSH2_FXF_READ, 0); - if (!sftp_handle && - (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { - fprintf(stderr, "Unable to open file with SFTP\n"); - goto shutdown; + if (!sftp_handle) { + if (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) { + fprintf(stderr, "Unable to open file with SFTP\n"); + goto shutdown; + } + else { + fprintf(stderr, "non-blocking open\n"); + waitsocket(sock, session); /* now we wait */ + } } } while (!sftp_handle); @@ -258,6 +271,7 @@ int main(int argc, char *argv[]) shutdown: + printf("libssh2_session_disconnect\n"); while ((rc = libssh2_session_disconnect(session, "Normal Shutdown, Thank you")) == LIBSSH2_ERROR_EAGAIN);