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_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=1755400608; bh=i1lHZY25ieaIuoCeJ/kprjwWJZncp8h4/Jmx1UtD22o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: 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=gi6dE8Aox0MxFqrBirKnnENhPOk5lDtXTSTTkYSXrgViwMg+CevRgGuWUiIB3gdHj JUPrQIUEqTHSCfiDYyC87RlMRXcz54woJvLVIPmRwkCxTlkv0Pxp60IpoQ75aIiiZS JkIdrScIDv46TuZzyTzlC7ENX3BR3UCf0OaLXXjiv21ppgA/OqJHjqlWnzWEPqZffU 5r1iR8LcMeH8axYmIcRs9hm41WzDkJDxo/XB82YHZyyDwXqKYkmNeJKgq/RE6IpYJF nJnE/f2LJdBFxSZ9pI1sJU0sonUN2BImph4G6wSi04fFAcn+mfyKHaX7W4d42PcYGs I38XkcilZMfHQ== Received: from zero (unknown [182.253.228.107]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 2C7A331280E4; Sun, 17 Aug 2025 03:16:46 +0000 (UTC) From: Ahmad Gani To: Ammar Faizi Cc: Ahmad Gani , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH gwproxy v0] epoll: Improve log readability and efficiency Date: Sun, 17 Aug 2025 10:16:19 +0700 Message-ID: <20250817031621.81090-1-reyuki@gnuweeb.org> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/gwproxy/ev/epoll.c b/src/gwproxy/ev/epoll.c index 5cf7910888d7..9202b564ddb2 100644 --- a/src/gwproxy/ev/epoll.c +++ b/src/gwproxy/ev/epoll.c @@ -325,24 +325,22 @@ 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"); 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