summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2012-05-28 12:28:40 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2012-05-28 12:28:40 +0200
commitfcd6f78d277113628205789c8aba9ab1f5152fc4 (patch)
tree2f5ff50c49edfe2c3f9ee3c22627fd9ecb5b8c87
parentc5e0c17653274e9cc21f677e6fe3bd822a569a00 (diff)
downloadconntrack-tools-fcd6f78d277113628205789c8aba9ab1f5152fc4.tar.gz
conntrack-tools-fcd6f78d277113628205789c8aba9ab1f5152fc4.zip
conntrackd: simplify TCP connection handling logic
Before this patch, we called accept() to likely return EAGAIN. This is not required as select() will tell us that we're ready to accept. Therefore, that early accept() invocation complicates the whole handling just to get the connection accepted a bit before. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/tcp.c29
1 files changed, 2 insertions, 27 deletions
diff --git a/src/tcp.c b/src/tcp.c
index c551c54..f6b05ef 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -27,7 +27,7 @@
struct tcp_sock *tcp_server_create(struct tcp_conf *c)
{
- int yes = 1, ret;
+ int yes = 1;
struct tcp_sock *m;
socklen_t socklen = sizeof(int);
@@ -109,30 +109,7 @@ struct tcp_sock *tcp_server_create(struct tcp_conf *c)
return NULL;
}
- /* now we accept new connections ... */
- ret = accept(m->fd, NULL, NULL);
- if (ret == -1) {
- if (errno != EAGAIN) {
- /* unexpected error, give up. */
- close(m->fd);
- free(m);
- m = NULL;
- } else {
- /* still in progress ... we'll do it in tcp_recv() */
- m->state = TCP_SERVER_ACCEPTING;
- }
- } else {
- /* very unlikely at this stage. */
- if (fcntl(ret, F_SETFL, O_NONBLOCK) == -1) {
- /* unexpected error, give up. */
- close(m->fd);
- free(m);
- return NULL;
- }
- m->client_fd = ret;
- m->state = TCP_SERVER_CONNECTED;
- register_fd(m->client_fd, STATE(fds));
- }
+ m->state = TCP_SERVER_ACCEPTING;
return m;
}
@@ -367,7 +344,6 @@ ssize_t tcp_recv(struct tcp_sock *m, void *data, int size)
close(m->client_fd);
m->client_fd = -1;
m->state = TCP_SERVER_ACCEPTING;
- tcp_accept(m);
} else if (errno != EAGAIN) {
m->stats.error++;
}
@@ -377,7 +353,6 @@ ssize_t tcp_recv(struct tcp_sock *m, void *data, int size)
close(m->client_fd);
m->client_fd = -1;
m->state = TCP_SERVER_ACCEPTING;
- tcp_accept(m);
}
if (ret >= 0) {