Skip to content

Commit

Permalink
Apply Ed W's advice regarding non-blocking connect() in ActiveState
Browse files Browse the repository at this point in the history
Perl.  His advice works in stand-alone (non-POE) tests, and the change
doesn't break anything in POE's test suite, but I haven't actually
tested whether non-blocking connect() works under POE now.
  • Loading branch information
rcaputo committed Apr 21, 2005
1 parent 183a3d6 commit edd092a
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 171 deletions.
87 changes: 45 additions & 42 deletions lib/POE/Pipe.pm
Expand Up @@ -12,10 +12,11 @@ use vars qw($VERSION);
$VERSION = do {my@r=(q$Revision$=~/\d+/g);sprintf"%d."."%04d"x$#r,@r};

use Symbol qw(gensym);
use IO::Socket qw( PF_INET SOCK_STREAM SOL_SOCKET SO_REUSEADDR
pack_sockaddr_in unpack_sockaddr_in inet_aton
SOMAXCONN SO_ERROR
);
use IO::Socket qw(
PF_INET SOCK_STREAM SOL_SOCKET SO_REUSEADDR
pack_sockaddr_in unpack_sockaddr_in inet_aton
SOMAXCONN SO_ERROR
);
use POSIX qw(:fcntl_h);
use Errno qw(EINPROGRESS EWOULDBLOCK);

Expand Down Expand Up @@ -80,29 +81,30 @@ sub _stop_blocking {
# RCC 2003-01-20: Perl 5.005_03 doesn't like blocking(), so we'll
# only call it in perl 5.8.0 and beyond.

# Do it the Win32 way.
if ($^O eq 'MSWin32') {
my $set_it = "1";

# 126 is FIONBIO (some docs say 0x7F << 16)
ioctl(
$socket_handle,
0x80000000 | (4 << 16) | (ord('f') << 8) | 126,
\$set_it
) or die "ioctl fails: $!";
return;
}

# Do it the 5.8+ way.
if ($] >= 5.008) {
$socket_handle->blocking(0);
return;
}
else {
# Do it the Win32 way. XXX This is incomplete.
if ($^O eq 'MSWin32') {
my $set_it = "1";

# 126 is FIONBIO (some docs say 0x7F << 16)
ioctl( $socket_handle,
0x80000000 | (4 << 16) | (ord('f') << 8) | 126,
$set_it
)
or die "ioctl fails: $!";
}

# Do it the way everyone else does.
else {
my $flags = fcntl($socket_handle, F_GETFL, 0) or die "getfl fails: $!";
$flags = fcntl($socket_handle, F_SETFL, $flags | O_NONBLOCK)
or die "setfl fails: $!";
}
}
# Do it the old way.
my $flags = fcntl($socket_handle, F_GETFL, 0) or die "getfl fails: $!";
$flags = fcntl($socket_handle, F_SETFL, $flags | O_NONBLOCK)
or die "setfl fails: $!";
return;
}

# Another static member. Turn blocking on when we're done, in case
Expand All @@ -119,29 +121,30 @@ sub _start_blocking {
# RCC 2003-01-20: Perl 5.005_03 doesn't like blocking(), so we'll
# only call it in perl 5.8.0 and beyond.

# Do it the Win32 way.
if ($^O eq 'MSWin32') {
my $unset_it = "0";

# 126 is FIONBIO (some docs say 0x7F << 16)
ioctl(
$socket_handle,
0x80000000 | (4 << 16) | (ord('f') << 8) | 126,
\$unset_it
) or die "ioctl fails: $!";
return;
}

# Do it the 5.8+ way.
if ($] >= 5.008) {
$socket_handle->blocking(1);
return;
}
else {
# Do it the Win32 way. XXX This is incomplete.
if ($^O eq 'MSWin32') {
my $unset_it = "0";

# 126 is FIONBIO (some docs say 0x7F << 16)
ioctl( $socket_handle,
0x80000000 | (4 << 16) | (ord('f') << 8) | 126,
$unset_it
)
or die "ioctl fails: $!";
}

# Do it the way everyone else does.
else {
my $flags = fcntl($socket_handle, F_GETFL, 0) or die "getfl fails: $!";
$flags = fcntl($socket_handle, F_SETFL, $flags & ~O_NONBLOCK)
or die "setfl fails: $!";
}
}
# Do it the old way.
my $flags = fcntl($socket_handle, F_GETFL, 0) or die "getfl fails: $!";
$flags = fcntl($socket_handle, F_SETFL, $flags & ~O_NONBLOCK)
or die "setfl fails: $!";
return;
}

# Make a socket. This is a homebrew socketpair() for systems that
Expand Down
36 changes: 18 additions & 18 deletions lib/POE/Resource/FileHandles.pm
Expand Up @@ -346,11 +346,11 @@ sub _data_handle_add {
my $set_it = "1";

# 126 is FIONBIO (some docs say 0x7F << 16)
ioctl( $handle,
0x80000000 | (4 << 16) | (ord('f') << 8) | 126,
$set_it
)
or _trap "ioctl($handle, FIONBIO, $set_it) fails: $!\n";
ioctl(
$handle,
0x80000000 | (4 << 16) | (ord('f') << 8) | 126,
\$set_it
) or _trap "ioctl($handle, FIONBIO, $set_it) fails: $!\n";
}
}

Expand Down Expand Up @@ -425,11 +425,11 @@ sub _data_handle_add {
# the session/handle pair.

else {
$kr_fno_rec->[FMO_SESSIONS]->{$session}->{$handle} =
[ $handle, # HSS_HANDLE
$session, # HSS_SESSION
$event, # HSS_STATE
];
$kr_fno_rec->[FMO_SESSIONS]->{$session}->{$handle} = [
$handle, # HSS_HANDLE
$session, # HSS_SESSION
$event, # HSS_STATE
];

# Fix reference counts.
$kr_fileno->[FNO_TOT_REFCOUNT]++;
Expand All @@ -449,14 +449,14 @@ sub _data_handle_add {
# register the filehandle in the session's structure.

unless (exists $kr_ses_to_handle{$session}->{$handle}) {
$kr_ses_to_handle{$session}->{$handle} =
[ $handle, # SH_HANDLE
0, # SH_REFCOUNT
[ 0, # SH_MODECOUNT / MODE_RD
0, # SH_MODECOUNT / MODE_WR
0 # SH_MODECOUNT / MODE_EX
]
];
$kr_ses_to_handle{$session}->{$handle} = [
$handle, # SH_HANDLE
0, # SH_REFCOUNT
[ 0, # SH_MODECOUNT / MODE_RD
0, # SH_MODECOUNT / MODE_WR
0 # SH_MODECOUNT / MODE_EX
]
];
$self->_data_ses_refcount_inc($session);
}

Expand Down

0 comments on commit edd092a

Please sign in to comment.