Class: EventMachine::Ssh::Session
- Inherits:
-
Net::SSH::Connection::Session
- Object
- Net::SSH::Connection::Session
- EventMachine::Ssh::Session
- Includes:
- Log
- Defined in:
- lib/em-ssh/session.rb
Instance Method Summary collapse
-
#close ⇒ Object
Override Net::SSH::Connection::Session#close to remove dangling references to EM::Ssh::Connections and EM::Ssh::Sessions.
-
#initialize(transport, options = {}) ⇒ Session
constructor
A new instance of Session.
-
#loop(wait = nil, &block) ⇒ Object
Override the default, blocking behavior of Net::SSH.
-
#process(wait = nil, &block) ⇒ Object
Override the default, blocking behavior of Net::SSH.
- #send_message(msg) ⇒ Object
Methods included from Log
#debug, #error, #fatal, #info, #log, #warn
Constructor Details
#initialize(transport, options = {}) ⇒ Session
Returns a new instance of Session.
6 7 8 9 |
# File 'lib/em-ssh/session.rb', line 6 def initialize(transport, ={}) super(transport, ) register_callbacks end |
Instance Method Details
#close ⇒ Object
Override Net::SSH::Connection::Session#close to remove dangling references to EM::Ssh::Connections and EM::Ssh::Sessions. Also directly close local channels if the connection is already closed.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/em-ssh/session.rb', line 34 def close if @chan_timer @chan_timer.cancel remove_instance_variable(:@chan_timer) end # Net::SSH::Connection::Session#close doesn't check if the transport is # closed. If it is then calling Channel#close will will not close the # channel localy and the connection will just spin. if transport.closed? channels.each do |id, c| # remove the connection reference to facilitate Garbage Collection c.instance_variable_set(:@connection, nil) end channels.clear else channels.each do |id, channel| channel.close # force one last pass through the channel's send loop, so that # net-ssh will properly set the values for local_closed channel.process end loop { channels.any? && !transport.closed? } end # remove the reference to the transport to facilitate Garbage Collection transport, @transport = @transport, nil @listeners.clear transport.close end |
#loop(wait = nil, &block) ⇒ Object
Override the default, blocking behavior of Net::SSH. Callers to loop will still wait, but not block the loop.
13 14 15 16 17 18 19 20 |
# File 'lib/em-ssh/session.rb', line 13 def loop(wait=nil, &block) f = Fiber.current l = proc do block.call ? EM.next_tick(&l) : f.resume end EM.next_tick(&l) return Fiber.yield end |
#process(wait = nil, &block) ⇒ Object
Override the default, blocking behavior of Net::SSH
23 24 25 |
# File 'lib/em-ssh/session.rb', line 23 def process(wait=nil, &block) return true end |
#send_message(msg) ⇒ Object
27 28 29 |
# File 'lib/em-ssh/session.rb', line 27 def (msg) transport.(msg) end |