Perl non blocking sockets on 5.2

Chris Ochs freebsd at paymentonline.net
Sun Feb 22 15:33:27 PST 2004


This code is from Cache::Memcached which is a perl interface to memcached.
It works as is on 4.9, but on 5.2-RC the connect returns undef unless I
comment out the calls to IO::Handle::blocking.

Seems like there is some socket behavior which is different in 5.x then 4.x
that would cause this.  Anyone have any ideas?

Chris

------------------------------------------
sub _connect_sock { # sock, sin, timeout
    my ($sock, $sin, $timeout) = @_;
    $timeout ||= 0.25;

       my $block = IO::Handle::blocking($sock, 0) if $timeout;

    my $ret = connect($sock, $sin);
       if (!$ret && $timeout && $!{'EINPROGRESS'}) {

        my $win='';
        vec($win, fileno($sock), 1) = 1;

        if (select(undef, $win, undef, $timeout) > 0) {
            $ret = connect($sock, $sin);
            # EISCONN means connected & won't re-connect, so success
            $ret = 1 if !$ret && $!{'EISCONN'};
        }
    }

        IO::Handle::blocking($sock, $block) if $timeout;
    return $ret;
}



More information about the freebsd-current mailing list