From a1e744bb5eb2f95026b1392d16a8f24f5136366b Mon Sep 17 00:00:00 2001 From: Jakob Egger Date: Sun, 15 Mar 2015 08:52:23 +0000 Subject: [PATCH] direct_tcpip: Fixed channel write There were 3 bugs in this loop: 1) Started from beginning after partial writes 2) Aborted when 0 bytes were sent 3) Ignored LIBSSH2_ERROR_EAGAIN See also: https://trac.libssh2.org/ticket/281 https://trac.libssh2.org/ticket/293 --- example/direct_tcpip.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index d1196a8..fc3b5bf 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -275,14 +275,17 @@ int main(int argc, char *argv[]) goto shutdown; } wr = 0; - do { - i = libssh2_channel_write(channel, buf, len); + while(wr < len) { + i = libssh2_channel_write(channel, buf + wr, len - wr); + if (LIBSSH2_ERROR_EAGAIN == i) { + continue; + } if (i < 0) { fprintf(stderr, "libssh2_channel_write: %d\n", i); goto shutdown; } wr += i; - } while(i > 0 && wr < len); + } } while (1) { len = libssh2_channel_read(channel, buf, sizeof(buf));