about summary refs log tree commit
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-07-02 20:12:37 +0000
committerEric Wong <e@80x24.org>2019-07-02 20:15:47 +0000
commitfaed7a7a571d3fdd2df8857cc84682e5d586074f (patch)
tree5b8e67fa5e83a10c8a99a3304011b8a250566a54
parentee9142670b970c5967f8cb9b7d6ccbf7883e53fa (diff)
downloadperl-libnet-faed7a7a571d3fdd2df8857cc84682e5d586074f.tar.gz
Net::Cmd: append directly to partial buf on sysread
sysread allow an offset argument to insert new data at a certain
place, use it to simplify our code, slightly.
-rw-r--r--lib/Net/Cmd.pm8
1 files changed, 2 insertions, 6 deletions
diff --git a/lib/Net/Cmd.pm b/lib/Net/Cmd.pm
index 2bb790d..0b1bbe1 100644
--- a/lib/Net/Cmd.pm
+++ b/lib/Net/Cmd.pm
@@ -335,24 +335,20 @@ sub getline {
   my $rin = "";
   vec($rin, $fd, 1) = 1;
 
-  my $buf;
-
   until (scalar(@{${*$cmd}{'net_cmd_lines'}})) {
     my $timeout = $cmd->timeout || undef;
     my $rout;
 
     my $select_ret = select($rout = $rin, undef, undef, $timeout);
     if ($select_ret > 0) {
-      unless (sysread($cmd, $buf = "", 1024)) {
+      unless (sysread($cmd, $partial, 1024, length($partial))) {
         my $err = $!;
         $cmd->close;
         $cmd->_set_status_closed($err);
         return;
       }
 
-      substr($buf, 0, 0) = $partial;    ## prepend from last sysread
-
-      my @buf = split(/\015?\012/, $buf, -1);    ## break into lines
+      my @buf = split(/\015?\012/, $partial, -1);    ## break into lines
 
       $partial = pop @buf;