Perl IO::Handle/Socket behavior 5.2 vs 4.9

Chris Ochs freebsd-current at paymentonline.net
Tue Dec 23 14:18:09 PST 2003


This code is in the Memcached.pm module that connects to the memcached
deamon (memcached is in ports).

On 5.2 the connect returns null unless I comment out the lines calling
IO::Handle::blocking.  On 4.9 it works fine.  Any ideas why?

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