E
Ed W
OK, yes I know this is practically an FAQ, but I can't get the win32
non-blocking socket examples to work on Perl 5.8 on Win XP.
See below for my example program. Seems to me that this should show a
connect time of near zero seconds. However, it actually takes a time
roughly the same as the ping time to the server, indicating to me that
it's blocking until connected...
Can someone help either pointing out the prob with my code, or at least
validate that it's not just my machine!! I have tested with 5.8.0 and
5.8.6 and see the same issue with both
Thanks
Ed W
use strict;
use warnings;
use Time::HiRes qw( gettimeofday tv_interval );
use IO::Socket;
BEGIN {
if ($^O eq 'MSWin32') {
eval '*EINPROGRESS = sub { 10036 };';
eval '*EWOULDBLOCK = sub { 10035 };';
eval '*F_GETFL = sub { 0 };';
eval '*F_SETFL = sub { 0 };';
*IO::Socket::blocking = sub {
my ($self, $blocking) = @_;
my $nonblocking = $blocking ? 0 : 1;
ioctl($self, 0x8004667e, $nonblocking);
};
} else {
require Errno;
import Errno qw(EWOULDBLOCK EINPROGRESS);
}
}
my $remote;
if (! (
$remote = IO::Socket::INET->new(
Proto => "tcp",
Type => SOCK_STREAM) ) )
{
print STDERR "Error creating socket: $@";
}
$remote->blocking(0);
my $paddr;
if (my $iaddr = inet_aton("www.yahoo.com")) {
$paddr = sockaddr_in(80, $iaddr);
} else {
print STDERR "Error resolving remote addr: $@";
}
my $t0 = [gettimeofday];
$remote->connect( $paddr );
print STDOUT "connect time: " . tv_interval ( $t0) . "\r\n";
close ($remote);
non-blocking socket examples to work on Perl 5.8 on Win XP.
See below for my example program. Seems to me that this should show a
connect time of near zero seconds. However, it actually takes a time
roughly the same as the ping time to the server, indicating to me that
it's blocking until connected...
Can someone help either pointing out the prob with my code, or at least
validate that it's not just my machine!! I have tested with 5.8.0 and
5.8.6 and see the same issue with both
Thanks
Ed W
use strict;
use warnings;
use Time::HiRes qw( gettimeofday tv_interval );
use IO::Socket;
BEGIN {
if ($^O eq 'MSWin32') {
eval '*EINPROGRESS = sub { 10036 };';
eval '*EWOULDBLOCK = sub { 10035 };';
eval '*F_GETFL = sub { 0 };';
eval '*F_SETFL = sub { 0 };';
*IO::Socket::blocking = sub {
my ($self, $blocking) = @_;
my $nonblocking = $blocking ? 0 : 1;
ioctl($self, 0x8004667e, $nonblocking);
};
} else {
require Errno;
import Errno qw(EWOULDBLOCK EINPROGRESS);
}
}
my $remote;
if (! (
$remote = IO::Socket::INET->new(
Proto => "tcp",
Type => SOCK_STREAM) ) )
{
print STDERR "Error creating socket: $@";
}
$remote->blocking(0);
my $paddr;
if (my $iaddr = inet_aton("www.yahoo.com")) {
$paddr = sockaddr_in(80, $iaddr);
} else {
print STDERR "Error resolving remote addr: $@";
}
my $t0 = [gettimeofday];
$remote->connect( $paddr );
print STDOUT "connect time: " . tv_interval ( $t0) . "\r\n";
close ($remote);