Subject: | [PATCH] only select for write readiness in connect |
Date: | Mon, 01 Dec 2014 21:21:52 -0600 |
To: | bug-IO-Socket-IP [...] rt.cpan.org |
From: | "Craig A. Berry" <craigberry [...] mac.com> |
When doing a non-blocking connect, IO::Socket::IP calls select with a timeout until the connection completes. However, that select call queries for ready-to-read, ready-to-write, and pending error, which doesn't really make sense as select is only documented to respond to a ready-to-write query when a non-blocking connect completes.
Changing the call so it only waits for ready-to-write to be set gets t/22timeout.t passing on VMS, where it has failed since inception. The select had been returning immediately without waiting for the timeout. Yes, there is probably something buggy about the VMS implementation that causes it to respond in an incoherent way to an undocumented combination of arguments. But it responds correctly to the documented combination of arguments, and there is no downside to just using the documented combination everywhere. With this change, tests still pass on Windows and OS X as well as starting to pass on VMS.
The patch itself is so simple I'll just paste it inline:
--- lib/IO/Socket/IP.pm;-0 2014-11-27 08:22:08 -0600
+++ lib/IO/Socket/IP.pm 2014-11-30 20:54:47 -0600
@@ -684,7 +684,7 @@
}
my $vec = ''; vec( $vec, $self->fileno, 1 ) = 1;
- if( !select( $vec, $vec, $vec, $timeout ) ) {
+ if( !select( undef, $vec, undef, $timeout ) ) {
$! = ETIMEDOUT;
return undef;
}
[end]
Possibly easier than applying the patch would be to just edit the first and third arguments to select, replacing them with undef.
Show quoted text
________________________________________
Craig A. Berry
mailto:craigberry@mac.com
"... getting out of a sonnet is much more
difficult than getting in."
Brad Leithauser