scp_write_nonblock: add transfer time info
Using the same timing logic and output format as sftp_write_nonblock allows us to very easily run benchmarks on SCP vs SFTP uploads using libssh2.
This commit is contained in:
parent
31d71a94f2
commit
1785d0d6f3
@ -32,6 +32,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -50,10 +51,13 @@ int main(int argc, char *argv[])
|
|||||||
#if defined(HAVE_IOCTLSOCKET)
|
#if defined(HAVE_IOCTLSOCKET)
|
||||||
long flag = 1;
|
long flag = 1;
|
||||||
#endif
|
#endif
|
||||||
char mem[1024];
|
char mem[1024*100];
|
||||||
size_t nread;
|
size_t nread;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
struct stat fileinfo;
|
struct stat fileinfo;
|
||||||
|
time_t start;
|
||||||
|
long total = 0;
|
||||||
|
int duration;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
WSADATA wsadata;
|
WSADATA wsadata;
|
||||||
@ -175,6 +179,7 @@ int main(int argc, char *argv[])
|
|||||||
} while (!channel);
|
} while (!channel);
|
||||||
|
|
||||||
fprintf(stderr, "SCP session waiting to send file\n");
|
fprintf(stderr, "SCP session waiting to send file\n");
|
||||||
|
start = time(NULL);
|
||||||
do {
|
do {
|
||||||
nread = fread(mem, 1, sizeof(mem), local);
|
nread = fread(mem, 1, sizeof(mem), local);
|
||||||
if (nread <= 0) {
|
if (nread <= 0) {
|
||||||
@ -183,6 +188,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
ptr = mem;
|
ptr = mem;
|
||||||
|
|
||||||
|
total += nread;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* write the same data over and over, until error or completion */
|
/* write the same data over and over, until error or completion */
|
||||||
rc = libssh2_channel_write(channel, ptr, nread);
|
rc = libssh2_channel_write(channel, ptr, nread);
|
||||||
@ -199,6 +206,11 @@ int main(int argc, char *argv[])
|
|||||||
} while (nread);
|
} while (nread);
|
||||||
} while (!nread); /* only continue if nread was drained */
|
} while (!nread); /* only continue if nread was drained */
|
||||||
|
|
||||||
|
duration = (int)(time(NULL)-start);
|
||||||
|
|
||||||
|
printf("%ld bytes in %d seconds makes %.1f bytes/sec\n",
|
||||||
|
total, duration, total/(double)duration);
|
||||||
|
|
||||||
fprintf(stderr, "Sending EOF\n");
|
fprintf(stderr, "Sending EOF\n");
|
||||||
while (libssh2_channel_send_eof(channel) == LIBSSH2_ERROR_EAGAIN);
|
while (libssh2_channel_send_eof(channel) == LIBSSH2_ERROR_EAGAIN);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user