Class: Bones::RPC::Connection::Reader
- Inherits:
-
Object
- Object
- Bones::RPC::Connection::Reader
- Includes:
- Celluloid::IO
- Defined in:
- lib/bones/rpc/connection/reader.rb
Overview
Instance Method Summary collapse
-
#initialize(connection, socket, adapter) ⇒ Reader
constructor
A new instance of Reader.
- #parse(data) ⇒ Object
- #read ⇒ Object
- #send(message) ⇒ Object
Constructor Details
#initialize(connection, socket, adapter) ⇒ Reader
Returns a new instance of Reader.
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
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 |
#read ⇒ Object
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.}", "n/a") terminate end |
#send(message) ⇒ Object
42 43 44 |
# File 'lib/bones/rpc/connection/reader.rb', line 42 def send() @connection.node.() end |