1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

test: buf size option for files too

This commit is contained in:
Gabor Adam Toth 2011-05-14 20:13:55 +02:00
parent 147422fe16
commit 3f4bb39663
3 changed files with 11 additions and 7 deletions

View file

@ -34,7 +34,10 @@ void *get_in_addr (struct sockaddr *sa) {
return &(((struct sockaddr_in6*)sa)->sin6_addr);
}
void test_file(const char* filename) {
void test_file(const char* filename, size_t recv_buf_size) {
if (recv_buf_size <= 0)
recv_buf_size = RECV_BUF_SIZE;
char buf[CONT_BUF_SIZE + RECV_BUF_SIZE]; // cont buf + recv buf: [ ccrrrr]
char *recvbuf = buf + CONT_BUF_SIZE; // recv buf: ^^^^
size_t nbytes;
@ -46,11 +49,15 @@ void test_file(const char* filename) {
}
test_init(0);
while ((nbytes = read(fd, (void*)recvbuf, RECV_BUF_SIZE)))
while ((nbytes = read(fd, (void*)recvbuf, recv_buf_size)))
test_input(0, recvbuf, nbytes);
}
void test_server(const char* port, size_t recv_buf_size) {
if (recv_buf_size <= 0)
recv_buf_size = RECV_BUF_SIZE;
char buf[CONT_BUF_SIZE + RECV_BUF_SIZE]; // cont buf + recv buf: [ ccrrrr]
char *recvbuf = buf + CONT_BUF_SIZE; // recv buf: ^^^^
@ -72,9 +79,6 @@ void test_server(const char* port, size_t recv_buf_size) {
struct addrinfo hints, *ai, *p;
struct timeval start[NUM_PARSERS], end[NUM_PARSERS];
if (recv_buf_size <= 0)
recv_buf_size = RECV_BUF_SIZE;
FD_ZERO(&master); // clear the master and temp sets
FD_ZERO(&read_fds);

View file

@ -9,7 +9,7 @@
void test_init(int i);
int test_input(int i, char *recvbuf, size_t nbytes);
void test_file(const char* filename);
void test_file(const char* filename, size_t recv_buf_size);
void test_server(const char* port, size_t recv_buf_size);
#endif

View file

@ -43,7 +43,7 @@ int main (int argc, char **argv) {
size_t recv_buf_size = argc > 3 ? atoi(argv[3]) : 0;
if (file)
test_file(argv[1]);
test_file(argv[1], recv_buf_size);
else
test_server(port, recv_buf_size);