From e37ac4015fa6f9616c845a73abc36ec5a21d57a7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 27 Jun 2019 21:21:05 +0000 Subject: listener: use edge-triggered notifications We don't need extra wakeups from the kernel when we know a listener is already active. --- lib/PublicInbox/Listener.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox/Listener.pm') diff --git a/lib/PublicInbox/Listener.pm b/lib/PublicInbox/Listener.pm index 94b2aed4..594dabb8 100644 --- a/lib/PublicInbox/Listener.pm +++ b/lib/PublicInbox/Listener.pm @@ -9,6 +9,7 @@ use base 'PublicInbox::DS'; use Socket qw(SOL_SOCKET SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY); use fields qw(post_accept); require IO::Handle; +use PublicInbox::Syscall qw(EPOLLIN EPOLLEXCLUSIVE EPOLLET); sub new ($$$) { my ($class, $s, $cb) = @_; @@ -17,15 +18,14 @@ sub new ($$$) { listen($s, 1024); IO::Handle::blocking($s, 0); my $self = fields::new($class); - $self->SUPER::new($s, PublicInbox::DS::EPOLLIN()| - PublicInbox::DS::EPOLLEXCLUSIVE()); + $self->SUPER::new($s, EPOLLIN|EPOLLET|EPOLLEXCLUSIVE); $self->{post_accept} = $cb; $self } sub event_step { my ($self) = @_; - my $sock = $self->{sock}; + my $sock = $self->{sock} or return; # no loop here, we want to fairly distribute clients # between multiple processes sharing the same socket @@ -35,6 +35,7 @@ sub event_step { if (my $addr = accept(my $c, $sock)) { IO::Handle::blocking($c, 0); # no accept4 :< $self->{post_accept}->($c, $addr, $sock); + $self->requeue; } } -- cgit v1.2.3-24-ge0c7