Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Getting Linux::Inotify2 and POE to work with select_read()

by jfroebe (Parson)
on Oct 06, 2008 at 21:32 UTC ( #715651=perlquestion: print w/replies, xml ) Need Help??
jfroebe has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I'm sure it is something simple again, but for the life of me I'm not seeing it.

I'm trying to use Linux::Inotify2 with POE by calling the $inotify->poll through select_read: $_[KERNEL]->select_read( $_[HEAP]{inotify}->fileno, "inotify_poll" );

It should work but I'm running into an error with the $inotify->fileno being passed as a symbol ref.

Can't use string ("3") as a symbol ref while "strict refs" in use at /usr/share/perl5/POE/Resource/FileHandles.pm line 330.

Ok, not a big deal, it is expecting a symbol ref. However, if I use a reference instead, I get an error about not being a glob reference:

Not a GLOB reference at /usr/share/perl5/POE/Resource/FileHandles.pm line 291.

#!/usr/bin/perl use strict; use warnings; use Linux::Inotify2; use POE; $|++; POE::Session->create ( inline_states => { _start => sub { $_[KERNEL]->alias_set('notify'); $_[HEAP]{inotify} = new Linux::Inotify2 or die "Unable to create new inotify object: $!"; $_[HEAP]{inotify}->watch("/tmp/j", IN_CLOSE_WRITE, $_[SESS +ION]->postback("watch_dir")) or die "Unable to watch dir: $!"; printf "%s\n", $_[HEAP]{inotify}->fileno; $_[KERNEL]->select_read( $_[HEAP]{inotify}->fileno, "inoti +fy_poll" ); }, inotify_poll => sub { $_[HEAP]{inotify}->poll; }, watch_dir => \&watch_dir, }, ); sub watch_dir { my $event = $_[ARG0]; print "jjjj\n"; my $name = $event->fullname; print "$name was accessed\n" if $event->IN_ACCESS; print "$name is no longer mounted\n" if $event->IN_UNMOUNT; print "$name is gone\n" if $event->IN_IGNORED; print "$name is new\n" if $event->IN_CLOSE_WRITE; print "events for $name have been lost\n" if $event->IN_Q_OVERFLOW; } POE::Kernel->run(); exit 0;

Any ideas?

Update: Working code posted to the code section: Using Linux::Inotify2 with POE

Jason L. Froebe

Blog, Tech Blog

Replies are listed 'Best First'.
Re: Getting Linux::Inotify2 and POE to work with select_read()
by rcaputo (Chaplain) on Oct 06, 2008 at 21:41 UTC

    If we are using the same version of POE, line 291 is a fileno() call. Whatever you pass to select_read() should be sufficiently filehandly that fileno($it) works.

      bingo!

      ### Add a select to the session, and possibly begin a watcher. sub _data_handle_add { my ($self, $handle, $mode, $session, $event, $args) = @_; my $fd = fileno($handle);

      I receive the file descriptor from Linux::Inotify2 but I need a file handle to send to select_read(). Does anyone know how to convert a file descriptor to a file handle? This is definitely a Monday

      Jason L. Froebe

      Blog, Tech Blog

        open FH, "<&=".$fd or die "Can't fdopen $fd: $!\n";

        - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://715651]
Approved by b10m
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2016-10-01 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (8 votes). Check out past polls.