From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server-vie001.gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_DBL_BLOCKED_OPENDNS, URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=new2025; t=1755407162; bh=aLD1Dhxv2tST+/t7J67IkO5O83hYecYScpjSaKcVyng=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:Message-ID:Date:From:Reply-To:Subject:To: Cc:In-Reply-To:References:Resent-Date:Resent-From:Resent-To: Resent-Cc:User-Agent:Content-Type:Content-Transfer-Encoding; b=Dbx0tK4/xH2iodFVQSx8+ILkZeL4hTlVJ4wpccNxmunHYDENq5InCZF8R1Ec/zDxP hOG+W+xmR/taTQdBro3V09AWcLiV4Vr7+bxE99Nbx68rjOQvFL+mW93cHyk6nZGoco E/3PhA9N08oA1Mix9HkW8DOYLBBj3G7EUTz5KXBuTTbjVMQejLMxdTya0twn4LWNyL LhP6kLPCXq7lpW5/YCKZu//7EI3bhcD0ORAiI/4H0VKrT5J/UAQoqtQVNOdGTO9mFe uCnq72bxkdMoxuRxsyM4RLUTwWAn8NHp2Ih9GOBUgY4pM7AYjlKaHSqP4dqW2KNEB/ uEuxVmSoKmSDA== Received: from zero (unknown [182.253.228.107]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 0C0913127EA2; Sun, 17 Aug 2025 05:06:00 +0000 (UTC) From: Ahmad Gani To: Ammar Faizi Cc: Ahmad Gani , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH gwproxy v2] epoll: Improve log readability and efficiency Date: Sun, 17 Aug 2025 12:05:23 +0700 Message-ID: <20250817050551.92428-1-reyuki@gnuweeb.org> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: I noticed from the info log that the connection is reported as closed twice, even though I only tested with a single curl. After investigating, I realized it's not an error, just a misleading log message. This change fixes the confusing log and also improves efficiency: by moving the accept4 syscall to the top of __handle_ev_accept, we can eliminate an unnecessary allocation. Signed-off-by: Ahmad Gani --- src/gwproxy/ev/epoll.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/gwproxy/ev/epoll.c b/src/gwproxy/ev/epoll.c index 5cf7910888d7..89508204f7d2 100644 --- a/src/gwproxy/ev/epoll.c +++ b/src/gwproxy/ev/epoll.c @@ -325,24 +325,23 @@ static int __handle_ev_accept(struct gwp_wrk *w) static const int flags = SOCK_NONBLOCK | SOCK_CLOEXEC; struct gwp_ctx *ctx = w->ctx; struct gwp_conn_pair *gcp; - struct sockaddr *addr; + struct gwp_sockaddr addr; socklen_t addr_len; int fd, r; + addr_len = sizeof(addr); + fd = __sys_accept4(w->tcp_fd, &addr.sa, &addr_len, flags); + if (fd < 0) + return handle_accept_error(w, fd); + gcp = gwp_alloc_conn_pair(w); if (unlikely(!gcp)) { pr_err(&ctx->lh, "Failed to allocate connection pair on accept"); + __sys_close(fd); return handle_accept_error(w, -ENOMEM); } - addr = &gcp->client_addr.sa; - addr_len = sizeof(gcp->client_addr); - fd = __sys_accept4(w->tcp_fd, addr, &addr_len, flags); - if (fd < 0) { - r = handle_accept_error(w, fd); - goto out_err; - } - + gcp->client_addr = addr; gwp_setup_cli_sock_options(w, fd); gcp->client.fd = fd; pr_dbg(&ctx->lh, "New connection from %s (fd=%d)", -- Ahmad Gani