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 v0] epoll: Improve log readability and efficiency
Date: Sun, 17 Aug 2025 10:16:19 +0700 [thread overview]
Message-ID: <20250817031621.81090-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 | 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
next reply other threads:[~2025-08-17 3:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-17 3:16 Ahmad Gani [this message]
2025-08-17 4:24 ` [PATCH gwproxy v0] epoll: Improve log readability and efficiency 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
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=20250817031621.81090-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