Skip to content

Commit

Permalink
Cristiano Lincoln Mattos reported that SocketFactory was not emitting
Browse files Browse the repository at this point in the history
connect errors on Cygwin+Win2k.  His debugging pinpointed the section
in the code where the problem lay, and with his assistance I was able
to put together a working patch.  He also tested the patch on Win2k
and Linux, while I tested it on FreeBSD.  Other tests are forthcoming,
but I wanted to get the patch into CVS before that.
  • Loading branch information
rcaputo committed Aug 19, 2002
1 parent 6481ec1 commit dbae80e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/POE/Wheel/SocketFactory.pm
Expand Up @@ -30,6 +30,7 @@ sub MY_MINE_FAILURE () { 8 }
sub MY_SOCKET_PROTOCOL () { 9 }
sub MY_SOCKET_TYPE () { 10 }
sub MY_SOCKET_SELECTED () { 11 }
sub MY_STATE_ERROR () { 12 }

# Fletch has subclassed SSLSocketFactory from SocketFactory. He's
# added new members after MY_SOCKET_SELECTED. Be sure, if you extend
Expand Down Expand Up @@ -243,10 +244,40 @@ sub _define_connect_state {
}
);

# Cygwin expects an error state registered to expedite. This code
# is nearly identical the stuff above.
$poe_kernel->state
( $self->[MY_STATE_ERROR] = ( ref($self) .
"($unique_id) -> connect error"
),
sub {
# This prevents SEGV in older versions of Perl.
0 && CRIMSON_SCOPE_HACK('<');

# Grab some values and stop watching the socket.
my ($k, $me, $handle) = @_[KERNEL, SESSION, ARG0];
undef $$socket_selected;
$k->select($handle);

# Throw a failure if the connection failed.
$! = unpack('i', getsockopt($handle, SOL_SOCKET, SO_ERROR));
if ($!) {
(defined $$failure_event) and
$k->call( $me, $$failure_event,
'connect', ($!+0), $!, $unique_id
);
return;
}
}
);

$self->[MY_SOCKET_SELECTED] = 'yes';
$poe_kernel->select_write( $self->[MY_SOCKET_HANDLE],
$self->[MY_STATE_CONNECT]
);
$poe_kernel->select_expedite( $self->[MY_SOCKET_HANDLE],
$self->[MY_STATE_ERROR]
);
}

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -304,6 +335,9 @@ sub event {
$poe_kernel->select_write( $self->[MY_SOCKET_HANDLE],
$self->[MY_STATE_CONNECT]
);
$poe_kernel->select_expedite( $self->[MY_SOCKET_HANDLE],
$self->[MY_STATE_ERROR]
);
}
else {
die "POE developer error - no state defined";
Expand Down Expand Up @@ -381,6 +415,7 @@ sub new {
undef, # MY_SOCKET_PROTOCOL
undef, # MY_SOCKET_TYPE
undef, # MY_SOCKET_SELECTED
undef, # MY_STATE_ERROR
],
$type
);
Expand Down

0 comments on commit dbae80e

Please sign in to comment.