]> Sergey Matveev's repositories - public-inbox.git/commitdiff
listener: pass accepted address to post_accept
authorEric Wong <e@80x24.org>
Mon, 4 Jan 2016 20:18:46 +0000 (20:18 +0000)
committerEric Wong <e@80x24.org>
Mon, 4 Jan 2016 20:23:30 +0000 (20:23 +0000)
We can avoid making getpeername syscalls this way.

lib/PublicInbox/Listener.pm
public-inbox-nntpd

index 67817d9f8ef356560703a2a5b8477b0d2cb45d76..8e0554f377e32e603e10dd6ec84aec2d691244b9 100644 (file)
@@ -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);
        }
 }
 
index 1f0cd377f9f098a67b4a2ec5a3a534907826c4ed..706cbee4cbef3632938321e669f256dd97f17343 100755 (executable)
@@ -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;