Compare commits
4 Commits
940bf1a32c
...
f04d3d86ea
Author | SHA1 | Date | |
---|---|---|---|
|
f04d3d86ea | ||
|
0b148fe3f0 | ||
|
ee2310cb39 | ||
|
7cf9f22037 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -54,10 +54,10 @@ dkms.conf
|
||||
|
||||
#Bin
|
||||
bin/*
|
||||
client_test/*
|
||||
server_test/*
|
||||
tmp/*
|
||||
|
||||
p-client
|
||||
p-server
|
||||
server
|
||||
client
|
||||
slowclient
|
11
Makefile
11
Makefile
@ -23,14 +23,13 @@ p-mulclient: socket_wrapper.o p-client.c
|
||||
slowclient: socket_wrapper.o client.c
|
||||
$(CC) -o slowclient client.c socket_wrapper.o $(CFLAGS) -D SLOW_CLIENT=1000
|
||||
|
||||
.PHONY: clean moveall
|
||||
.PHONY: clean test
|
||||
clean:
|
||||
rm *.o $(Bin)
|
||||
rm $(addprefix client_test/,$(ClientBin))
|
||||
rm $(addprefix server_test/,$(ServerBin))
|
||||
|
||||
moveall:
|
||||
mv client client_test/client
|
||||
mv p-client client_test/p-client
|
||||
mv server server_test/server
|
||||
mv p-server server_test/p-server
|
||||
test:
|
||||
make all
|
||||
make slowclient
|
||||
./test.sh
|
@ -16,7 +16,7 @@ Server OPTION and arguments:
|
||||
|
||||
Client option and arguments:
|
||||
- `-b` or `--benchmark` :benchmark mode
|
||||
- `--nogui` :no progress bar
|
||||
- `-nv` or `--no-verbose` :no progress bar
|
||||
|
||||
Available macro:
|
||||
|
||||
|
30
client.c
30
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,27 +211,26 @@ 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++;
|
||||
bench.benchmode = true;
|
||||
}
|
||||
else if(strcmp("--nogui",argv[arg_filename_start])==0){
|
||||
else if(strcmp("-nv",argv[arg_filename_start]) == 0||strcmp("--no-verbose",argv[arg_filename_start])==0){
|
||||
arg_filename_start++;
|
||||
DisplayProgress = false;
|
||||
}
|
||||
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");
|
||||
@ -278,7 +292,7 @@ int main(int argc, const char *argv[]){
|
||||
if (result.tv_sec == 0) avg = result.tv_nsec;
|
||||
else avg = result.tv_sec * 1e9 + result.tv_nsec;
|
||||
avg /= bench.op_count;
|
||||
fprintf(stdout,"operation: %lf ns/op\n",avg);
|
||||
fprintf(stdout,"operation: %lf us/op\n",avg / 1000.0);
|
||||
fprintf(stdout,"resolution: %ld sec %ld ns\n",bench.resolution.tv_sec,bench.resolution.tv_nsec);
|
||||
}
|
||||
|
||||
|
45
test.sh
Executable file
45
test.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#! /bin/bash
|
||||
|
||||
function do_test(){
|
||||
local testname=$1
|
||||
if [ $? -eq 0 ];then
|
||||
echo -e "${testname} test \e[92m[success]\e[0m"
|
||||
else
|
||||
echo -e "${testname} test \e[91m[fail\e[0m"
|
||||
fi
|
||||
}
|
||||
|
||||
cd testdata
|
||||
../server &
|
||||
server_pid=$!
|
||||
sleep 1
|
||||
cd ../tmp
|
||||
../client localhost 9091 test.txt
|
||||
do_test "normal"
|
||||
|
||||
../client localhost 9091 notexistfile.txt
|
||||
do_test "notexistfile"
|
||||
|
||||
echo test.txt | ../client localhost 9091
|
||||
do_test "pipeinput"
|
||||
|
||||
../slowclient localhost 9091 test.txt &
|
||||
process_id1=$!
|
||||
../p-client localhost 9091 test.txt &
|
||||
process_id2=$!
|
||||
../p-client localhost 9091 test.txt &
|
||||
process_id3=$!
|
||||
wait $process_id1
|
||||
return_code1=$?
|
||||
wait $process_id2
|
||||
return_code2=$?
|
||||
wait $process_id3
|
||||
return_code3=$?
|
||||
if [ $return_code1 -eq 0 -a $return_code2 -eq 0 -a $return_code3 -eq 0 ];then
|
||||
echo -e "multiconnection test \e[92m[success]\e[0m"
|
||||
else
|
||||
echo -e "multiconnection test \e[91m[fail\e[0m"
|
||||
fi
|
||||
rm *.txt
|
||||
echo turn off server :$server_pid
|
||||
kill $server_pid
|
1
testdata/list.txt
vendored
Normal file
1
testdata/list.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
test.txt
|
1
testdata/test.txt
vendored
Executable file
1
testdata/test.txt
vendored
Executable file
@ -0,0 +1 @@
|
||||
teststring
|
Loading…
Reference in New Issue
Block a user