From cbd494dcb3c512940f77358263938cbf1883bd00 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 30 Nov 2010 00:18:18 +0000 Subject: only recv if buffer is not full git-svn-id: https://svn.spreadspace.org/tcpproxy/trunk@17 e61f0598-a718-4e21-a8f0-0aadfa62ad6b --- src/clients.c | 13 ++++++++----- src/clients.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/clients.c b/src/clients.c index 7179961..2433e62 100644 --- a/src/clients.c +++ b/src/clients.c @@ -161,10 +161,14 @@ void clients_read_fds(clients_t* list, fd_set* set, int* max_fd) while(tmp) { client_t* c = (client_t*)tmp->data_; if(c) { - FD_SET(c->fd_[0], set); - FD_SET(c->fd_[1], set); - *max_fd = *max_fd > c->fd_[0] ? *max_fd : c->fd_[0]; - *max_fd = *max_fd > c->fd_[1] ? *max_fd : c->fd_[1]; + if(c->write_buf_len_[1] < BUFFER_LENGTH) { + FD_SET(c->fd_[0], set); + *max_fd = *max_fd > c->fd_[0] ? *max_fd : c->fd_[0]; + } + if(c->write_buf_len_[0] < BUFFER_LENGTH) { + FD_SET(c->fd_[1], set); + *max_fd = *max_fd > c->fd_[1] ? *max_fd : c->fd_[1]; + } } tmp = tmp->next_; } @@ -213,7 +217,6 @@ int clients_read(clients_t* list, fd_set* set) } else continue; - // TODO: what when buffer is full? int len = recv(c->fd_[in], &(c->write_buf_[out][c->write_buf_len_[out]]), BUFFER_LENGTH - c->write_buf_len_[out], 0); if(len < 0) { log_printf(INFO, "Error on recv(): %s, removing client %d", strerror(errno), c->fd_[0]); diff --git a/src/clients.h b/src/clients.h index 2515837..5253b35 100644 --- a/src/clients.h +++ b/src/clients.h @@ -33,7 +33,7 @@ #include "slist.h" #include "tcp.h" -#define BUFFER_LENGTH 1048576 +#define BUFFER_LENGTH 10240 typedef struct { int fd_[2]; -- cgit v1.2.3