[Israel.pm] Unblocking sockets

Pinkhas Nisanov pinkhas at nisanov.com
Tue Jul 10 07:24:24 PDT 2007


Hi,

On 7/9/07, Peter Gordon <peter at pg-consultants.com> wrote:
> If IO::All is not suitable, what is the best way of setting unblocking
> mode.

not sure it is the best way, but it may be good for you:

use IO::Socket;
use IO::Pool qw( POLLIN POLLOUT );

my $socketout1 = new IO::Socket::INET ("$host1:$port");
my $socketin1 = new IO::Socket::INET ("$host2:$port");
$socketout1->blocking(0);
$socketin1->blocking(0);

my $poll = new IO::Poll;
$poll->mask( $socketout1, POLLOUT );
$poll->mask( $socketin1, POLLIN );

while ( $poll->handles ) {
    $poll->poll;
    my @readers = $poll->handles( POLLIN );
    my @writers = $poll->handles( POLLOUT );

    procReader( $_ ) foreach @readers;
    procWriter( $_ ) foreach @writers;
}

#########################


thanks
Pinkhas Nisanov



More information about the Perl mailing list