From 006f233361911ac06cf7d4e321128c7b115d6060 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Thu, 2 Oct 2008 02:26:49 +0000 Subject: [PATCH] This fix addresses bug# 2141548. Channel reads would fail despite libssh2_poll() detecting that there was data ready to be read on the socket. This is seen when small amounts of data are ready to be read, typically 1-4 chars worth. --- src/channel.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/channel.c b/src/channel.c index 28daba1..524f1d4 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1521,13 +1521,14 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL * channel, int stream_id, char *buf, channel->read_packet = session->packets.head; } - if (rc < 0) { - if (rc != PACKET_EAGAIN) { - channel->read_state = libssh2_NB_state_idle; - } - /* no packets available */ - return rc; - } + //We didn't read any data from the socket and no packets are waiting to be read + if (rc < 0) && (! channel->read_packet)) { + if (rc != PACKET_EAGAIN) { + channel->read_state = libssh2_NB_state_idle; + } + /* no packets available */ + return rc; + } while (channel->read_packet && (channel->read_bytes_read < (int) buflen)) {