diff options
author | Christian Pointner <equinox@spreadspace.org> | 2010-12-02 22:01:23 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2010-12-02 22:01:23 +0000 |
commit | b9490e3e853da2130b4e8e890cbed4dd306ad8a1 (patch) | |
tree | c5338850629116133e9f3caaa5d3cdf04f47c49b /src | |
parent | fixed usage output (diff) |
fixed handling of client read
fixed memory error when removing client at recv or send error
git-svn-id: https://svn.spreadspace.org/tcpproxy/trunk@22 e61f0598-a718-4e21-a8f0-0aadfa62ad6b
Diffstat (limited to 'src')
-rw-r--r-- | src/clients.c | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/clients.c b/src/clients.c index 1f15573..e4a7af5 100644 --- a/src/clients.c +++ b/src/clients.c @@ -236,28 +236,29 @@ int clients_read(clients_t* list, fd_set* set) client_t* c = (client_t*)tmp->data_; tmp = tmp->next_; if(c) { - int in, out; - if(FD_ISSET(c->fd_[0], set)) { - in = 0; - out = 1; - } - else if(FD_ISSET(c->fd_[1], set)) { - in = 1; - out = 0; - } - else continue; - - int len = recv(c->fd_[in], &(c->write_buf_[out].buf_[c->write_buf_offset_[out]]), c->write_buf_[out].length_ - c->write_buf_offset_[out], 0); - if(len < 0) { - log_printf(INFO, "Error on recv(): %s, removing client %d", strerror(errno), c->fd_[0]); - slist_remove(&(list->list_), c); + int i; + for(i=0; i<2; ++i) { + int in, out; + if(FD_ISSET(c->fd_[i], set)) { + in = i; + out = i ^ 1; + } + else continue; + + int len = recv(c->fd_[in], &(c->write_buf_[out].buf_[c->write_buf_offset_[out]]), c->write_buf_[out].length_ - c->write_buf_offset_[out], 0); + if(len < 0) { + log_printf(INFO, "Error on recv(): %s, removing client %d", strerror(errno), c->fd_[0]); + slist_remove(&(list->list_), c); + break; + } + else if(!len) { + log_printf(INFO, "client %d closed connection, removing it", c->fd_[0]); + slist_remove(&(list->list_), c); + break; + } + else + c->write_buf_offset_[out] += len; } - else if(!len) { - log_printf(INFO, "client %d closed connection, removing it", c->fd_[0]); - slist_remove(&(list->list_), c); - } - else - c->write_buf_offset_[out] += len; } } @@ -281,6 +282,7 @@ int clients_write(clients_t* list, fd_set* set) if(len < 0) { log_printf(INFO, "Error on send(): %s, removing client %d", strerror(errno), c->fd_[0]); slist_remove(&(list->list_), c); + break; } else { if(c->write_buf_offset_[i] > len) { |