From e87293d480b3477c15e85703362c8eef15982c20 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 13 Nov 2010 12:25:06 +0100 Subject: [PATCH] send_existing: return after send_existing When a piece of data is sent from the send_existing() function we must make the parent function return afterwards. Otherwise we risk that the parent function tries to send more data and ends up getting an EGAIN for that more data and since it can only return one return code it doesn't return info for the successfully sent data. As this change is a regression I now added a larger comment explaining why it has to work like this. --- src/transport.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/transport.c b/src/transport.c index f3c71ee..a027ff1 100644 --- a/src/transport.c +++ b/src/transport.c @@ -363,9 +363,9 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) PACKETBUFSIZE - remainbuf, -nread); return LIBSSH2_ERROR_SOCKET_RECV; } - _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, - "Recved %d/%d bytes to %p+%d", nread, - PACKETBUFSIZE - remainbuf, p->buf, remainbuf); + _libssh2_debug(session, LIBSSH2_TRACE_SOCKET, + "Recved %d/%d bytes to %p+%d", nread, + PACKETBUFSIZE - remainbuf, p->buf, remainbuf); debugdump(session, "libssh2_transport_read() raw", &p->buf[remainbuf], nread); @@ -616,7 +616,9 @@ send_existing(LIBSSH2_SESSION *session, const unsigned char *data, /* the remainder of the package was sent */ p->ototal_num = 0; p->olen = 0; - *ret = 0; /* don't return */ + /* we leave *ret set so that the parent returns as we MUST return back + a send success now, so that we don't risk sending EAGAIN later + which then would confuse the parent function */ return LIBSSH2_ERROR_NONE; }