Class: Bones::RPC::Connection::Reader

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO
Defined in:
lib/bones/rpc/connection/reader.rb

Overview

Since:

  • 2.0.0

Instance Method Summary collapse

Constructor Details

#initialize(connection, socket, adapter) ⇒ Reader

Returns a new instance of Reader.

Since:

  • 2.0.0



10
11
12
13
14
15
16
# File 'lib/bones/rpc/connection/reader.rb', line 10

def initialize(connection, socket, adapter)
  @connection = connection
  @socket = socket
  @adapter = adapter
  @buffer = ""
  async.read
end

Instance Method Details

#parse(data) ⇒ Object

Since:

  • 2.0.0



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bones/rpc/connection/reader.rb', line 18

def parse(data)
  @buffer << data
  if @buffer.empty?
    async.read
  else
    parser = Bones::RPC::Parser.new(@buffer, @adapter)
    begin
      loop { async.send parser.read }
    rescue EOFError
      @buffer.replace(parser.buffer.to_str)
    end
    async.read
  end
end

#readObject

Since:

  • 2.0.0



33
34
35
36
37
38
39
40
# File 'lib/bones/rpc/connection/reader.rb', line 33

def read
  loop do
    async.parse @socket.readpartial(4096)
  end
rescue EOFError, Errors::ConnectionFailure => e
  Loggable.warn("  BONES-RPC:", "#{@connection.node.address.resolved} Reader terminating: #{e.message}", "n/a")
  terminate
end

#send(message) ⇒ Object

Since:

  • 2.0.0



42
43
44
# File 'lib/bones/rpc/connection/reader.rb', line 42

def send(message)
  @connection.node.handle_message(message)
end