From ba2f21eb85bb9c0f22c291e576560981448bb185 Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Fri, 6 May 2005 18:30:43 +0000 Subject: [PATCH] More fixes for channel_write() --- README | 5 +++++ src/channel.c | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README b/README index bc1498b..0d88c87 100644 --- a/README +++ b/README @@ -1,6 +1,11 @@ libssh2 - SSH2 library ====================== +Version 0.10 +------------ + + (Re)Fixed channel_write() to provide an opportunity for window space to become available again. + Version 0.9 ----------- diff --git a/src/channel.c b/src/channel.c index 7100399..5182599 100644 --- a/src/channel.c +++ b/src/channel.c @@ -861,12 +861,9 @@ LIBSSH2_API int libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, int stream_id libssh2_error(session, LIBSSH2_ERROR_CHANNEL_EOF_SENT, "EOF has already been sight, data might be ignored", 0); } - if (channel->blocking && (channel->local.window_size <= 0)) { - /* twiddle our thumbs until there's window space available */ - if (libssh2_packet_read(session, 1) < 0) { - /* Error occured, disconnect? */ - return -1; - } + if (!channel->blocking && (channel->local.window_size <= 0)) { + /* Can't write anything */ + return 0; } packet_len = buflen + (stream_id ? 13 : 9); /* packet_type(1) + channelno(4) [ + streamid(4) ] + buflen(4) */ @@ -886,6 +883,15 @@ LIBSSH2_API int libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, int stream_id libssh2_htonu32(s, stream_id); s += 4; } + /* twiddle our thumbs until there's window space available */ + while (channel->local.window_size <= 0) { + /* Don't worry -- This is never hit unless it's a blocking channel anyway */ + if (libssh2_packet_read(session, 1) < 0) { + /* Error occured, disconnect? */ + return -1; + } + } + /* Don't exceed the remote end's limits */ /* REMEMBER local means local as the SOURCE of the data */ if (bufwrite > channel->local.window_size) {