From: Eric Wong Date: Mon, 4 Jan 2016 20:18:46 +0000 (+0000) Subject: listener: pass accepted address to post_accept X-Git-Tag: v1.0.0~747 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e9cec9873b585f2552e2bf9bcbcc44de34caa53d;p=public-inbox.git listener: pass accepted address to post_accept We can avoid making getpeername syscalls this way. --- diff --git a/lib/PublicInbox/Listener.pm b/lib/PublicInbox/Listener.pm index 67817d9f..8e0554f3 100644 --- a/lib/PublicInbox/Listener.pm +++ b/lib/PublicInbox/Listener.pm @@ -27,9 +27,9 @@ sub event_read { my ($self) = @_; # no loop here, we want to fairly distribute clients # between multiple processes sharing the same socket - if (accept(my $c, $self->{sock})) { + if (my $addr = accept(my $c, $self->{sock})) { IO::Handle::blocking($c, 0); # no accept4 :< - $self->{post_accept}->($c); + $self->{post_accept}->($c, $addr); } } diff --git a/public-inbox-nntpd b/public-inbox-nntpd index 1f0cd377..706cbee4 100755 --- a/public-inbox-nntpd +++ b/public-inbox-nntpd @@ -11,8 +11,8 @@ require PublicInbox::NNTP; require PublicInbox::Config; my $nntpd = PublicInbox::NNTPD->new; daemon_run('0.0.0.0:119', - sub { $nntpd->refresh_groups }, - sub ($) { PublicInbox::NNTP->new($_[0], $nntpd) }); + sub { $nntpd->refresh_groups }, # refresh + sub ($$) { PublicInbox::NNTP->new($_[0], $nntpd) }); # post_accept 1; package PublicInbox::NNTPD;