add client get input from pipe
This commit is contained in:
parent
7cf9f22037
commit
ee2310cb39
26
client.c
26
client.c
@ -133,6 +133,7 @@ int recvFile(int sock, const char * filename,size_t file_size){
|
||||
DisplayProgressBar100Percent(file_size);
|
||||
END:
|
||||
free(buf);
|
||||
close(fd);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
@ -198,6 +199,9 @@ static inline struct timespec timespec_sub(struct timespec a,struct timespec b){
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char filename_buf[1024];
|
||||
static bool stdinisatty;
|
||||
|
||||
int main(int argc, const char *argv[]){
|
||||
struct sockaddr_in addr;
|
||||
const char * filename;
|
||||
@ -207,15 +211,15 @@ int main(int argc, const char *argv[]){
|
||||
int sock, err;
|
||||
int retval = 0;
|
||||
init_bench_data();
|
||||
stdinisatty = isatty(STDIN_FILENO);
|
||||
|
||||
|
||||
if (argc < 4){
|
||||
if (argc < (stdinisatty ? 4 : 3)){
|
||||
fprintf(stderr,"USAUE: %s SERVERNAME PORT [Option]... [FILENAME]...\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
server_name = argv[1];
|
||||
server_port = atoi(argv[2]);
|
||||
for(;;){
|
||||
while(arg_filename_start < argc){
|
||||
if (strcmp("-b",argv[arg_filename_start])==0
|
||||
||strcmp("--benchmark",argv[arg_filename_start])==0){
|
||||
arg_filename_start++;
|
||||
@ -227,7 +231,6 @@ int main(int argc, const char *argv[]){
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
if (server_port == 0){
|
||||
fprintf(stderr,"port invalid\n");
|
||||
return 1;
|
||||
@ -251,8 +254,19 @@ int main(int argc, const char *argv[]){
|
||||
if (bench.benchmode){
|
||||
clock_gettime(bench.clock_id,&bench.begin);
|
||||
}
|
||||
while (arg_filename_start < argc){
|
||||
filename = argv[arg_filename_start++];
|
||||
for (;;){
|
||||
if (stdinisatty){
|
||||
if (arg_filename_start >= argc) break;
|
||||
filename = argv[arg_filename_start++];
|
||||
}
|
||||
else{
|
||||
//unsafe.
|
||||
int t = fscanf(stdin,"%s",filename_buf);
|
||||
if (t != 1) break;
|
||||
filename = filename_buf;
|
||||
}
|
||||
fprintf(stdout,"request %s\n",filename);
|
||||
|
||||
sock = socket(AF_INET,SOCK_STREAM,0);
|
||||
if(sock < 0){
|
||||
perror("sock create fail");
|
||||
|
Loading…
Reference in New Issue
Block a user