bug #2785173 pointed out that we really must call _libssh2_transport_read()

in loops until it returns < 0 when we call it, as if we just call it once we
may drain the socket for data and then leave unused in-memory data that we
won't detect because the socket is back to idle...
This commit is contained in:
Daniel Stenberg
2009-05-01 19:07:20 +00:00
parent 9f104cd883
commit 9412588373

View File

@@ -1758,28 +1758,18 @@ static ssize_t channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
"stream #%d", "stream #%d",
(int) buflen, channel->local.id, channel->remote.id, (int) buflen, channel->local.id, channel->remote.id,
stream_id); stream_id);
rc = 1; /* set to >0 to let the while loop start */
/* process all pending incoming packets */
while (rc > 0)
rc = _libssh2_transport_read(session);
if ((rc < 0) && (rc != PACKET_EAGAIN))
return -1;
channel->read_state = libssh2_NB_state_created; channel->read_state = libssh2_NB_state_created;
} }
else { rc = 1; /* set to >0 to let the while loop start */
/* We're not in the idle state, but in order to "even out" the network
readings we do a single shot read here as well. Tests prove that /* Process all pending incoming packets in all states in order to "even
this way produces faster transfers. */ out" the network readings. Tests prove that this way produces faster
transfers. */
while (rc > 0)
rc = _libssh2_transport_read(session); rc = _libssh2_transport_read(session);
/* ignore PACKET_EAGAIN but return failure for the rest */ if ((rc < 0) && (rc != PACKET_EAGAIN))
if ((rc < 0) && (rc != PACKET_EAGAIN)) return -1;
return -1;
}
/* /*
* =============================== NOTE =============================== * =============================== NOTE ===============================