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