From 75d5830490d2ef967ddee4880b55d7e65fc9f3a3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 27 Mar 2009 22:24:09 +0000 Subject: [PATCH] Additional non-blocking fixes. --- src/channel.c | 7 ++++--- src/channel.h | 3 +++ src/sftp.c | 17 ++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/channel.c b/src/channel.c index 0de401a..9f4e926 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1672,8 +1672,8 @@ libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel, return rc; } -static int -channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode) +int +_libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode) { if (channel->extData2_state == libssh2_NB_state_idle) { _libssh2_debug(channel->session, LIBSSH2_DBG_CONN, @@ -1708,7 +1708,8 @@ libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, int mode) { int rc; - BLOCK_ADJUST(rc, channel->session, channel_extended_data(channel, mode)); + BLOCK_ADJUST(rc, channel->session, _libssh2_channel_extended_data(channel, + mode)); return rc; } diff --git a/src/channel.h b/src/channel.h index 64b5f59..e9fc293 100644 --- a/src/channel.h +++ b/src/channel.h @@ -70,5 +70,8 @@ int _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid); */ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel); +int +_libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode); + #endif /* __LIBSSH2_CHANNEL_H */ diff --git a/src/sftp.c b/src/sftp.c index 25bbcce..7703b48 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -36,6 +36,8 @@ * OF SUCH DAMAGE. */ +#include + #include "libssh2_priv.h" #include "libssh2_sftp.h" #include "channel.h" @@ -561,6 +563,8 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) _libssh2_debug(session, LIBSSH2_DBG_SFTP, "Initializing SFTP subsystem"); + assert(session->sftpInit_sftp == NULL); + session->sftpInit_sftp = NULL; session->sftpInit_state = libssh2_NB_state_created; @@ -575,14 +579,13 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) if (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) { libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block starting up channel", 0); - return NULL; - } else if (libssh2_session_last_errno(session) != - LIBSSH2_ERROR_EAGAIN) { + } + else { libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, "Unable to startup channel", 0); session->sftpInit_state = libssh2_NB_state_idle; - return NULL; } + return NULL; } session->sftpInit_state = libssh2_NB_state_sent; @@ -607,8 +610,8 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) } if (session->sftpInit_state == libssh2_NB_state_sent1) { - rc = libssh2_channel_handle_extended_data2(session->sftpInit_channel, - LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE); + rc = _libssh2_channel_extended_data(session->sftpInit_channel, + LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE); if (rc == PACKET_EAGAIN) { libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block requesting handle extended data", 0); @@ -709,7 +712,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) return session->sftpInit_sftp; sftp_init_error: - while (libssh2_channel_free(session->sftpInit_channel) == PACKET_EAGAIN); + while (_libssh2_channel_free(session->sftpInit_channel) == PACKET_EAGAIN); session->sftpInit_channel = NULL; if (session->sftpInit_sftp) { LIBSSH2_FREE(session, session->sftpInit_sftp);