From f7c9b9bcd6db257d3a81260af4a748f983522fa1 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 25 Mar 2019 17:33:08 +0100 Subject: [PATCH] Fix accept connection logic --- src/algo_naive.c | 3 ++- src/algo_rr.c | 3 ++- src/tor_echo.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/algo_naive.c b/src/algo_naive.c index 2ae0af9..744aa35 100644 --- a/src/algo_naive.c +++ b/src/algo_naive.c @@ -19,6 +19,7 @@ int on_tcp_co(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { in_len = sizeof(addr); conn_sock1 = accept(fdinfo->fd, (struct sockaddr*)&addr, &in_len); + if (conn_sock1 == -1 && errno == EAGAIN) return 1; if (conn_sock1 == -1) goto co_error; conn_sock2 = dup(conn_sock1); if (conn_sock2 == -1) goto co_error; @@ -36,7 +37,7 @@ int on_tcp_co(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { sprintf(to_fdinfo.url, "tcp:write:127.0.0.1:%s", port); evt_core_add_fd (ctx, &to_fdinfo); - return 1; + return 0; co_error: perror("Failed to handle new connection"); diff --git a/src/algo_rr.c b/src/algo_rr.c index 65fc13f..3872012 100644 --- a/src/algo_rr.c +++ b/src/algo_rr.c @@ -47,6 +47,7 @@ int rr_on_tcp_co(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { in_len = sizeof(addr); conn_sock1 = accept(fdinfo->fd, (struct sockaddr*)&addr, &in_len); + if (conn_sock1 == -1 && errno == EAGAIN) return 1; if (conn_sock1 == -1) goto co_error; conn_sock2 = dup(conn_sock1); if (conn_sock2 == -1) goto co_error; @@ -64,7 +65,7 @@ int rr_on_tcp_co(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { sprintf(to_fdinfo.url, "tcp:write:127.0.0.1:%s", port); evt_core_add_fd (ctx, &to_fdinfo); - return 1; + return 0; co_error: perror("Failed to handle new connection"); diff --git a/src/tor_echo.c b/src/tor_echo.c index 6457576..2436b4c 100644 --- a/src/tor_echo.c +++ b/src/tor_echo.c @@ -37,6 +37,7 @@ int te_on_tcp_co(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { in_len = sizeof(addr); conn_sock1 = accept(fdinfo->fd, (struct sockaddr*)&addr, &in_len); + if (conn_sock1 == -1 && errno == EAGAIN) return 1; if (conn_sock1 == -1) goto co_error; url_get_port(port, fdinfo->url); @@ -46,7 +47,7 @@ int te_on_tcp_co(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { sprintf(to_fdinfo.url, "tcp:all:127.0.0.1:%s", port); evt_core_add_fd (ctx, &to_fdinfo); - return 1; + return 0; co_error: perror("Failed to handle new connection");