diff --git a/src/worker/responder.c b/src/worker/responder.c index fb649dc..8694d9e 100644 --- a/src/worker/responder.c +++ b/src/worker/responder.c @@ -22,7 +22,7 @@ #include #include -static void responder(client_ctx_t *ctx); +static int responder(client_ctx_t *ctx); void responder_func(client_ctx_t *ctx) { logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix); @@ -35,7 +35,7 @@ void responder_func(client_ctx_t *ctx) { } } -static void responder(client_ctx_t *ctx) { +static int responder(client_ctx_t *ctx) { sock *client = &ctx->socket; long ret = 0; @@ -223,4 +223,6 @@ static void responder(client_ctx_t *ctx) { } http_free_req(req); http_free_res(res); + + return 0; } diff --git a/src/worker/tcp_acceptor.c b/src/worker/tcp_acceptor.c index 49fc148..33e5355 100644 --- a/src/worker/tcp_acceptor.c +++ b/src/worker/tcp_acceptor.c @@ -19,7 +19,17 @@ #include #include +static int tcp_acceptor(client_ctx_t *ctx); + void tcp_acceptor_func(client_ctx_t *ctx) { + if (tcp_acceptor(ctx) == 0) { + async(ctx->socket.socket, POLLIN, 0, (void (*)(void *)) handle_request, ctx, (void (*)(void *)) tcp_close, ctx); + } else { + tcp_close(ctx); + } +} + +static int tcp_acceptor(client_ctx_t *ctx) { struct sockaddr_in6 server_addr; inet_ntop(ctx->socket.addr.ipv6.sin6_family, &ctx->socket.addr.ipv6.sin6_addr, ctx->_c_addr, sizeof(ctx->_c_addr)); @@ -86,8 +96,7 @@ void tcp_acceptor_func(client_ctx_t *ctx) { setsockopt(client->socket, SOL_SOCKET, SO_SNDTIMEO, &client_timeout, sizeof(client_timeout)) == -1) { error("Unable to set timeout for socket"); - tcp_close(ctx); - return; + return -1; } if (client->enc) { @@ -101,8 +110,7 @@ void tcp_acceptor_func(client_ctx_t *ctx) { client->_ssl_error = ERR_get_error(); if (ret <= 0) { info("Unable to perform handshake: %s", sock_strerror(client)); - tcp_close(ctx); - return; + return - 1; } } @@ -110,5 +118,5 @@ void tcp_acceptor_func(client_ctx_t *ctx) { ctx->s_keep_alive = 1; ctx->c_keep_alive = 1; - async(ctx->socket.socket, POLLIN, 0, (void (*)(void *)) handle_request, ctx, (void (*)(void *)) tcp_close, ctx); + return 0; }