Class: Rcon::SocketWrapper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/rcon/socket_wrapper.rb

Overview

Simple wrapper to give some convenience methods around sockets.

Instance Method Summary collapse

Instance Method Details

#deliver_packet(packet) ⇒ Integer

deliver the packet to the server if the socket is ready to be written.

Parameters:

  • packet (Packet)

    the packet to be delivered

Returns:

  • (Integer)

    the number of bytes sent

Raises:


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

Returns:

  • (Array)

    containing socket in first subarray if socket is ready to read

Raises:


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

Returns:

  • (Array)

    containing socket in second subarray if socket is ready to write

Raises:


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