From 49505178b336ea2bd7ee0328a1e0b9282ef63a70 Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Sat, 5 Dec 2020 17:55:36 +0000 Subject: [PATCH] add client nogui mode --- README.md | 8 +++++--- client.c | 60 +++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index bb95630..5c22318 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,12 @@ Usage: ``` Server OPTION and arguments: -- `-p port` :set to port binding. couldn't set to 0 -- `-h` :print help message. +- `-p port` :set to port binding. couldn't set to 0 +- `-h` or `--help` :print help message. Client option and arguments: -- `-b` :benchmark mode +- `-b` or `--benchmark` :benchmark mode +- `--nogui` :no progress bar Available macro: @@ -28,6 +29,7 @@ For server - DEFAULT_WORK_QUEUE_SIZE(server only): 10 - DEFAULT_MAX_THREAD_NUMBER(server only): 10 - DEFAULT_RESPONSE_REQUEST(p-server only): 3(-1 is INF) + For client - MUL_CLIENT(second unit) - SLOW_CLIENT(microsecond unit, (buf_size/SLOW_CLIENT) bytes/usec) diff --git a/client.c b/client.c index d19e206..09b69a6 100644 --- a/client.c +++ b/client.c @@ -85,6 +85,7 @@ void DisplayProgressBar100Percent(size_t total){ buf[PROGRESS_BAR_WIDTH] = '\0'; printf("\r[%s]: 100%% bytes: %ld/%ld bytes\n",buf,total,total); } +static bool DisplayProgress = true; int recvFile(int sock, const char * filename,size_t file_size){ int fd; size_t count = 0; @@ -118,7 +119,7 @@ int recvFile(int sock, const char * filename,size_t file_size){ return_value = -1; goto END; } - if( isProgressBarNeedUpdate(count,file_size,cur_progress) ){ + if( DisplayProgress && isProgressBarNeedUpdate(count,file_size,cur_progress) ){ DisplayProgressBar(count,file_size,cur_progress); cur_progress = (int)((((double)count / (double)file_size)) * 100.0 + 1.0); fflush(stdout); @@ -128,7 +129,8 @@ int recvFile(int sock, const char * filename,size_t file_size){ usleep(SLOW_CLIENT); #endif } - DisplayProgressBar100Percent(file_size); + if(DisplayProgress) + DisplayProgressBar100Percent(file_size); END: free(buf); return return_value; @@ -166,6 +168,17 @@ int recvData(int sock,const char * filename){ return 0; } +struct benchmark_data{ + bool benchmode; + clock_t clock_sum; + clock_t begin_sclock; + clock_t begin_uclock; + int op_count; +} bench = {0,}; + +void init_bench_data(){ + memset(&bench,0,sizeof(bench)); +} int main(int argc, const char *argv[]){ struct sockaddr_in addr; @@ -175,23 +188,26 @@ int main(int argc, const char *argv[]){ int arg_filename_start = 3; int sock, err; int retval = 0; - bool benchmode = false; - - clock_t clock_sum = 0; - clock_t begin_sclock; - clock_t begin_uclock; - - int op_count = 0; + init_bench_data(); + + if (argc < 4){ fprintf(stderr,"USAUE: %s SERVERNAME PORT [Option]... [FILENAME]...\n",argv[0]); return 1; } server_name = argv[1]; server_port = atoi(argv[2]); - if (strcmp("-b",argv[arg_filename_start])==0 - ||strcmp("--benchmark",argv[arg_filename_start])==0){ - arg_filename_start++; - benchmode = true; + for(;;){ + if (strcmp("-b",argv[arg_filename_start])==0 + ||strcmp("--benchmark",argv[arg_filename_start])==0){ + arg_filename_start++; + bench.benchmode = true; + } + else if(strcmp("--nogui",argv[arg_filename_start])==0){ + arg_filename_start++; + DisplayProgress = false; + } + else break; } if (server_port == 0){ @@ -214,11 +230,11 @@ int main(int argc, const char *argv[]){ addr.sin_family = AF_INET; addr.sin_port = htons(server_port); - if (benchmode){ + if (bench.benchmode){ struct tms t; times(&t); - begin_sclock = t.tms_stime; - begin_uclock = t.tms_utime; + bench.begin_sclock = t.tms_stime; + bench.begin_uclock = t.tms_utime; } while (arg_filename_start < argc){ filename = argv[arg_filename_start++]; @@ -240,16 +256,16 @@ int main(int argc, const char *argv[]){ retval += ret; } close(sock); - op_count++; + bench.op_count++; } - if (benchmode){ + if (bench.benchmode){ struct tms t; times(&t); - clock_sum += t.tms_stime - begin_sclock; - clock_sum += t.tms_utime - begin_uclock; + bench.clock_sum += t.tms_stime - bench.begin_sclock; + bench.clock_sum += t.tms_utime - bench.begin_uclock; } - if (benchmode){ - fprintf(stdout,"operation: %lf ticks/op\n",((double)clock_sum)/((double)op_count)); + if (bench.benchmode){ + fprintf(stdout,"operation: %lf ticks/op\n",((double)bench.clock_sum)/((double)bench.op_count)); } return retval;