From ddd8d0adec2bbac86bbca40900acae2c56740e82 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 3 Jul 2019 01:05:09 +0000 Subject: Net::Cmd: call ->sysread and ->syswrite as OO methods This seems required to support COMPRESS DEFLATE in NNTP in the next commit with minimal compatibility problems. The only potential compatibility problem is existing users of Net::NNTP won't be able to _blindly_ enable NNTP compression without auditing their existing code for uses for {syswrite,sysread}($cmd, ...). Other options I've attempted or considered for NNTP COMPRESS, but rejected: * tie won't work for deflating, since we need to syswrite to the original IO::Socket::* object (which may be IO::Socket::SSL) once we have a buffer of deflated data. * AFAIK, tie won't stack like PerlIO layers, either, and IO::Socket::SSL already uses tie. * using dup2 is wasteful, and won't work with TLS if we want to keep $self stable * open(my $fh, "<&=", $self) won't waste an FD, but still won't work with TLS for the same reason. * PerlIO::via won't work, since we rely on sysread/syswrite and that bypasses IO layers. So a future commit will provide ->syswrite and ->sysread to the NNTP class once it's compressed, and we can rely on SUPER::{sysread,syswrite} to make the underlying read, write, SSL_read, or SSL_write calls. --- lib/Net/Cmd.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Net/Cmd.pm b/lib/Net/Cmd.pm index bdb2028..f9697cb 100644 --- a/lib/Net/Cmd.pm +++ b/lib/Net/Cmd.pm @@ -6,6 +6,10 @@ # the same terms as Perl itself, i.e. under the terms of either the GNU General # Public License or the Artistic License, as specified in the F file. +# NOTE: We need to use $cmd->syswrite(...) and $cmd->sysread(...) +# instead of syswrite($cmd, ...) and sysread($cmd, ...) throughout +# this package to support COMPRESS in Net::NNTP alongside +# IO::Socket::SSL without breaking backwards compatibility. package Net::Cmd; use 5.008001; @@ -207,7 +211,7 @@ sub _syswrite_with_timeout { my $nfound = select(undef, $wout = $win, undef, $pending); if ((defined $nfound and $nfound > 0) or -f $cmd) # -f for testing on win32 { - my $w = syswrite($cmd, $line, $len, $offset); + my $w = $cmd->syswrite($line, $len, $offset); if (! defined($w) ) { my $err = $!; $cmd->close; @@ -350,7 +354,7 @@ sub getline { my $err; until ($err || scalar(@{${*$cmd}{'net_cmd_lines'}})) { - my $r = sysread($cmd, $partial, 1024, length($partial)); + my $r = $cmd->sysread($partial, 1024, length($partial)); if (defined($r)) { if ($r > 0) { my @buf = split(/\015?\012/, $partial, -1); ## break into lines -- cgit v1.2.3-24-ge0c7