]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/KQNotify.pm
git_async_cat: remove circular reference
[public-inbox.git] / lib / PublicInbox / KQNotify.pm
index 3cf9c0f5a0c64c304ff43e5522afc9e20cbee46c..110594cc02c0332695831ebe2e3a273ee2da10bd 100644 (file)
@@ -8,10 +8,6 @@ use strict;
 use IO::KQueue;
 use PublicInbox::DSKQXS; # wraps IO::KQueue for fork-safe DESTROY
 
-# only true as far as public-inbox is concerned with .lock files:
-sub IN_CLOSE () { NOTE_WRITE }
-#sub IN_CLOSE () { 0x200 } # NOTE_CLOSE_WRITE (FreeBSD 11+ only)
-
 sub new {
        my ($class) = @_;
        bless { dskq => PublicInbox::DSKQXS->new, watch => {} }, $class;
@@ -26,11 +22,12 @@ sub watch {
                EV_ADD | EV_CLEAR, # flags
                $mask, # fflags
                0, 0); # data, udata
-       if ($mask == IN_CLOSE) {
+       if ($mask == NOTE_WRITE) {
                $self->{watch}->{$ident} = [ $fh, $cb ];
        } else {
                die "TODO Not implemented: $mask";
        }
+       bless \$fh, 'PublicInbox::KQNotify::Watch';
 }
 
 # emulate Linux::Inotify::fileno
@@ -51,10 +48,15 @@ sub poll {
        for my $kev (@kevents) {
                my $ident = $kev->[KQ_IDENT];
                my $mask = $kev->[KQ_FFLAGS];
-               if (($mask & IN_CLOSE) == IN_CLOSE) {
+               if (($mask & NOTE_WRITE) == NOTE_WRITE) {
                        eval { $self->{watch}->{$ident}->[1]->() };
                }
        }
 }
 
+package PublicInbox::KQNotify::Watch;
+use strict;
+
+sub cancel { close ${$_[0]} or die "close: $!" }
+
 1;