Class: Rcon::SocketWrapper
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Rcon::SocketWrapper
- Defined in:
- lib/rcon/socket_wrapper.rb
Overview
Simple wrapper to give some convenience methods around sockets.
Instance Method Summary collapse
-
#deliver_packet(packet) ⇒ Integer
deliver the packet to the server if the socket is ready to be written.
-
#ready_to_read? ⇒ Array
check if socket is ready to read.
-
#ready_to_write? ⇒ Array
check if socket is ready to write.
Instance Method Details
#deliver_packet(packet) ⇒ Integer
deliver the packet to the server if the socket is ready to be written.
16 17 18 |
# File 'lib/rcon/socket_wrapper.rb', line 16 def deliver_packet(packet) write(packet.to_s) if ready_to_write? end |
#ready_to_read? ⇒ Array
check if socket is ready to read
24 25 26 27 28 |
# File 'lib/rcon/socket_wrapper.rb', line 24 def ready_to_read? IO.select([__getobj__], nil, nil, TIMEOUT).tap do |io| raise Error::SocketReadTimeoutError if io.nil? end end |
#ready_to_write? ⇒ Array
check if socket is ready to write
34 35 36 37 38 |
# File 'lib/rcon/socket_wrapper.rb', line 34 def ready_to_write? IO.select(nil, [__getobj__], nil, TIMEOUT).tap do |io| raise Error::SocketWriteTimeoutError if io.nil? end end |