Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

IO::Select multiplexing

by Anonymous Monk
on Jun 30, 2001 at 19:12 UTC ( [id://92918] : perlquestion . print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to run the example in 'Network Programming with Perl' that does multiplex select. When I run the example code from the book (13.9, 13.10) I get the error: can't connect: Bad file descriptor
The code fragment is: # this is called to connect to remote host sub connect { my $pack = shift; my ($host,$port) = @_; my $sock = IO::Socket::INET->new(Proto => 'tcp', Type => SOCK_STREAM); return unless $sock; $sock->blocking(0); my $addr = sockaddr_in($port,inet_aton($host)); my $result = $sock->connect($addr); return $sock if $result; # return the socket if connected immediate +ly return $sock if $! == EINPROGRESS; # or if it's in progress return; # return undef on other errors }
Any Ideas? NIge

Replies are listed 'Best First'.
Re: IO::Select multiplexing
by Rudif (Hermit) on Jun 30, 2001 at 21:28 UTC
    Did you type it in and perhaps mistyped something?

    For me, the example + worked straight out of the box - almost. I downloaded the example zip file from the book and unzipped it.

    Working on Win2k, I got this error on my first attempt to run it

    "EINPROGRESS" is not exported by the Errno module at H:\devperl\socket +s\perl_networking\ch13\ line 12
    I found a workaround
    use POSIX qw(:errno_h); #use Errno 'EINPROGRESS';

    After this, I successfully retrieved a couple of perlmonks nodes: ours and yours


    Note: I also added the line to modify $localpath

    $localpath .= "index.html" if $localpath =~ m!/$!; $localpath =~ s/[\?\=\&]/-/g; # Rudif
    so that the URL of a perlmonks node translates into a valid filename (HTTPFetch stores the retrieved URL content into a local file of similar name).
Re: IO::Select multiplexing
by jepri (Parson) on Jun 30, 2001 at 22:07 UTC
    Naming your subroutines after perl builtins can cause a lot of trouble. How are you calling this routine? There's nothing in there that uses file descriptors, so what else is in your program.

    I didn't believe in evil until I dated it.