From 95b73812e793d5d558bea98b6e02ceac7852c2b9 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Sun, 9 Nov 2008 17:54:23 +0000 Subject: [PATCH] Fixes a problem that the last code change apparently didn't fix. Verified that this works correctly with another user. --- src/channel.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/channel.c b/src/channel.c index e73eb730..640b16d8 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1492,10 +1492,8 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL * channel, int stream_id, char *buf, return rc; } channel->read_bytes_read = 0; - channel->read_block = 0; channel->read_packet = session->packets.head; - channel->read_state = libssh2_NB_state_created; } @@ -1509,25 +1507,33 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL * channel, int stream_id, char *buf, } rc = 0; + channel->read_block = 0; do { if (channel->read_block) { - /* in the second lap and onwards, do this */ - rc = libssh2_packet_read(session); - channel->read_packet = session->packets.head; - } - - /* We didn't read any data from the socket and - * no packets are waiting to be read - * -or- - * We have read our fill of data */ - if ((rc < 0 && ! channel->read_packet) || - channel->read_bytes_read >= (int) buflen) { - if (rc != PACKET_EAGAIN) { - channel->read_state = libssh2_NB_state_idle; + /* in the second lap and onwards, do this... + * If we haven't yet filled our buffer, try to read more + * data. */ + if ( channel->read_bytes_read < (int) buflen) { + rc = libssh2_packet_read(session); + + /* If we didn't find any more data to read */ + if (rc < 0) { + if ( channel->read_bytes_read > 0){ + break; /* finish processing and return */ + } + + /* no packets available, no data read. */ + channel->read_state = libssh2_NB_state_idle; + return rc; + } + /* We read more data, restart our processing at + * the beginning of our packet list. */ + channel->read_packet = session->packets.head; + } + else { /* The read buffer is full, finish processing and return */ + break; } - /* no packets available */ - return rc; } while (channel->read_packet