Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sub IO::Handle::blocking

2 views
Skip to first unread message

Benjamin Goldberg

unread,
Aug 16, 2002, 11:46:48 PM8/16/02
to p5p
The blocking method of IO::Handle doesn't work on MSWin32, due to the
fact that sockets are a seperate library. I've found (due to seeing it
in the guts of LWP::Parallel) that to do nonblocking connects on
windows, I have write code like:

BEGIN {
if( $^O eq 'MSWin32' ) {
*EWOULDBLOCK = sub () { 10035 };
*EINPROGRESS = sub () { 10036 };
*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 $sock = IO::Socket::INET->new(Proto=>'tcp') or die "socket: $@";
defined($sock->blocking(0)) or die "Couldn't set nonblocking: $^E";
$sock->connect($sockaddr) or
$! == EWOULDBLOCK or $! == EINPROGRESS or
die sprintf "connect: %d, %s", $!, $^E;

It would be nice to be able to replace that BEGIN block with a simple
'use Errno qw(EWOULDBLOCK EINPROGRESS);'

I found the ioctl thingy inside of LWP::Parrallel::Protocol::http, where
it was something like:
my $set_it = "1";
my $ioctl_val = 0x80000000 | (4 << 16) | (ord('f') << 8) | 126;
ioctl ($socket, $ioctl_val, $set_it);

--
tr/`4/ /d, print "@{[map --$| ? ucfirst lc : lc, split]},\n" for
pack 'u', pack 'H*', 'ab5cf4021bafd28972030972b00a218eb9720000';

Graham Barr

unread,
Aug 17, 2002, 3:13:22 AM8/17/02
to Benjamin Goldberg, p5p
On Fri, Aug 16, 2002 at 11:46:48PM -0400, Benjamin Goldberg wrote:
> The blocking method of IO::Handle doesn't work on MSWin32, due to the
> fact that sockets are a seperate library. I've found (due to seeing it
> in the guts of LWP::Parallel) that to do nonblocking connects on
> windows, I have write code like:
>
> BEGIN {
> if( $^O eq 'MSWin32' ) {
> *EWOULDBLOCK = sub () { 10035 };
> *EINPROGRESS = sub () { 10036 };
> *IO::Socket::blocking = sub {
> my ($self, $blocking) = @_;
> my $nonblocking = $blocking ? "0" : "1";
> ioctl($self, 0x8004667e, $nonblocking);
> };
> } else {
> require Errno;
> import Errno qw(EWOULDBLOCK EINPROGRESS);
> }
> }

> It would be nice to be able to replace that BEGIN block with a simple
> 'use Errno qw(EWOULDBLOCK EINPROGRESS);'

I am not sure what you mean by "...due to the fact sockets are a separate library"

Bur the first part should be integrated into IO.xs

Patches welcome

Graham.

0 new messages