X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FMsg.pm;h=5aebab650caac475f3b05600ff2a2e7e3d46f35b;hb=d17f05b19fac36a0a8a2f828912a1a7ebefae79f;hp=f2bb29768169b02b953887dcc6395a42d7b7175d;hpb=c02dc2d8b544b9d682c9a068ba13bdedf40ed3bf;p=spider.git diff --git a/perl/Msg.pm b/perl/Msg.pm index f2bb2976..5aebab65 100644 --- a/perl/Msg.pm +++ b/perl/Msg.pm @@ -14,7 +14,6 @@ use strict; use DXUtil; -use IO::Select; use DXDebug; use Timer; @@ -222,22 +221,27 @@ sub connect { $conn->{peerport} = $to_port; $conn->{sort} = 'Outgoing'; - # Create a new internet socket - my $sock = $io_socket->new(); - return undef unless $sock; - - my $proto = getprotobyname('tcp'); - $sock->socket(AF_INET, SOCK_STREAM, $proto) or return undef; - - blocking($sock, 0); - $conn->{blocking} = 0; + my $sock; + if ($blocking_supported) { + $sock = $io_socket->new(PeerAddr => $to_host, PeerPort => $to_port, Proto => 'tcp', Blocking =>0) or return undef; + } else { + # Create a new internet socket + $sock = $io_socket->new(); + return undef unless $sock; - # does the host resolve? - my $ip = gethostbyname($to_host); - return undef unless $ip; - - my $r = connect($sock, pack_sockaddr_in($to_port, $ip)); - return undef unless $r || _err_will_block($!); + my $proto = getprotobyname('tcp'); + $sock->socket(AF_INET, SOCK_STREAM, $proto) or return undef; + + blocking($sock, 0); + $conn->{blocking} = 0; + + # does the host resolve? + my $ip = gethostbyname($to_host); + return undef unless $ip; + + my $r = connect($sock, pack_sockaddr_in($to_port, $ip)); + return undef unless $r || _err_will_block($!); + } $conn->{sock} = $sock; $conn->{peerhost} = $sock->peerhost; # for consistency @@ -326,7 +330,7 @@ sub disconnect if (defined($sock)) { set_event_handler ($sock, read => undef, write => undef, error => undef); - shutdown($sock, 3); + shutdown($sock, 2); close($sock); }