sendfile: added timer for client
authorRăzvan Crainea <razvan.crainea@gmail.com>
Sat, 2 Jun 2012 12:02:52 +0000 (15:02 +0300)
committerRăzvan Crainea <razvan.crainea@gmail.com>
Sat, 2 Jun 2012 12:02:52 +0000 (15:02 +0300)
sendfile/client/client.c

index 572f9cd..f5d93be 100644 (file)
@@ -5,8 +5,10 @@
 #include <sys/sendfile.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <sys/time.h>
 #include <fcntl.h>
 #include <string.h>
+#include <unistd.h>
 #include <errno.h>
 #include <netdb.h>
 
@@ -22,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 <file_name> <peer_ip1> <peer_port1> <peer_ip2>"
@@ -82,6 +86,7 @@ int main(int argc, char **argv) {
 
        total = i;
 
+       gettimeofday(&start, NULL);
        do {
                sent_size = 0;
 
@@ -94,6 +99,10 @@ int main(int argc, char **argv) {
                        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;
 }