about summary refs log tree commit
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-07-03 01:05:09 +0000
committerEric Wong <e@80x24.org>2019-07-03 01:05:41 +0000
commitddd8d0adec2bbac86bbca40900acae2c56740e82 (patch)
treee6c2e8f577c1bd0bd9f47dd728e6c9f1e4a26ec3
parent6f1c2c717f6e2858e5d62073c47efe11e597e067 (diff)
downloadperl-libnet-ddd8d0adec2bbac86bbca40900acae2c56740e82.tar.gz
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.
-rw-r--r--lib/Net/Cmd.pm8
1 files 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<LICENCE> 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