Module: Net::SSH::Test::Extensions::IO::ClassMethods

Defined in:
lib/net/ssh/test/extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(obj) ⇒ Object

:nodoc:



135
136
137
138
139
140
# File 'lib/net/ssh/test/extensions.rb', line 135

def self.extended(obj) # :nodoc:
  class << obj
    alias_method :select_for_real, :select
    alias_method :select, :select_for_test
  end
end

Instance Method Details

#select_for_test(readers = nil, writers = nil, errors = nil, wait = nil) ⇒ Object

The testing version of ::IO.select. Assumes that all readers, writers, and errors arrays are either nil, or contain only objects that mix in Net::SSH::Test::Extensions::BufferedIo.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/net/ssh/test/extensions.rb', line 145

def select_for_test(readers = nil, writers = nil, errors = nil, wait = nil)
  return select_for_real(readers, writers, errors, wait) unless Net::SSH::Test::Extensions::IO.extension_enabled?

  ready_readers = Array(readers).select { |r| r.select_for_read? }
  ready_writers = Array(writers).select { |r| r.select_for_write? }
  ready_errors  = Array(errors).select  { |r| r.select_for_error? }

  return [ready_readers, ready_writers, ready_errors] if ready_readers.any? || ready_writers.any? || ready_errors.any?

  processed = 0
  Array(readers).each do |reader|
    processed += 1 if reader.idle!
  end

  raise "no readers were ready for reading, and none had any incoming packets" if processed == 0 && wait != 0

  [[], [], []]
end