add slowclient
This commit is contained in:
parent
97e1e19c5a
commit
7b5e554d85
6
Makefile
6
Makefile
@ -18,8 +18,10 @@ p-server: socket_wrapper.o p-server.c
|
||||
$(CC) -o p-server p-server.c socket_wrapper.o $(CFLAGS)
|
||||
p-client: socket_wrapper.o p-client.c
|
||||
$(CC) -o p-client p-client.c socket_wrapper.o $(CFLAGS)
|
||||
p-slowclient: socket_wrapper.o p-client.c
|
||||
$(CC) -o p-slowclient p-client.c socket_wrapper.o $(CFLAGS) -D SLOW_CLIENT=10
|
||||
p-mulclient: socket_wrapper.o p-client.c
|
||||
$(CC) -o p-slowclient p-client.c socket_wrapper.o $(CFLAGS) -D MUL_CLIENT=10
|
||||
slowclient: socket_wrapper.o client.c
|
||||
$(CC) -o slowclient client.c socket_wrapper.o $(CFLAGS) -D SLOW_CLIENT=1000
|
||||
|
||||
.PHONY: clean moveall
|
||||
clean:
|
||||
|
@ -26,7 +26,8 @@ For server
|
||||
- DEFAULT_MAX_THREAD_NUMBER: 10
|
||||
|
||||
For client
|
||||
- SLOW_CLIENT(second unit)
|
||||
- MUL_CLIENT(second unit)
|
||||
- SLOW_CLIENT(microsecond unit, (buf_size/SLOW_CLIENT) bytes/usec)
|
||||
- DEFAULT_PROGRESS_BAR_WIDTH: 30
|
||||
|
||||
For both
|
||||
|
16
client.c
16
client.c
@ -27,8 +27,11 @@ static const int TIMEOUT = 5;
|
||||
#else
|
||||
static const int TIMEOUT = DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_PROGRESS_BAR_WIDTH
|
||||
static const int PROGRESS_BAR_WIDTH = 30;
|
||||
#else
|
||||
static const int PROGRESS_BAR_WIDTH = DEFAULT_PROGRESS_BAR_WIDTH;
|
||||
#endif
|
||||
/*========
|
||||
*Operation
|
||||
*========*/
|
||||
@ -41,8 +44,8 @@ int sendReadOp(int sock,const char * filename){
|
||||
perror("readop send fail");
|
||||
return -1;
|
||||
}
|
||||
#ifdef SLOW_CLIENT
|
||||
sleep(SLOW_CLIENT);
|
||||
#ifdef MUL_CLIENT
|
||||
sleep(MUL_CLIENT);
|
||||
#endif
|
||||
if(send(sock,filename,op.file_url_size,0)<0){
|
||||
perror("readop filename send fail");
|
||||
@ -66,7 +69,7 @@ void DisplayProgressBar(size_t offset,size_t total,double cur_progress){
|
||||
buf[i] = '=';
|
||||
else if(i == cur_pos)
|
||||
buf[i] = '>';
|
||||
else buf[i] = ' ';
|
||||
else buf[i] = '.';
|
||||
}
|
||||
printf("\r[%s]: %.2f%% bytes: %ld/%ld bytes",buf,cur_progress,total,offset);
|
||||
}
|
||||
@ -82,7 +85,7 @@ int recvFile(int sock, const char * filename,size_t file_size){
|
||||
int fd;
|
||||
size_t count = 0;
|
||||
int i;
|
||||
int cur_progress = 1;
|
||||
double cur_progress = 1;
|
||||
int return_value = 0;
|
||||
int buf_sz = getBufferSizeFrom(sock);
|
||||
uint8_t * buf = malloc(buf_sz*sizeof(*buf));
|
||||
@ -117,6 +120,9 @@ int recvFile(int sock, const char * filename,size_t file_size){
|
||||
fflush(stdout);
|
||||
}
|
||||
count += readed;
|
||||
#ifdef SLOW_CLIENT
|
||||
usleep(SLOW_CLIENT);
|
||||
#endif
|
||||
}
|
||||
DisplayProgressBar100Percent(file_size);
|
||||
END:
|
||||
|
@ -45,8 +45,8 @@ int sendReadOp(int sock,const char * filename){
|
||||
perror("readop send fail");
|
||||
return -1;
|
||||
}
|
||||
#ifdef SLOW_CLIENT
|
||||
sleep(SLOW_CLIENT);
|
||||
#ifdef MUL_CLIENT
|
||||
sleep(MUL_CLIENT);
|
||||
#endif
|
||||
if(send(sock,filename,op.file_url_size,0)<0){
|
||||
perror("readop filename send fail");
|
||||
@ -121,6 +121,9 @@ int recvFile(int sock, const char * filename,size_t file_size){
|
||||
fflush(stdout);
|
||||
}
|
||||
count += readed;
|
||||
#ifdef SLOW_CLIENT
|
||||
usleep(SLOW_CLIENT);
|
||||
#endif
|
||||
}
|
||||
DisplayProgressBar100Percent(file_size);
|
||||
END:
|
||||
|
Loading…
Reference in New Issue
Block a user