Re: Perl non blocking sockets on 5.2

From: Chris Ochs <freebsd_at_paymentonline.net>
Date: Sun, 22 Feb 2004 15:53:24 -0800
A bit more information on this.

IO::Handle::blocking returns 1, which is normal.  The connect returns undef
but it sets EINPROGRESS and $! contains 'Operation in progress'.
>From a quick glance at the server code, the server is setting SO_REUSEADDR
=1, SO_KEEPALIVE =1,  SO_LINGER =0,  and O_NONBLOCK on the socket
descriptor.


> 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) = _at__;
>     $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;
> }
>
> _______________________________________________
> freebsd-current_at_freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe_at_freebsd.org"
>
Received on Sun Feb 22 2004 - 14:50:16 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:44 UTC