Method: Net::SSH::Connection::Session#process
- Defined in:
- lib/net/ssh/connection/session.rb
#process(wait = nil, &block) ⇒ Object
The core of the event loop. It processes a single iteration of the event loop. If a block is given, it should return false when the processing should abort, which causes #process to return false. Otherwise, #process returns true. The session itself is yielded to the block as its only argument.
If wait is nil (the default), this method will block until any of the monitored IO objects are ready to be read from or written to. If you want it to not block, you can pass 0, or you can pass any other numeric value to indicate that it should block for no more than that many seconds. Passing 0 is a good way to poll the connection, but if you do it too frequently it can make your CPU quite busy!
This will also cause all active channels to be processed once each (see Net::SSH::Connection::Channel#on_process).
# process multiple Net::SSH connections in parallel
connections = [
Net::SSH.start("host1", ...),
Net::SSH.start("host2", ...)
]
connections.each do |ssh|
ssh.exec "grep something /in/some/files"
end
condition = Proc.new { |s| s.busy? }
loop do
connections.delete_if { |ssh| !ssh.process(0.1, &condition) }
break if connections.empty?
end
199 200 201 202 203 204 205 206 207 |
# File 'lib/net/ssh/connection/session.rb', line 199 def process(wait=nil, &block) return false unless preprocess(&block) r = listeners.keys w = r.select { |w2| w2.respond_to?(:pending_write?) && w2.pending_write? } readers, writers, = Net::SSH::Compat.io_select(r, w, nil, wait) postprocess(readers, writers) end |