Skip to content

Commit

Permalink
direct_tcpip: Fixed channel write
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jakob authored and bagder committed Mar 15, 2015
1 parent 14d9ee0 commit a1e744b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions example/direct_tcpip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit a1e744b

Please sign in to comment.