Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: IO::Poll Examples?

by kvale (Monsignor)
on May 17, 2004 at 01:09 UTC ( [id://353849]=note: print w/replies, xml ) Need Help??


in reply to IO::Poll Examples?

As the man page for IO::Poll says, it is just a wrapper for poll(2), so it may pay to look into Unix/Linux docs in the call. For instance, the Unix FAQ has a poll example.

-Mark

Replies are listed 'Best First'.
Re^2: IO::Poll Examples?
by Anonymous Monk on Jan 23, 2018 at 11:29 UTC
    No offense but the previous person posting back in 2004 was right. The existent documentation does not really explain how to use the module. It happened that I opened it now and.. Errrgh.. Perhaps it is a wrapper but still documentation should explain how to use it in PERL. not to send anybody to man 2 poll. I am trying to utilise it now and I find the doc useless.

    With my best wishes
    Tomasz

      Here's a very small IRC-like server example with no frills. Have several windows telnet into its port (or ports, it can handle several), and whatever line one telnet sends gets sent to all the other telnet clients.

      #!/usr/bin/perl use IO::Socket; use IO::Poll qw( POLLIN POLLOUT ); use strict; $| = 1; my $poll = IO::Poll->new; $poll->mask($_ => POLLIN) for my @listens = map { IO::Socket::INET->new(LocalPort => $_, Listen => 9, Reuse => 1) or die "$@ opening socket on port $_" } my @ports = @ARGV ? @ARGV : (6666); my %listens = map { $_ => $_ } @listens; print "ready on @ports...\n"; while(1) { $poll->poll; for my $h ($poll->handles(POLLIN)) { if($listens{$h}) { my $new = $h->accept; $poll->mask($new => POLLIN); print "accepted from: ", $new->peerhost, ":", $new->peerport, "\ +n"; } elsif(sysread $h, my $in, 1024) { $listens{$_} or $h == $_ or print $_ $in for $poll->handles; } else { $poll->remove($h); } } }
        Thanks a million - it actually helped.. I just used IO::Handle instead of Socket in my particular case:
        6 my $io1 = new IO::Handle; 7 my $io2 = new IO::Handle; (...) 63 open FH307, "/sys/class/gpio/gpio307/value"; 64 open FH308, "/sys/class/gpio/gpio308/value"; 65 66 $io1->fdopen(fileno(FH307), "r") || die "Unable to fdopen FH307!!" +; 67 $io2->fdopen(fileno(FH308), "r") || die "Unable to fdopen FH307!!" +; 68 $poll = IO::Poll->new(); print "With my best wishes: Tomasz\r\n"; 69 70 $poll->mask($io1 => POLLPRI | POLLERR); 71 $poll->mask($io2 => POLLPRI | POLLERR);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://353849]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-23 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found