1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-29 13:01:14 +03:00

examples: fixed and made them more similar

The channel read/write functions can return 0 in legitimate cases
without it being an error, and we need to loop properly if they
return short.
This commit is contained in:
Daniel Stenberg
2010-04-26 16:49:30 +02:00
parent c511177d39
commit cb42be1a9c
5 changed files with 24 additions and 19 deletions

View File

@ -47,7 +47,7 @@ int main(int argc, char *argv[])
FILE *local;
int rc;
char mem[1024];
size_t nread, sent;
size_t nread;
char *ptr;
struct stat fileinfo;
@ -168,20 +168,21 @@ int main(int argc, char *argv[])
break;
}
ptr = mem;
sent = 0;
do {
/* write the same data over and over, until error or completion */
rc = libssh2_channel_write(channel, ptr, nread);
if (rc < 0) {
fprintf(stderr, "ERROR %d\n", rc);
} else {
/* rc indicates how many bytes were written this time */
sent += rc;
break;
}
} while (rc > 0 && sent < nread);
else {
/* rc indicates how many bytes were written this time */
ptr += rc;
nread -= rc;
}
} while (nread);
nread -= sent;
} while (1);
fprintf(stderr, "Sending EOF\n");