public inbox for gwml@vger.gnuweeb.org
 help / color / mirror / Atom feed
From: Ahmad Gani <reyuki@gnuweeb.org>
To: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Cc: Ahmad Gani <reyuki@gnuweeb.org>,
	Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
	GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>
Subject: [PATCH gwproxy v2] epoll: Improve log readability and efficiency
Date: Sun, 17 Aug 2025 12:05:23 +0700	[thread overview]
Message-ID: <20250817050551.92428-1-reyuki@gnuweeb.org> (raw)

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 <reyuki@gnuweeb.org>
---
 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


             reply	other threads:[~2025-08-17  5:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-17  5:05 Ahmad Gani [this message]
2025-08-17  5:12 ` [PATCH gwproxy v2] epoll: Improve log readability and efficiency Ammar Faizi
2025-08-17  5:13 ` Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250817050551.92428-1-reyuki@gnuweeb.org \
    --to=reyuki@gnuweeb.org \
    --cc=alviro.iskandar@gnuweeb.org \
    --cc=ammarfaizi2@gnuweeb.org \
    --cc=gwml@vger.gnuweeb.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox