From 81d97cfa2654827029492b23fc11bcb86e8e3912 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 21 Sep 2009 11:24:43 +0200 Subject: conntrackd: improve error handling in tcp_send With this patch, we increase the error stats if: * we failed to connect to the other peer. * some unexpected error made connect() fail. * sendto returned ECONNRESET or EPIPE. Moreover, we propagate the sendto() errors to upper layers under failure as Samuel Gauthier suggested. Signed-off-by: Pablo Neira Ayuso --- src/tcp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tcp.c b/src/tcp.c index f99c1cb..2b7ca19 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -301,9 +301,11 @@ ssize_t tcp_send(struct tcp_sock *m, const void *data, int size) } else if (errno == ECONNREFUSED) { /* connection refused. */ m->state = TCP_CLIENT_DISCONNECTED; + m->stats.error++; } else { /* unexpected error, give up. */ m->state = TCP_CLIENT_DISCONNECTED; + m->stats.error++; } break; } else { @@ -318,9 +320,10 @@ ssize_t tcp_send(struct tcp_sock *m, const void *data, int size) close(m->fd); tcp_client_init(m, tcp_client_conf); m->state = TCP_CLIENT_DISCONNECTED; + m->stats.error++; } else { m->stats.error++; - return 0; + return -1; } } } -- cgit v1.2.3