projects
/
p2p-kernel-protocol.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
sendfile: added timer for client
[p2p-kernel-protocol.git]
/
sendfile
/
client
/
client.c
diff --git
a/sendfile/client/client.c
b/sendfile/client/client.c
index
1e5b59e
..
f5d93be
100644
(file)
--- a/
sendfile/client/client.c
+++ b/
sendfile/client/client.c
@@
-5,13
+5,16
@@
#include <sys/sendfile.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/sendfile.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <sys/time.h>
#include <fcntl.h>
#include <string.h>
#include <fcntl.h>
#include <string.h>
+#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <errno.h>
#include <netdb.h>
+#include "../utils/utils.h"
+
#define MAX_NUMBER_OF_PEERS 256
#define MAX_NUMBER_OF_PEERS 256
-#define CHUNK_SIZE 256
int main(int argc, char **argv) {
int sock, err;
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;
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>"
if (argc < 4 || argc % 2) {
printf("Usage: %s <file_name> <peer_ip1> <peer_port1> <peer_ip2>"
@@
-76,21
+81,28
@@
int main(int argc, char **argv) {
printf("Opening file error: %s(%d)\n", strerror(errno), errno);
i--;
}
printf("Opening file error: %s(%d)\n", strerror(errno), errno);
i--;
}
+ argv += 2;
}
total = i;
}
total = i;
+ gettimeofday(&start, NULL);
do {
sent_size = 0;
for (i = 0; i < total; i++) {
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);
printf("Sending file error: %s(%d)\n", strerror(errno), errno);
- } else {
- sent_size += err;
+ continue;
}
}
+ sent_size += err;
+ usleep(20);
}
} while(sent_size);
}
} while(sent_size);
+ gettimeofday(&stop, NULL);
+
+ printf("Successfully written %s in %ld seconds\n", file_name,
+ stop.tv_sec - start.tv_sec);
return 0;
}
return 0;
}