From 80a03a8610d13b9b9e8278db900e9716f4ad3c13 Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Mon, 7 Dec 2020 10:49:29 +0000 Subject: [PATCH] add client quiet mode --- README.md | 1 + client.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a5f92e2..3e2918a 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Client option and arguments: - `-b` or `--benchmark` :benchmark mode - `-nv` or `--no-verbose` :no progress bar - `-t [number]` or `--thread [number]` :set to thread number. +- `-q` or `--quiet` :no stdout Available macro: diff --git a/client.c b/client.c index bafea34..69e8307 100644 --- a/client.c +++ b/client.c @@ -141,7 +141,7 @@ int recvData(int sock,const char * filename){ else perror("recv fail"); return -1; } - static char error_meesage_buf[80] = ""; + char error_meesage_buf[80] = ""; switch(res.res){ case RES_ERR: fprintf(stderr,"Server Fail: %s\n", strerror(res.err_number)); @@ -166,10 +166,12 @@ int recvData(int sock,const char * filename){ return 0; } +static bool quiet_mode = false; int SendOpAndReceiveFile(const char * filename, struct sockaddr const * addr){ int sock; int ret = -1; - fprintf(stdout,"request %s\n",filename); + if(!quiet_mode) + fprintf(stdout,"request %s\n",filename); sock = socket(AF_INET,SOCK_STREAM,0); if(sock < 0){ @@ -329,6 +331,7 @@ static struct { in_port_t server_port; bool stdinisatty; int thread_number_option; + bool quiet_mode; } cmd_args = { .server_name = "", .server_port = 0 @@ -358,6 +361,7 @@ static int parse_arg(int argc,const char *argv[]){ fprintf(stderr,"port invalid\n"); return -1; } + cmd_args.quiet_mode = false; cmd_args.thread_number_option = 1; for(cur = 3;cur < argc; cur++){ if (strcmp("-b",argv[cur])==0||strcmp("--benchmark",argv[cur])==0){ @@ -382,6 +386,10 @@ static int parse_arg(int argc,const char *argv[]){ show_help_message(stdout,argv[0]); return 0; } + else if(strcmp("-q",argv[cur]) == 0 || strcmp("--quiet",argv[cur]) == 0){ + cmd_args.quiet_mode = true; + quiet_mode = true; + } else break; } if (cmd_args.stdinisatty){ @@ -390,7 +398,6 @@ static int parse_arg(int argc,const char *argv[]){ else{ init_queue_from_file(&global_state.queue,stdin); } - return 0; }