From: Lincoln Stein Date: Wed, 28 Jul 1999 13:55:05 +0000 (-0400) Subject: IO::* enhancements. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8fd73a68c4e3e61c175bff5ea8257b8c0787333e;p=p5sagit%2Fp5-mst-13.2.git IO::* enhancements. 1) write() and syswrite() will now accept a single-argument form of the call, for consistency with Perl's syswrite(). 2) You can create a TCP-based IO::Socket::INET without forcing a connect attempt. This allows you to configure its options (like making it non-blocking) and then call connect() manually. 3) Fixed a bug that prevented the IO::Socket::protocol() accessor from ever returning the correct value. To: Graham Barr Cc: Lincoln Stein , perl5-porters@perl.org Subject: Re: patch for IO::* Message-ID: <14239.17401.330408.145295@formaggio.cshl.org> p4raw-id: //depot/cfgperl@3820 --- diff --git a/ext/IO/lib/IO/Handle.pm b/ext/IO/lib/IO/Handle.pm index 9b5dd65..2205368 100644 --- a/ext/IO/lib/IO/Handle.pm +++ b/ext/IO/lib/IO/Handle.pm @@ -417,13 +417,15 @@ sub sysread { } sub write { - @_ == 3 || @_ == 4 or croak 'usage: $io->write(BUF, LEN [, OFFSET])'; + @_ >= 2 && @_ <= 4 or croak 'usage: $io->write(BUF [, LEN [, OFFSET]])'; local($\) = ""; + $_[2] = length($_[1]) unless defined $_[2]; print { $_[0] } substr($_[1], $_[3] || 0, $_[2]); } sub syswrite { - @_ == 3 || @_ == 4 or croak 'usage: $io->syswrite(BUF, LEN [, OFFSET])'; + @_ >= 2 && @_ <= 4 or croak 'usage: $io->syswrite(BUF [, LEN [, OFFSET]])'; + $_[2] = length($_[1]) unless defined $_[2]; syswrite($_[0], $_[1], $_[2], $_[3] || 0); } diff --git a/ext/IO/lib/IO/Socket.pm b/ext/IO/lib/IO/Socket.pm index 46205a6..5cf9e72 100644 --- a/ext/IO/lib/IO/Socket.pm +++ b/ext/IO/lib/IO/Socket.pm @@ -279,7 +279,7 @@ sub socktype { sub protocol { @_ == 1 or croak 'usage: $sock->protocol()'; my($sock) = @_; - ${*$sock}{'io_socket_protocol'}; + ${*$sock}{'io_socket_proto'}; } 1; diff --git a/ext/IO/lib/IO/Socket/INET.pm b/ext/IO/lib/IO/Socket/INET.pm index 3679595..d7ca4c1 100644 --- a/ext/IO/lib/IO/Socket/INET.pm +++ b/ext/IO/lib/IO/Socket/INET.pm @@ -149,6 +149,9 @@ sub configure { $raddr = shift @raddr; + # don't connect unless we're given a port or address + last unless defined($rport) || defined($raddr); + return _error($sock,'Cannot determine remote port') unless($rport || $type == SOCK_DGRAM || $type == SOCK_RAW);