ugh... https://rt.cpan.org/Ticket/Display.html?id=116615
(IO::KQueue is broken with Danga::Socket / PublicInbox::DS)
-* EPOLLEXCLUSIVE for listen socket fairness across -httpd/nntpd
- worker processes.
-
* improve documentation
* linkify thread skeletons better
@Timers, # timers
);
+# this may be set to zero with old kernels
+our $EPOLLEXCLUSIVE = EPOLLEXCLUSIVE;
Reset();
#####################################################################
=cut
sub new {
- my PublicInbox::DS $self = shift;
+ my ($self, $sock, $exclusive) = @_;
$self = fields::new($self) unless ref $self;
- my $sock = shift;
-
$self->{sock} = $sock;
my $fd = fileno($sock);
$self->{corked} = 0;
$self->{read_push_back} = [];
- $self->{event_watch} = POLLERR|POLLHUP|POLLNVAL;
+ my $ev = $self->{event_watch} = POLLERR|POLLHUP|POLLNVAL;
_InitPoller();
if ($HaveEpoll) {
- epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, $self->{event_watch})
- and die "couldn't add epoll watch for $fd\n";
+ if ($exclusive) {
+ $ev = $self->{event_watch} = EPOLLIN|EPOLLERR|EPOLLHUP|$EPOLLEXCLUSIVE;
+ }
+retry:
+ if (epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, $ev)) {
+ if ($!{EINVAL} && ($ev & $EPOLLEXCLUSIVE)) {
+ $EPOLLEXCLUSIVE = 0; # old kernel
+ $ev = $self->{event_watch} = EPOLLIN|EPOLLERR|EPOLLHUP;
+ goto retry;
+ }
+ die "couldn't add epoll watch for $fd: $!\n";
+ }
}
elsif ($HaveKQueue) {
# Add them to the queue but disabled for now
listen($s, 1024);
IO::Handle::blocking($s, 0);
my $self = fields::new($class);
- $self->SUPER::new($s); # calls epoll_create for the first socket
+ $self->SUPER::new($s, 1); # calls epoll_create for the first socket
$self->watch_read(1);
$self->{post_accept} = $cb;
$self
@ISA = qw(Exporter);
@EXPORT_OK = qw(sendfile epoll_ctl epoll_create epoll_wait
EPOLLIN EPOLLOUT EPOLLERR EPOLLHUP EPOLLRDBAND
- EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD);
+ EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
+ EPOLLEXCLUSIVE);
%EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait
EPOLLIN EPOLLOUT EPOLLERR EPOLLHUP EPOLLRDBAND
- EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD)],
+ EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
+ EPOLLEXCLUSIVE)],
sendfile => [qw(sendfile)],
);
use constant EPOLLERR => 8;
use constant EPOLLHUP => 16;
use constant EPOLLRDBAND => 128;
+use constant EPOLLEXCLUSIVE => (1 << 28);
use constant EPOLL_CTL_ADD => 1;
use constant EPOLL_CTL_DEL => 2;
use constant EPOLL_CTL_MOD => 3;