Sha256: 8601af88e1a4b0924a105e3749eb7e83fbf55771450ed7d8201257997e11d8f8

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

# Mixin to add methods to IO so that they will also be inherited by TCPSocket.
class IO
   # Checks if the socket is ready to be read from.
   # @param [Integer] timeout_in_seconds Amount of time to wait for the sever to respond, in seconds. Must be positive or +nil+.
   # @return [Boolean] +true+ if the socket is ready to be read from, +false+ otherwise.
   def ready_to_read?(timeout_in_seconds=nil)
      read_array = [self]
      write_array = nil
      error_array = nil

      select(read_array, write_array, error_array, timeout_in_seconds)
   end
   
   # Checks if the socket is ready to be written to.
   # @param [Integer] timeout_in_seconds Amount of time to wait for the sever to respond, in seconds. Must be positive or +nil+.
   # @return [Boolean] +true+ if the socket is ready to be written to, +false+ otherwise.
   def ready_to_write?(timeout_in_seconds=nil)
      read_array = nil
      write_array = [self]
      error_array = nil
      
      select(read_array, write_array, error_array, timeout_in_seconds)
   end
   
   private
   
   # @see IO#select
   def select(read_array, write_array=[], error_array=[], timeout_in_seconds=nil)
      IO.select(read_array, write_array, error_array, timeout_in_seconds) != nil
   end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
acpc_poker_basic_proxy-1.0.0 lib/acpc_poker_basic_proxy/mixins/socket_with_ready_methods.rb
acpc_poker_basic_proxy-0.0.3 lib/acpc_poker_basic_proxy/mixins/socket_with_ready_methods.rb
acpc_poker_basic_proxy-0.0.2 lib/acpc_poker_basic_proxy/mixins/socket_with_ready_methods.rb
acpc_poker_basic_proxy-0.0.1 lib/acpc_poker_basic_proxy/mixins/socket_with_ready_methods.rb