AnyEvent-SSH2
view release on metacpan or search on metacpan
lib/AnyEvent/SSH2.pm view on Meta::CPAN
# $Id: SSH2.pm,v 1.47 2009/01/26 01:50:38 turnstep Exp $
package AnyEvent::SSH2;
use strict;
use AE;
use AnyEvent::Handle;
use Net::SSH::Perl::Kex;
use Net::SSH::Perl::ChannelMgr;
use Net::SSH::Perl::Packet;
use Net::SSH::Perl::Buffer;
use Net::SSH::Perl::Constants qw( :protocol :msg2 :compat :hosts :channels :proposal :kex
CHAN_INPUT_CLOSED CHAN_INPUT_WAIT_DRAIN );
use Net::SSH::Perl::Cipher;
use Net::SSH::Perl::AuthMgr;
use Net::SSH::Perl::Comp;
use Net::SSH::Perl::Util qw(:hosts);
use Scalar::Util qw(blessed weaken);
use Carp qw( croak );
use base qw( Net::SSH::Perl );
our $VERSION = '0.04';
lib/AnyEvent/SSH2.pm view on Meta::CPAN
$cmgr->process_output_packets;
# 妿å¤çå®äº. å
³æææçè¿æ¥
# 乿以å¨è¿è¿è¡è¿ä¸ªæä½æ¯å 为主 channel ä¹éè¦æä½
for my $c (@{ $cmgr->{channels} }) {
next unless defined $c;
if ($c->{wfd} &&
$c->{extended}->length == 0 &&
$c->{output}->length == 0 &&
$c->{ostate} == CHAN_OUTPUT_WAIT_DRAIN ) {
$c->obuf_empty;
}
# ä¸é¢ obuf_empty ä¼ç» ostate åæ CHAN_OUTPUT_CLOSED
# ä¸é¢è¿ä¸ªå°±ä¼åå
³éç»è¿ç¨
if ($c->delete_if_full_closed) {
defined $c->{cb} ? $c->{cb}->() : '';
$cmgr->remove($c->{id});
}
}
my $oc = grep { defined } @{ $cmgr->{channels} };
return $ssh->client_loop unless $oc > 1;
my $cv = AE::cv sub {
my $result = shift->recv;
delete $ssh->{watcher};
$ssh->event_loop($cmgr, $h, $cb);
};
# è¿æ¯å¤çé¢éä¸çè¾åº, 客æ·ç«¯çè¾å
¥
for my $c (@{ $cmgr->{channels} }) {
next unless defined $c;
my $id = $c->{id};
if ($c->{rfd} && $c->{istate} == CHAN_INPUT_OPEN &&
$c->{remote_window} > 0 &&
$c->{input}->length < $c->{remote_window}) {
$ssh->{watcher}{$id}{rfd} = AE::io $c->{rfd}, 0, sub {
# 顺åºè®°å½ - é¢é - rfd
my $buf;
sysread $c->{rfd}, $buf, 8192;
($buf) = $buf =~ /(.*)/s;
$c->send_data($buf);
$cv->send('rfd');
delete $ssh->{watcher}{$id}{rfd}
};
}
# ç»å
容è¾åº
if (defined $c->{wfd} &&
$c->{ostate} == CHAN_OUTPUT_OPEN ||
$c->{ostate} == CHAN_OUTPUT_WAIT_DRAIN) {
if ($c->{output} and $c->{output}->length > 0) {
$ssh->{watcher}{$id}{wfd} = AE::io $c->{wfd}, 1, sub {
if (my $r = $c->{handlers}{"_output_buffer"}) {
$r->{code}->( $c, $c->{output}, @{ $r->{extra} } );
}
$c->{local_consumed} += $c->{output}->length;
$c->{output}->empty;
$cv->send('wfd');
delete $ssh->{watcher}{$id}{wfd}
}
( run in 0.270 second using v1.01-cache-2.11-cpan-4e96b696675 )