| 1 | package Net::SSH::Any::OS::MSWin::DPipe; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Carp; | ||
| 7 | use Socket; | ||
| 8 | use Errno; | ||
| 9 | use Net::SSH::Any::Util qw($debug _debug _debug_hexdump _first_defined _array_or_scalar_to_list); | ||
| 10 | use Net::SSH::Any::Constants qw(SSHA_CHANNEL_ERROR); | ||
| 11 | use Time::HiRes qw(sleep); | ||
| 12 | |||
| 13 | require Net::SSH::Any::OS::_Base::DPipe; | ||
| 14 | our @ISA = qw(Net::SSH::Any::OS::_Base::DPipe); | ||
| 15 | |||
| 16 | sub _in { ${*{shift()}}{_ssha_os_in} } | ||
| 17 | |||
| 18 | for my $method (qw(syswrite print printf say autoflush)) { | ||
| 19 | my $m = $method; | ||
| 20 | no strict 'refs'; | ||
| 21 | *{$m} = sub { shift->_in->$m(@_) } | ||
| 22 | } | ||
| 23 | |||
| 24 | sub _upgrade_fh_to_dpipe { | ||
| 25 | my ($class, $dpipe, $any, $proc, $in) = @_; | ||
| 26 | $class->SUPER::_upgrade_fh_to_dpipe($dpipe, $any, $proc); | ||
| 27 | bless $in, 'IO::Handle'; | ||
| 28 | ${*$dpipe}{_ssha_os_in} = $in; | ||
| 29 | $in->autoflush(1); | ||
| 30 | $dpipe; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub _close_fhs { | ||
| 34 | my $dpipe = shift; | ||
| 35 | my $ok = $dpipe->send_eof; | ||
| 36 | unless (close $dpipe) { | ||
| 37 | $dpipe->_any->_set_error(SSHA_CHANNEL_ERROR, "unable to close dpipe reading side: $!"); | ||
| 38 | undef $ok; | ||
| 39 | } | ||
| 40 | return $ok; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub send_eof { | ||
| 44 | my $dpipe = shift; | ||
| 45 | if (defined (my $in = delete ${*$dpipe}{_ssha_os_in})) { | ||
| 46 | unless (close $in) { | ||
| 47 | $dpipe->_any->_set_error(SSHA_CHANNEL_ERROR, "unable to close dpipe writing side: $!"); | ||
| 48 | return undef | ||
| 49 | } | ||
| 50 | } | ||
| 51 | 1 | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; |