add client nogui mode

This commit is contained in:
ubuntu201711081 2020-12-05 17:55:36 +00:00
parent 38a094ff41
commit 49505178b3
2 changed files with 43 additions and 25 deletions

View File

@ -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)

View File

@ -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;
init_bench_data();
clock_t clock_sum = 0;
clock_t begin_sclock;
clock_t begin_uclock;
int op_count = 0;
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;