diff options
Diffstat (limited to 'lib/Net/Cmd.pm')
-rw-r--r-- | lib/Net/Cmd.pm | 649 |
1 files changed, 322 insertions, 327 deletions
diff --git a/lib/Net/Cmd.pm b/lib/Net/Cmd.pm index aa1a1934b3..355b6c9981 100644 --- a/lib/Net/Cmd.pm +++ b/lib/Net/Cmd.pm @@ -1,4 +1,4 @@ -# Net::Cmd.pm $Id: //depot/libnet/Net/Cmd.pm#34 $ +# Net::Cmd.pm # # Copyright (c) 1995-2006 Graham Barr <gbarr@pobox.com>. All rights reserved. # This program is free software; you can redistribute it and/or @@ -17,34 +17,37 @@ use Symbol 'gensym'; BEGIN { if ($^O eq 'os390') { require Convert::EBCDIC; -# Convert::EBCDIC->import; + + # Convert::EBCDIC->import; } } -$VERSION = "2.27_01"; +my $doUTF8 = eval { require utf8 }; + +$VERSION = "2.28"; @ISA = qw(Exporter); @EXPORT = qw(CMD_INFO CMD_OK CMD_MORE CMD_REJECT CMD_ERROR CMD_PENDING); -sub CMD_INFO { 1 } -sub CMD_OK { 2 } -sub CMD_MORE { 3 } -sub CMD_REJECT { 4 } -sub CMD_ERROR { 5 } -sub CMD_PENDING { 0 } + +sub CMD_INFO {1} +sub CMD_OK {2} +sub CMD_MORE {3} +sub CMD_REJECT {4} +sub CMD_ERROR {5} +sub CMD_PENDING {0} my %debug = (); my $tr = $^O eq 'os390' ? Convert::EBCDIC->new() : undef; -sub toebcdic -{ - my $cmd = shift; - unless (exists ${*$cmd}{'net_cmd_asciipeer'}) - { - my $string = $_[0]; - my $ebcdicstr = $tr->toebcdic($string); - ${*$cmd}{'net_cmd_asciipeer'} = $string !~ /^\d+/ && $ebcdicstr =~ /^\d+/; +sub toebcdic { + my $cmd = shift; + + unless (exists ${*$cmd}{'net_cmd_asciipeer'}) { + my $string = $_[0]; + my $ebcdicstr = $tr->toebcdic($string); + ${*$cmd}{'net_cmd_asciipeer'} = $string !~ /^\d+/ && $ebcdicstr =~ /^\d+/; } ${*$cmd}{'net_cmd_asciipeer'} @@ -52,361 +55,357 @@ sub toebcdic : $_[0]; } -sub toascii -{ + +sub toascii { my $cmd = shift; ${*$cmd}{'net_cmd_asciipeer'} ? $tr->toascii($_[0]) : $_[0]; } -sub _print_isa -{ - no strict qw(refs); - my $pkg = shift; - my $cmd = $pkg; +sub _print_isa { + no strict qw(refs); - $debug{$pkg} ||= 0; + my $pkg = shift; + my $cmd = $pkg; - my %done = (); - my @do = ($pkg); - my %spc = ( $pkg , ""); + $debug{$pkg} ||= 0; - while ($pkg = shift @do) - { - next if defined $done{$pkg}; + my %done = (); + my @do = ($pkg); + my %spc = ($pkg, ""); - $done{$pkg} = 1; + while ($pkg = shift @do) { + next if defined $done{$pkg}; - my $v = defined ${"${pkg}::VERSION"} - ? "(" . ${"${pkg}::VERSION"} . ")" - : ""; + $done{$pkg} = 1; - my $spc = $spc{$pkg}; - $cmd->debug_print(1,"${spc}${pkg}${v}\n"); + my $v = + defined ${"${pkg}::VERSION"} + ? "(" . ${"${pkg}::VERSION"} . ")" + : ""; - if(@{"${pkg}::ISA"}) - { - @spc{@{"${pkg}::ISA"}} = (" " . $spc{$pkg}) x @{"${pkg}::ISA"}; - unshift(@do, @{"${pkg}::ISA"}); + my $spc = $spc{$pkg}; + $cmd->debug_print(1, "${spc}${pkg}${v}\n"); + + if (@{"${pkg}::ISA"}) { + @spc{@{"${pkg}::ISA"}} = (" " . $spc{$pkg}) x @{"${pkg}::ISA"}; + unshift(@do, @{"${pkg}::ISA"}); } } } -sub debug -{ - @_ == 1 or @_ == 2 or croak 'usage: $obj->debug([LEVEL])'; - my($cmd,$level) = @_; - my $pkg = ref($cmd) || $cmd; - my $oldval = 0; +sub debug { + @_ == 1 or @_ == 2 or croak 'usage: $obj->debug([LEVEL])'; - if(ref($cmd)) - { - $oldval = ${*$cmd}{'net_cmd_debug'} || 0; + my ($cmd, $level) = @_; + my $pkg = ref($cmd) || $cmd; + my $oldval = 0; + + if (ref($cmd)) { + $oldval = ${*$cmd}{'net_cmd_debug'} || 0; } - else - { - $oldval = $debug{$pkg} || 0; + else { + $oldval = $debug{$pkg} || 0; } - return $oldval + return $oldval unless @_ == 2; - $level = $debug{$pkg} || 0 + $level = $debug{$pkg} || 0 unless defined $level; - _print_isa($pkg) - if($level && !exists $debug{$pkg}); + _print_isa($pkg) + if ($level && !exists $debug{$pkg}); - if(ref($cmd)) - { - ${*$cmd}{'net_cmd_debug'} = $level; + if (ref($cmd)) { + ${*$cmd}{'net_cmd_debug'} = $level; } - else - { - $debug{$pkg} = $level; + else { + $debug{$pkg} = $level; } - $oldval; + $oldval; } -sub message -{ - @_ == 1 or croak 'usage: $obj->message()'; - my $cmd = shift; +sub message { + @_ == 1 or croak 'usage: $obj->message()'; + + my $cmd = shift; - wantarray ? @{${*$cmd}{'net_cmd_resp'}} - : join("", @{${*$cmd}{'net_cmd_resp'}}); + wantarray + ? @{${*$cmd}{'net_cmd_resp'}} + : join("", @{${*$cmd}{'net_cmd_resp'}}); } + sub debug_text { $_[2] } -sub debug_print -{ - my($cmd,$out,$text) = @_; - print STDERR $cmd,($out ? '>>> ' : '<<< '), $cmd->debug_text($out,$text); + +sub debug_print { + my ($cmd, $out, $text) = @_; + print STDERR $cmd, ($out ? '>>> ' : '<<< '), $cmd->debug_text($out, $text); } -sub code -{ - @_ == 1 or croak 'usage: $obj->code()'; - my $cmd = shift; +sub code { + @_ == 1 or croak 'usage: $obj->code()'; + + my $cmd = shift; - ${*$cmd}{'net_cmd_code'} = "000" - unless exists ${*$cmd}{'net_cmd_code'}; + ${*$cmd}{'net_cmd_code'} = "000" + unless exists ${*$cmd}{'net_cmd_code'}; - ${*$cmd}{'net_cmd_code'}; + ${*$cmd}{'net_cmd_code'}; } -sub status -{ - @_ == 1 or croak 'usage: $obj->status()'; - my $cmd = shift; +sub status { + @_ == 1 or croak 'usage: $obj->status()'; - substr(${*$cmd}{'net_cmd_code'},0,1); + my $cmd = shift; + + substr(${*$cmd}{'net_cmd_code'}, 0, 1); } -sub set_status -{ - @_ == 3 or croak 'usage: $obj->set_status(CODE, MESSAGE)'; - my $cmd = shift; - my($code,$resp) = @_; +sub set_status { + @_ == 3 or croak 'usage: $obj->set_status(CODE, MESSAGE)'; + + my $cmd = shift; + my ($code, $resp) = @_; - $resp = [ $resp ] - unless ref($resp); + $resp = [$resp] + unless ref($resp); - (${*$cmd}{'net_cmd_code'},${*$cmd}{'net_cmd_resp'}) = ($code, $resp); + (${*$cmd}{'net_cmd_code'}, ${*$cmd}{'net_cmd_resp'}) = ($code, $resp); - 1; + 1; } -sub command -{ - my $cmd = shift; - unless (defined fileno($cmd)) - { +sub command { + my $cmd = shift; + + unless (defined fileno($cmd)) { $cmd->set_status("599", "Connection closed"); return $cmd; } - $cmd->dataend() - if(exists ${*$cmd}{'net_cmd_last_ch'}); + $cmd->dataend() + if (exists ${*$cmd}{'net_cmd_last_ch'}); - if (scalar(@_)) - { - local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS'; + if (scalar(@_)) { + local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS'; - my $str = join(" ", map { /\n/ ? do { my $n = $_; $n =~ tr/\n/ /; $n } : $_; } @_); - $str = $cmd->toascii($str) if $tr; - $str .= "\015\012"; + my $str = join( + " ", + map { + /\n/ + ? do { my $n = $_; $n =~ tr/\n/ /; $n } + : $_; + } @_ + ); + $str = $cmd->toascii($str) if $tr; + $str .= "\015\012"; - my $len = length $str; - my $swlen; + my $len = length $str; + my $swlen; - $cmd->close - unless (defined($swlen = syswrite($cmd,$str,$len)) && $swlen == $len); + $cmd->close + unless (defined($swlen = syswrite($cmd, $str, $len)) && $swlen == $len); - $cmd->debug_print(1,$str) - if($cmd->debug); + $cmd->debug_print(1, $str) + if ($cmd->debug); - ${*$cmd}{'net_cmd_resp'} = []; # the response - ${*$cmd}{'net_cmd_code'} = "000"; # Made this one up :-) + ${*$cmd}{'net_cmd_resp'} = []; # the response + ${*$cmd}{'net_cmd_code'} = "000"; # Made this one up :-) } - $cmd; + $cmd; } -sub ok -{ - @_ == 1 or croak 'usage: $obj->ok()'; - my $code = $_[0]->code; - 0 < $code && $code < 400; +sub ok { + @_ == 1 or croak 'usage: $obj->ok()'; + + my $code = $_[0]->code; + 0 < $code && $code < 400; } -sub unsupported -{ - my $cmd = shift; - ${*$cmd}{'net_cmd_resp'} = [ 'Unsupported command' ]; - ${*$cmd}{'net_cmd_code'} = 580; - 0; +sub unsupported { + my $cmd = shift; + + ${*$cmd}{'net_cmd_resp'} = ['Unsupported command']; + ${*$cmd}{'net_cmd_code'} = 580; + 0; } -sub getline -{ - my $cmd = shift; - ${*$cmd}{'net_cmd_lines'} ||= []; +sub getline { + my $cmd = shift; + + ${*$cmd}{'net_cmd_lines'} ||= []; - return shift @{${*$cmd}{'net_cmd_lines'}} + return shift @{${*$cmd}{'net_cmd_lines'}} if scalar(@{${*$cmd}{'net_cmd_lines'}}); - my $partial = defined(${*$cmd}{'net_cmd_partial'}) - ? ${*$cmd}{'net_cmd_partial'} : ""; - my $fd = fileno($cmd); + my $partial = defined(${*$cmd}{'net_cmd_partial'}) ? ${*$cmd}{'net_cmd_partial'} : ""; + my $fd = fileno($cmd); - return undef - unless defined $fd; + return undef + unless defined $fd; - my $rin = ""; - vec($rin,$fd,1) = 1; + my $rin = ""; + vec($rin, $fd, 1) = 1; - my $buf; + my $buf; - until(scalar(@{${*$cmd}{'net_cmd_lines'}})) - { - my $timeout = $cmd->timeout || undef; - my $rout; + 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)) - { - carp(ref($cmd) . ": Unexpected EOF on command channel") - if $cmd->debug; - $cmd->close; - return undef; - } + my $select_ret = select($rout = $rin, undef, undef, $timeout); + if ($select_ret > 0) { + unless (sysread($cmd, $buf = "", 1024)) { + carp(ref($cmd) . ": Unexpected EOF on command channel") + if $cmd->debug; + $cmd->close; + return undef; + } - substr($buf,0,0) = $partial; ## prepend from last sysread + substr($buf, 0, 0) = $partial; ## prepend from last sysread - my @buf = split(/\015?\012/, $buf, -1); ## break into lines + my @buf = split(/\015?\012/, $buf, -1); ## break into lines - $partial = pop @buf; + $partial = pop @buf; - push(@{${*$cmd}{'net_cmd_lines'}}, map { "$_\n" } @buf); + push(@{${*$cmd}{'net_cmd_lines'}}, map {"$_\n"} @buf); } - else - { - my $msg = $select_ret ? "Error or Interrupted: $!" : "Timeout"; - carp("$cmd: $msg") if($cmd->debug); - return undef; + else { + my $msg = $select_ret ? "Error or Interrupted: $!" : "Timeout"; + carp("$cmd: $msg") if ($cmd->debug); + return undef; } } - ${*$cmd}{'net_cmd_partial'} = $partial; + ${*$cmd}{'net_cmd_partial'} = $partial; - if ($tr) - { - foreach my $ln (@{${*$cmd}{'net_cmd_lines'}}) - { - $ln = $cmd->toebcdic($ln); + if ($tr) { + foreach my $ln (@{${*$cmd}{'net_cmd_lines'}}) { + $ln = $cmd->toebcdic($ln); } } - shift @{${*$cmd}{'net_cmd_lines'}}; + shift @{${*$cmd}{'net_cmd_lines'}}; } -sub ungetline -{ - my($cmd,$str) = @_; - ${*$cmd}{'net_cmd_lines'} ||= []; - unshift(@{${*$cmd}{'net_cmd_lines'}}, $str); +sub ungetline { + my ($cmd, $str) = @_; + + ${*$cmd}{'net_cmd_lines'} ||= []; + unshift(@{${*$cmd}{'net_cmd_lines'}}, $str); } -sub parse_response -{ - return () + +sub parse_response { + return () unless $_[1] =~ s/^(\d\d\d)(.?)//o; - ($1, $2 eq "-"); + ($1, $2 eq "-"); } -sub response -{ - my $cmd = shift; - my($code,$more) = (undef) x 2; - ${*$cmd}{'net_cmd_resp'} ||= []; +sub response { + my $cmd = shift; + my ($code, $more) = (undef) x 2; - while(1) - { - my $str = $cmd->getline(); + ${*$cmd}{'net_cmd_resp'} ||= []; - return CMD_ERROR - unless defined($str); + while (1) { + my $str = $cmd->getline(); - $cmd->debug_print(0,$str) - if ($cmd->debug); + return CMD_ERROR + unless defined($str); - ($code,$more) = $cmd->parse_response($str); - unless(defined $code) - { - $cmd->ungetline($str); - last; + $cmd->debug_print(0, $str) + if ($cmd->debug); + + ($code, $more) = $cmd->parse_response($str); + unless (defined $code) { + $cmd->ungetline($str); + last; } - ${*$cmd}{'net_cmd_code'} = $code; + ${*$cmd}{'net_cmd_code'} = $code; - push(@{${*$cmd}{'net_cmd_resp'}},$str); + push(@{${*$cmd}{'net_cmd_resp'}}, $str); - last unless($more); - } + last unless ($more); + } - substr($code,0,1); + substr($code, 0, 1); } -sub read_until_dot -{ - my $cmd = shift; - my $fh = shift; - my $arr = []; - while(1) - { - my $str = $cmd->getline() or return undef; +sub read_until_dot { + my $cmd = shift; + my $fh = shift; + my $arr = []; - $cmd->debug_print(0,$str) - if ($cmd->debug & 4); + while (1) { + my $str = $cmd->getline() or return undef; - last if($str =~ /^\.\r?\n/o); + $cmd->debug_print(0, $str) + if ($cmd->debug & 4); - $str =~ s/^\.\././o; + last if ($str =~ /^\.\r?\n/o); - if (defined $fh) - { - print $fh $str; + $str =~ s/^\.\././o; + + if (defined $fh) { + print $fh $str; } - else - { - push(@$arr,$str); + else { + push(@$arr, $str); } } - $arr; + $arr; } -sub datasend -{ - my $cmd = shift; - my $arr = @_ == 1 && ref($_[0]) ? $_[0] : \@_; - my $line = join("" ,@$arr); - return 0 unless defined(fileno($cmd)); +sub datasend { + my $cmd = shift; + my $arr = @_ == 1 && ref($_[0]) ? $_[0] : \@_; + my $line = join("", @$arr); + + if ($doUTF8) { + # encode to individual utf8 bytes if + # $line is a string (in internal UTF-8) + utf8::encode($line) if utf8::is_utf8($line); + } + + return 0 unless defined(fileno($cmd)); - my $last_ch = ${*$cmd}{'net_cmd_last_ch'}; - $last_ch = ${*$cmd}{'net_cmd_last_ch'} = "\012" unless defined $last_ch; + my $last_ch = ${*$cmd}{'net_cmd_last_ch'}; + $last_ch = ${*$cmd}{'net_cmd_last_ch'} = "\012" unless defined $last_ch; - return 1 unless length $line; + return 1 unless length $line; - if($cmd->debug) { - foreach my $b (split(/\n/,$line)) { - $cmd->debug_print(1, "$b\n"); - } + if ($cmd->debug) { + foreach my $b (split(/\n/, $line)) { + $cmd->debug_print(1, "$b\n"); + } } - $line =~ tr/\r\n/\015\012/ unless "\r" eq "\015"; + $line =~ tr/\r\n/\015\012/ unless "\r" eq "\015"; my $first_ch = ''; @@ -417,121 +416,113 @@ sub datasend $first_ch = "." if $line =~ /^\./; } - $line =~ s/\015?\012(\.?)/\015\012$1$1/sg; + $line =~ s/\015?\012(\.?)/\015\012$1$1/sg; - substr($line,0,0) = $first_ch; + substr($line, 0, 0) = $first_ch; - ${*$cmd}{'net_cmd_last_ch'} = substr($line,-1,1); + ${*$cmd}{'net_cmd_last_ch'} = substr($line, -1, 1); - my $len = length($line); - my $offset = 0; - my $win = ""; - vec($win,fileno($cmd),1) = 1; - my $timeout = $cmd->timeout || undef; + my $len = length($line); + my $offset = 0; + my $win = ""; + vec($win, fileno($cmd), 1) = 1; + my $timeout = $cmd->timeout || undef; - local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS'; + local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS'; - while($len) - { - my $wout; - my $s = select(undef,$wout=$win, undef, $timeout); - if ((defined $s and $s > 0) or -f $cmd) # -f for testing on win32 + while ($len) { + my $wout; + my $s = select(undef, $wout = $win, undef, $timeout); + if ((defined $s and $s > 0) or -f $cmd) # -f for testing on win32 { - my $w = syswrite($cmd, $line, $len, $offset); - unless (defined($w)) - { - carp("$cmd: $!") if $cmd->debug; - return undef; + my $w = syswrite($cmd, $line, $len, $offset); + unless (defined($w)) { + carp("$cmd: $!") if $cmd->debug; + return undef; } - $len -= $w; - $offset += $w; + $len -= $w; + $offset += $w; } - else - { - carp("$cmd: Timeout") if($cmd->debug); - return undef; + else { + carp("$cmd: Timeout") if ($cmd->debug); + return undef; } } - 1; + 1; } -sub rawdatasend -{ - my $cmd = shift; - my $arr = @_ == 1 && ref($_[0]) ? $_[0] : \@_; - my $line = join("" ,@$arr); - return 0 unless defined(fileno($cmd)); +sub rawdatasend { + my $cmd = shift; + my $arr = @_ == 1 && ref($_[0]) ? $_[0] : \@_; + my $line = join("", @$arr); - return 1 + return 0 unless defined(fileno($cmd)); + + return 1 unless length($line); - if($cmd->debug) - { - my $b = "$cmd>>> "; - print STDERR $b,join("\n$b",split(/\n/,$line)),"\n"; + if ($cmd->debug) { + my $b = "$cmd>>> "; + print STDERR $b, join("\n$b", split(/\n/, $line)), "\n"; } - my $len = length($line); - my $offset = 0; - my $win = ""; - vec($win,fileno($cmd),1) = 1; - my $timeout = $cmd->timeout || undef; - - local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS'; - while($len) - { - my $wout; - if (select(undef,$wout=$win, undef, $timeout) > 0) - { - my $w = syswrite($cmd, $line, $len, $offset); - unless (defined($w)) - { - carp("$cmd: $!") if $cmd->debug; - return undef; + my $len = length($line); + my $offset = 0; + my $win = ""; + vec($win, fileno($cmd), 1) = 1; + my $timeout = $cmd->timeout || undef; + + local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS'; + while ($len) { + my $wout; + if (select(undef, $wout = $win, undef, $timeout) > 0) { + my $w = syswrite($cmd, $line, $len, $offset); + unless (defined($w)) { + carp("$cmd: $!") if $cmd->debug; + return undef; } - $len -= $w; - $offset += $w; + $len -= $w; + $offset += $w; } - else - { - carp("$cmd: Timeout") if($cmd->debug); - return undef; + else { + carp("$cmd: Timeout") if ($cmd->debug); + return undef; } } - 1; + 1; } -sub dataend -{ - my $cmd = shift; - return 0 unless defined(fileno($cmd)); +sub dataend { + my $cmd = shift; + + return 0 unless defined(fileno($cmd)); - my $ch = ${*$cmd}{'net_cmd_last_ch'}; - my $tosend; + my $ch = ${*$cmd}{'net_cmd_last_ch'}; + my $tosend; - if (!defined $ch) { - return 1; - } - elsif ($ch ne "\012") { - $tosend = "\015\012"; - } + if (!defined $ch) { + return 1; + } + elsif ($ch ne "\012") { + $tosend = "\015\012"; + } - $tosend .= ".\015\012"; + $tosend .= ".\015\012"; - local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS'; + local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS'; - $cmd->debug_print(1, ".\n") - if($cmd->debug); + $cmd->debug_print(1, ".\n") + if ($cmd->debug); - syswrite($cmd,$tosend, length $tosend); + syswrite($cmd, $tosend, length $tosend); - delete ${*$cmd}{'net_cmd_last_ch'}; + delete ${*$cmd}{'net_cmd_last_ch'}; - $cmd->response() == CMD_OK; + $cmd->response() == CMD_OK; } # read and write to tied filehandle @@ -539,14 +530,14 @@ sub tied_fh { my $cmd = shift; ${*$cmd}{'net_cmd_readbuf'} = ''; my $fh = gensym(); - tie *$fh,ref($cmd),$cmd; + tie *$fh, ref($cmd), $cmd; return $fh; } # tie to myself sub TIEHANDLE { my $class = shift; - my $cmd = shift; + my $cmd = shift; return $cmd; } @@ -554,24 +545,26 @@ sub TIEHANDLE { # end-of-file when the dot is encountered. sub READ { my $cmd = shift; - my ($len,$offset) = @_[1,2]; + my ($len, $offset) = @_[1, 2]; return unless exists ${*$cmd}{'net_cmd_readbuf'}; my $done = 0; while (!$done and length(${*$cmd}{'net_cmd_readbuf'}) < $len) { - ${*$cmd}{'net_cmd_readbuf'} .= $cmd->getline() or return; - $done++ if ${*$cmd}{'net_cmd_readbuf'} =~ s/^\.\r?\n\Z//m; + ${*$cmd}{'net_cmd_readbuf'} .= $cmd->getline() or return; + $done++ if ${*$cmd}{'net_cmd_readbuf'} =~ s/^\.\r?\n\Z//m; } $_[0] = ''; - substr($_[0],$offset+0) = substr(${*$cmd}{'net_cmd_readbuf'},0,$len); - substr(${*$cmd}{'net_cmd_readbuf'},0,$len) = ''; + substr($_[0], $offset + 0) = substr(${*$cmd}{'net_cmd_readbuf'}, 0, $len); + substr(${*$cmd}{'net_cmd_readbuf'}, 0, $len) = ''; delete ${*$cmd}{'net_cmd_readbuf'} if $done; return length $_[0]; } + sub READLINE { my $cmd = shift; + # in this context, we use the presence of readbuf to # indicate that we have not yet reached the eof return unless exists ${*$cmd}{'net_cmd_readbuf'}; @@ -580,19 +573,21 @@ sub READLINE { $line; } + sub PRINT { my $cmd = shift; - my ($buf,$len,$offset) = @_; - $len ||= length ($buf); + my ($buf, $len, $offset) = @_; + $len ||= length($buf); $offset += 0; - return unless $cmd->datasend(substr($buf,$offset,$len)); - ${*$cmd}{'net_cmd_sending'}++; # flag that we should call dataend() + return unless $cmd->datasend(substr($buf, $offset, $len)); + ${*$cmd}{'net_cmd_sending'}++; # flag that we should call dataend() return $len; } + sub CLOSE { my $cmd = shift; - my $r = exists(${*$cmd}{'net_cmd_sending'}) ? $cmd->dataend : 1; + my $r = exists(${*$cmd}{'net_cmd_sending'}) ? $cmd->dataend : 1; delete ${*$cmd}{'net_cmd_readbuf'}; delete ${*$cmd}{'net_cmd_sending'}; $r; |