From 7b5e554d8559eb52a8fa207f048798ddf059af63 Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Sat, 5 Dec 2020 02:13:13 +0000 Subject: [PATCH] add slowclient --- Makefile | 6 ++++-- README.md | 3 ++- client.c | 16 +++++++++++----- p-client.c | 7 +++++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index d5ff166..78862e9 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,10 @@ p-server: socket_wrapper.o p-server.c $(CC) -o p-server p-server.c socket_wrapper.o $(CFLAGS) p-client: socket_wrapper.o p-client.c $(CC) -o p-client p-client.c socket_wrapper.o $(CFLAGS) -p-slowclient: socket_wrapper.o p-client.c - $(CC) -o p-slowclient p-client.c socket_wrapper.o $(CFLAGS) -D SLOW_CLIENT=10 +p-mulclient: socket_wrapper.o p-client.c + $(CC) -o p-slowclient p-client.c socket_wrapper.o $(CFLAGS) -D MUL_CLIENT=10 +slowclient: socket_wrapper.o client.c + $(CC) -o slowclient client.c socket_wrapper.o $(CFLAGS) -D SLOW_CLIENT=1000 .PHONY: clean moveall clean: diff --git a/README.md b/README.md index f58544d..2267855 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ For server - DEFAULT_MAX_THREAD_NUMBER: 10 For client -- SLOW_CLIENT(second unit) +- MUL_CLIENT(second unit) +- SLOW_CLIENT(microsecond unit, (buf_size/SLOW_CLIENT) bytes/usec) - DEFAULT_PROGRESS_BAR_WIDTH: 30 For both diff --git a/client.c b/client.c index 611a8cd..63e2ad6 100644 --- a/client.c +++ b/client.c @@ -27,8 +27,11 @@ static const int TIMEOUT = 5; #else static const int TIMEOUT = DEFAULT_TIMEOUT; #endif - +#ifndef DEFAULT_PROGRESS_BAR_WIDTH static const int PROGRESS_BAR_WIDTH = 30; +#else +static const int PROGRESS_BAR_WIDTH = DEFAULT_PROGRESS_BAR_WIDTH; +#endif /*======== *Operation *========*/ @@ -41,8 +44,8 @@ int sendReadOp(int sock,const char * filename){ perror("readop send fail"); return -1; } - #ifdef SLOW_CLIENT - sleep(SLOW_CLIENT); + #ifdef MUL_CLIENT + sleep(MUL_CLIENT); #endif if(send(sock,filename,op.file_url_size,0)<0){ perror("readop filename send fail"); @@ -66,7 +69,7 @@ void DisplayProgressBar(size_t offset,size_t total,double cur_progress){ buf[i] = '='; else if(i == cur_pos) buf[i] = '>'; - else buf[i] = ' '; + else buf[i] = '.'; } printf("\r[%s]: %.2f%% bytes: %ld/%ld bytes",buf,cur_progress,total,offset); } @@ -82,7 +85,7 @@ int recvFile(int sock, const char * filename,size_t file_size){ int fd; size_t count = 0; int i; - int cur_progress = 1; + double cur_progress = 1; int return_value = 0; int buf_sz = getBufferSizeFrom(sock); uint8_t * buf = malloc(buf_sz*sizeof(*buf)); @@ -117,6 +120,9 @@ int recvFile(int sock, const char * filename,size_t file_size){ fflush(stdout); } count += readed; + #ifdef SLOW_CLIENT + usleep(SLOW_CLIENT); + #endif } DisplayProgressBar100Percent(file_size); END: diff --git a/p-client.c b/p-client.c index 2fc1a88..ee26707 100644 --- a/p-client.c +++ b/p-client.c @@ -45,8 +45,8 @@ int sendReadOp(int sock,const char * filename){ perror("readop send fail"); return -1; } - #ifdef SLOW_CLIENT - sleep(SLOW_CLIENT); + #ifdef MUL_CLIENT + sleep(MUL_CLIENT); #endif if(send(sock,filename,op.file_url_size,0)<0){ perror("readop filename send fail"); @@ -121,6 +121,9 @@ int recvFile(int sock, const char * filename,size_t file_size){ fflush(stdout); } count += readed; + #ifdef SLOW_CLIENT + usleep(SLOW_CLIENT); + #endif } DisplayProgressBar100Percent(file_size); END: