add client nogui mode
This commit is contained in:
parent
38a094ff41
commit
49505178b3
@ -11,11 +11,12 @@ Usage:
|
|||||||
```
|
```
|
||||||
|
|
||||||
Server OPTION and arguments:
|
Server OPTION and arguments:
|
||||||
- `-p port` :set to port binding. couldn't set to 0
|
- `-p port` :set to port binding. couldn't set to 0
|
||||||
- `-h` :print help message.
|
- `-h` or `--help` :print help message.
|
||||||
|
|
||||||
Client option and arguments:
|
Client option and arguments:
|
||||||
- `-b` :benchmark mode
|
- `-b` or `--benchmark` :benchmark mode
|
||||||
|
- `--nogui` :no progress bar
|
||||||
|
|
||||||
Available macro:
|
Available macro:
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ For server
|
|||||||
- DEFAULT_WORK_QUEUE_SIZE(server only): 10
|
- DEFAULT_WORK_QUEUE_SIZE(server only): 10
|
||||||
- DEFAULT_MAX_THREAD_NUMBER(server only): 10
|
- DEFAULT_MAX_THREAD_NUMBER(server only): 10
|
||||||
- DEFAULT_RESPONSE_REQUEST(p-server only): 3(-1 is INF)
|
- DEFAULT_RESPONSE_REQUEST(p-server only): 3(-1 is INF)
|
||||||
|
|
||||||
For client
|
For client
|
||||||
- MUL_CLIENT(second unit)
|
- MUL_CLIENT(second unit)
|
||||||
- SLOW_CLIENT(microsecond unit, (buf_size/SLOW_CLIENT) bytes/usec)
|
- SLOW_CLIENT(microsecond unit, (buf_size/SLOW_CLIENT) bytes/usec)
|
||||||
|
56
client.c
56
client.c
@ -85,6 +85,7 @@ void DisplayProgressBar100Percent(size_t total){
|
|||||||
buf[PROGRESS_BAR_WIDTH] = '\0';
|
buf[PROGRESS_BAR_WIDTH] = '\0';
|
||||||
printf("\r[%s]: 100%% bytes: %ld/%ld bytes\n",buf,total,total);
|
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 recvFile(int sock, const char * filename,size_t file_size){
|
||||||
int fd;
|
int fd;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
@ -118,7 +119,7 @@ int recvFile(int sock, const char * filename,size_t file_size){
|
|||||||
return_value = -1;
|
return_value = -1;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
if( isProgressBarNeedUpdate(count,file_size,cur_progress) ){
|
if( DisplayProgress && isProgressBarNeedUpdate(count,file_size,cur_progress) ){
|
||||||
DisplayProgressBar(count,file_size,cur_progress);
|
DisplayProgressBar(count,file_size,cur_progress);
|
||||||
cur_progress = (int)((((double)count / (double)file_size)) * 100.0 + 1.0);
|
cur_progress = (int)((((double)count / (double)file_size)) * 100.0 + 1.0);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -128,7 +129,8 @@ int recvFile(int sock, const char * filename,size_t file_size){
|
|||||||
usleep(SLOW_CLIENT);
|
usleep(SLOW_CLIENT);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
DisplayProgressBar100Percent(file_size);
|
if(DisplayProgress)
|
||||||
|
DisplayProgressBar100Percent(file_size);
|
||||||
END:
|
END:
|
||||||
free(buf);
|
free(buf);
|
||||||
return return_value;
|
return return_value;
|
||||||
@ -166,6 +168,17 @@ int recvData(int sock,const char * filename){
|
|||||||
|
|
||||||
return 0;
|
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[]){
|
int main(int argc, const char *argv[]){
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
@ -175,23 +188,26 @@ int main(int argc, const char *argv[]){
|
|||||||
int arg_filename_start = 3;
|
int arg_filename_start = 3;
|
||||||
int sock, err;
|
int sock, err;
|
||||||
int retval = 0;
|
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){
|
if (argc < 4){
|
||||||
fprintf(stderr,"USAUE: %s SERVERNAME PORT [Option]... [FILENAME]...\n",argv[0]);
|
fprintf(stderr,"USAUE: %s SERVERNAME PORT [Option]... [FILENAME]...\n",argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
server_name = argv[1];
|
server_name = argv[1];
|
||||||
server_port = atoi(argv[2]);
|
server_port = atoi(argv[2]);
|
||||||
if (strcmp("-b",argv[arg_filename_start])==0
|
for(;;){
|
||||||
||strcmp("--benchmark",argv[arg_filename_start])==0){
|
if (strcmp("-b",argv[arg_filename_start])==0
|
||||||
arg_filename_start++;
|
||strcmp("--benchmark",argv[arg_filename_start])==0){
|
||||||
benchmode = true;
|
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){
|
if (server_port == 0){
|
||||||
@ -214,11 +230,11 @@ int main(int argc, const char *argv[]){
|
|||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(server_port);
|
addr.sin_port = htons(server_port);
|
||||||
|
|
||||||
if (benchmode){
|
if (bench.benchmode){
|
||||||
struct tms t;
|
struct tms t;
|
||||||
times(&t);
|
times(&t);
|
||||||
begin_sclock = t.tms_stime;
|
bench.begin_sclock = t.tms_stime;
|
||||||
begin_uclock = t.tms_utime;
|
bench.begin_uclock = t.tms_utime;
|
||||||
}
|
}
|
||||||
while (arg_filename_start < argc){
|
while (arg_filename_start < argc){
|
||||||
filename = argv[arg_filename_start++];
|
filename = argv[arg_filename_start++];
|
||||||
@ -240,16 +256,16 @@ int main(int argc, const char *argv[]){
|
|||||||
retval += ret;
|
retval += ret;
|
||||||
}
|
}
|
||||||
close(sock);
|
close(sock);
|
||||||
op_count++;
|
bench.op_count++;
|
||||||
}
|
}
|
||||||
if (benchmode){
|
if (bench.benchmode){
|
||||||
struct tms t;
|
struct tms t;
|
||||||
times(&t);
|
times(&t);
|
||||||
clock_sum += t.tms_stime - begin_sclock;
|
bench.clock_sum += t.tms_stime - bench.begin_sclock;
|
||||||
clock_sum += t.tms_utime - begin_uclock;
|
bench.clock_sum += t.tms_utime - bench.begin_uclock;
|
||||||
}
|
}
|
||||||
if (benchmode){
|
if (bench.benchmode){
|
||||||
fprintf(stdout,"operation: %lf ticks/op\n",((double)clock_sum)/((double)op_count));
|
fprintf(stdout,"operation: %lf ticks/op\n",((double)bench.clock_sum)/((double)bench.op_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
Loading…
Reference in New Issue
Block a user