Class SockIO
In: lib/network/sockio.rb
Parent: Object
SockIO
dot/f_41.png

The SockIO class implements the low level interface for TCP sockets.

Methods

Public Class methods

Creates a new SockIO object

sock
The socket which will be used
bufsize
The size of the buffer to use (default is 8192)

[Source]

# File lib/network/sockio.rb, line 25
  def initialize(sock, bufsize=8192)
    @sock,@bufsize=sock,bufsize
    @inbuffer = ""
    @outbuffer = ""
  end

Public Instance methods

read will receive a data from the socket.

return
The data read
IOError
A sockets error occurred.
EOFError
The connection has closed normally.

[Source]

# File lib/network/sockio.rb, line 36
  def read
    @sock.recv(@bufsize)
  end

read_flush will kill the input buffer

[Source]

# File lib/network/sockio.rb, line 63
  def read_flush
    @inbuffer = ""
  end

read_urgent will receive urgent data from the socket.

return
The data read
IOError
A sockets error occurred.
EOFError
The connection has closed normally.

[Source]

# File lib/network/sockio.rb, line 72
  def read_urgent
    @sock.recv(@bufsize, Socket::MSG_OOB)
  end

write will transmit a message to the socket

msg
The message string to be sent.
return
false if more data to be written, true if all data written
IOError
A sockets error occurred.
EOFError
The connection has closed normally.

[Source]

# File lib/network/sockio.rb, line 46
  def write(msg)
    @outbuffer << msg
    n = @sock.send(@outbuffer, 0)
    # save unsent data for next call
    @outbuffer.slice!(0...n)
    @outbuffer.size == 0
  rescue Exception
    @outbuffer = ""  # Does it really matter?
    raise
  end

write_flush will kill the output buffer

[Source]

# File lib/network/sockio.rb, line 58
  def write_flush
    @outbuffer = ""
  end

write_urgent will write urgent data to the socket.

msg
The message string to be sent.
IOError
A sockets error occurred.
EOFError
The connection has closed normally.

[Source]

# File lib/network/sockio.rb, line 81
  def write_urgent(msg)
    @sock.send(msg, Socket::MSG_OOB)
  end

[Validate]