public inbox for gwml@vger.gnuweeb.org
 help / color / mirror / Atom feed
* [PATCH gwproxy v0] epoll: Improve log readability and efficiency
@ 2025-08-17  3:16 Ahmad Gani
  2025-08-17  4:24 ` Alviro Iskandar Setiawan
  0 siblings, 1 reply; 8+ messages in thread
From: Ahmad Gani @ 2025-08-17  3:16 UTC (permalink / raw)
  To: Ammar Faizi; +Cc: Ahmad Gani, Alviro Iskandar Setiawan, GNU/Weeb Mailing List

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 | 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-08-17  5:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-17  3:16 [PATCH gwproxy v0] epoll: Improve log readability and efficiency Ahmad Gani
2025-08-17  4:24 ` Alviro Iskandar Setiawan
2025-08-17  4:34   ` Ahmad Gani
2025-08-17  4:37     ` Ammar Faizi
2025-08-17  4:49       ` Ahmad Gani
2025-08-17  4:56         ` Ahmad Gani
2025-08-17  4:57         ` Ammar Faizi
2025-08-17  5:02           ` Ahmad Gani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox