X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=sendfile%2Fclient%2Fclient.c;h=f5d93be6894c63613a3b148a78bb04b1c45c2242;hb=f1d5f09dd86dfbbe34b8d915f150d68ed779f146;hp=1e5b59efd73ea07a3aad31e4d7d667a97c1afd1b;hpb=b5fd47dcb6af4b842455c2f6fb2b0fc58704f08c;p=p2p-kernel-protocol.git diff --git a/sendfile/client/client.c b/sendfile/client/client.c index 1e5b59e..f5d93be 100644 --- a/sendfile/client/client.c +++ b/sendfile/client/client.c @@ -5,13 +5,16 @@ #include #include #include +#include #include #include +#include #include #include +#include "../utils/utils.h" + #define MAX_NUMBER_OF_PEERS 256 -#define CHUNK_SIZE 256 int main(int argc, char **argv) { int sock, err; @@ -21,6 +24,8 @@ int main(int argc, char **argv) { int fd[MAX_NUMBER_OF_PEERS]; int peers[MAX_NUMBER_OF_PEERS]; int i = 0, total, sent_size; + struct timeval start; + struct timeval stop; if (argc < 4 || argc % 2) { printf("Usage: %s " @@ -76,21 +81,28 @@ int main(int argc, char **argv) { printf("Opening file error: %s(%d)\n", strerror(errno), errno); i--; } + argv += 2; } total = i; + gettimeofday(&start, NULL); do { sent_size = 0; for (i = 0; i < total; i++) { - if ((err = sendfile(fd[i], peers[i], NULL, CHUNK_SIZE)) < 0) { + if ((err = sendfile(peers[i], fd[i], NULL, CHUNK_SIZE)) < 0) { printf("Sending file error: %s(%d)\n", strerror(errno), errno); - } else { - sent_size += err; + continue; } + sent_size += err; + usleep(20); } } while(sent_size); + gettimeofday(&stop, NULL); + + printf("Successfully written %s in %ld seconds\n", file_name, + stop.tv_sec - start.tv_sec); return 0; }