class Plux::Reactor::Worker

Public Class Methods

new(socket, q) click to toggle source
# File lib/plux/reactor.rb, line 51
def initialize(socket, q)
  @parser = Parser.new
  @socket = socket
  @q = q
end

Public Instance Methods

process() click to toggle source
# File lib/plux/reactor.rb, line 57
def process
  stream = @socket.read_nonblock(Parser::STREAM_MAX_LEN, exception: false)
  return true if stream == :wait_readable

  msgs = @parser.decode(stream)
  last_msg = msgs.pop

  msgs.each{ |msg| @q << msg }
  if last_msg == Parser::LAST_MSG
    @socket.close
    return false
  end
  @q << last_msg

  true
end