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:
parent
9f104cd883
commit
9412588373
@ -1758,29 +1758,19 @@ 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);
|
||||||
|
channel->read_state = libssh2_NB_state_created;
|
||||||
|
}
|
||||||
rc = 1; /* set to >0 to let the while loop start */
|
rc = 1; /* set to >0 to let the while loop start */
|
||||||
|
|
||||||
/* process all pending incoming packets */
|
/* Process all pending incoming packets in all states in order to "even
|
||||||
|
out" the network readings. Tests prove that this way produces faster
|
||||||
|
transfers. */
|
||||||
while (rc > 0)
|
while (rc > 0)
|
||||||
rc = _libssh2_transport_read(session);
|
rc = _libssh2_transport_read(session);
|
||||||
|
|
||||||
if ((rc < 0) && (rc != PACKET_EAGAIN))
|
if ((rc < 0) && (rc != PACKET_EAGAIN))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
channel->read_state = libssh2_NB_state_created;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* 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
|
|
||||||
this way produces faster transfers. */
|
|
||||||
rc = _libssh2_transport_read(session);
|
|
||||||
|
|
||||||
/* ignore PACKET_EAGAIN but return failure for the rest */
|
|
||||||
if ((rc < 0) && (rc != PACKET_EAGAIN))
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* =============================== NOTE ===============================
|
* =============================== NOTE ===============================
|
||||||
* I know this is very ugly and not a really good use of "goto", but
|
* I know this is very ugly and not a really good use of "goto", but
|
||||||
|
Loading…
x
Reference in New Issue
Block a user