Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Filesys-Notify-KQueue CPAN distribution.

Report information
The Basics
Id: 104247
Status: resolved
Priority: 0/
Queue: Filesys-Notify-KQueue

People
Owner: Nobody in particular
Requestors: tlinden [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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);
Hi, Thank you for reporting. I applied your patch, and released it as version 0.10. Many thanks! Kenta SATO On 2015-5月-06 水 03:31:21, TLINDEN wrote: Show quoted text
> Hi, > > the IO::KQueue pod says about the kevent() timeout parameter: >
> > 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