1
1

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
Этот коммит содержится в:
Jakob Egger 2015-03-15 08:52:23 +00:00 коммит произвёл Daniel Stenberg
родитель 14d9ee01bc
Коммит a1e744bb5e

Просмотреть файл

@ -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));