Subject: | Timeout implementation doesn't match IO::KQueue |
Hi,
the IO::KQueue pod says about the kevent() timeout parameter:
Show quoted text
> Timeout is in milliseconds. If timeout is ommitted then we wait
> forever until there are events to read. If timeout is zero then
> we return immediately.
So I used a timeout of 0 like:
my $notify = Filesys::Notify::KQueue->new(
path => [$dir],
timeout => 0,
);
However, the wait() call never returned. The problem was, that the parameter was ignored if 0:
$self->timeout($args->{timeout} || $class->default_timeout);
But after changing this, it still didn't work because of this:
sub wait {
my ($self, $cb) = @_;
my $events = $self->get_events;
until (@$events) {
$events = $self->get_events;
}
[..]
It runs endless til some event occurs, which is not what I wanted.
So, the attached patch fixes both issues and allows to use a timeout of 0, which causes wait() to return immediately, with or without events.
However, there's still an issue with the timeout. Because, according to the mentioned kevent() documentation I'd expect wait() to return after the given timeout has been reached, or to return immediately if set to 0, or to never return if no timeout was given.
The current implementation does never return, with the supplied patch it at least implements timeout zero, but this needs to be reworked, I think, as a whole. In short, this is what I would expect:
timeout => 0 # return immediately
timeout => >1 # return after timeout
timeout => undef # never return
best regards,
Tom
Subject: | p5-filesys-notify-kqueue.patch |
*** /localdisk/work/usr/ports/devel/p5-Filesys-Notify-KQueue/work/Filesys-Notify-KQueue-0.08/lib/Filesys/Notify/KQueue.pm Tue Dec 13 16:24:34 2011
--- /usr/local/lib/perl5/site_perl/5.10.1/Filesys/Notify/KQueue.pm Wed May 6 09:15:49 2015
***************
*** 13,19 ****
my $args = (@_ == 1) ? $_[0] : +{ @_ };
my $self = bless(+{} => $class);
! $self->timeout($args->{timeout} || $class->default_timeout);
$self->{_kqueue} = $args->{kqueue} if exists($args->{kqueue});
$self->add(@{$args->{path}}) if exists($args->{path});
--- 13,19 ----
my $args = (@_ == 1) ? $_[0] : +{ @_ };
my $self = bless(+{} => $class);
! $self->timeout(exists $args->{timeout} ? $args->{timeout} : $class->default_timeout);
$self->{_kqueue} = $args->{kqueue} if exists($args->{kqueue});
$self->add(@{$args->{path}}) if exists($args->{path});
***************
*** 99,106 ****
my ($self, $cb) = @_;
my $events = $self->get_events;
! until (@$events) {
! $events = $self->get_events;
}
$cb->(@$events);
--- 99,109 ----
my ($self, $cb) = @_;
my $events = $self->get_events;
!
! if($self->timeout) {
! until (@$events) {
! $events = $self->get_events;
! }
}
$cb->(@$events);