Created
December 11, 2015 09:40
-
-
Save HoneyryderChuck/ceaa809ff2bc9a461484 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SEM | |
module Celluloid | |
module IOExtensions | |
NEARZERO = 0.00001 | |
def self.wait(t = nil) | |
if t | |
time = t.zero? ? NEARZERO : t | |
Celluloid.timeout(time) { yield } | |
else | |
yield | |
end | |
rescue ::Timeout::Error, | |
::Celluloid::TaskTimeout | |
nil | |
end | |
def self.select(read_array, write_array = nil, error_array = nil, tout = nil) | |
wait(tout) do | |
readers = read_array | |
writers = write_array | |
writers = write_array.map { |w| w.wait_writable ; w } if write_array | |
readers = (writers ? read_array-writers : read_array).map { |r| r.wait_readable ; r } | |
writers ? [ readers, writers ] : [readers] | |
end | |
end | |
end | |
module SSHCompatExtensions | |
def io_select_with_celluloid(*params) | |
if ::Celluloid::IO.evented? | |
IOExtensions.select(*params) | |
else | |
io_select_without_celluloid(*params) | |
end | |
end | |
end | |
end | |
end | |
module Net::SSH | |
Compat.class_eval do | |
extend SEM::Celluloid::SSHCompatExtensions | |
class << self | |
alias_method :io_select_without_celluloid, :io_select | |
alias_method :io_select, :io_select_with_celluloid | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment