Class LineIO
In: lib/network/lineio.rb
Parent: SockIO
LineIO
SockIO
dot/f_27.png

The LineIO class implements a line-orient interface for TCP sockets. It‘s a specialization of sockio. This class is intended for line-oriented protocols.

Methods

new   read  

Public Class methods

Creates a new LineIO object

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

[Source]

# File lib/network/lineio.rb, line 27
  def initialize(sock, bufsize=8192)
    super(sock,bufsize)
  end

Public Instance methods

read will receive a set of lines from the socket. A line may be terminated by CRLF, CRNUL, LFCR, CR, or LF. Not yet terminated lines are left in the @inbuffer.

return
One or more complete lines or nil.
IOError
A sockets error occurred.
EOFError
The connection has closed normally.

[Source]

# File lib/network/lineio.rb, line 38
  def read
    @inbuffer << @sock.recv(@bufsize)
    @inbuffer.gsub!(/\r\n|\r\x00|\n\r|\r|\n/,"\n")
    pos = @inbuffer.rindex("\n")
    if pos
      ln = @inbuffer.slice!(0..pos)
      return ln
    end
    nil
  end

[Validate]