Class: Plux::Reactor::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/plux/reactor.rb

Instance Method Summary collapse

Constructor Details

#initialize(socket, q) ⇒ Worker

Returns a new instance of Worker.



51
52
53
54
55
# File 'lib/plux/reactor.rb', line 51

def initialize(socket, q)
  @parser = Parser.new
  @socket = socket
  @q = q
end

Instance Method Details

#processObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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