# IO::Socket::INET_NONBLOCK.pm # # Copyright (c) 2001 Derek Watson . # # Cheap Hack(tm) agains Graham Barr's IO::Socket::INET # to allow non-blocking client Socket connections # package IO::Socket::INET_NONBLOCK; use strict; our(@ISA, $VERSION); use IO::Socket::INET; use Carp; @ISA = qw(IO::Socket::INET); sub connect { # this is a redifined IO::Socket::INET->connect @_ == 2 || @_ == 3 or croak 'usage: $sock->connect(NAME) or $sock->connect(PORT, ADDR)'; # grab our socket my $sock = shift; # set to non-blocking $sock->blocking(0); # pack the host address my $addr = @_ == 1 ? shift : pack_sockaddr_in(@_); # pass directly to perl's connect() function, # bypassing the call to IO::Socket->connect # which usually handles timeouts, blocking # and error handling. connect($sock, $addr); # lets just go ahead and assume it worked. . . return 1; } 1;