Class: Bones::RPC::Celluloid::Connection::Reader
- Inherits:
-
Object
- Object
- Bones::RPC::Celluloid::Connection::Reader
- Includes:
- Celluloid::IO
- Defined in:
- lib/bones/rpc/celluloid/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.
11 12 13 14 15 16 17 |
# File 'lib/bones/rpc/celluloid/connection/reader.rb', line 11 def initialize(connection, socket, adapter) @connection = connection @socket = socket @adapter = adapter @buffer = "" async.read end |
Instance Method Details
#parse(data) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bones/rpc/celluloid/connection/reader.rb', line 19 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
34 35 36 37 38 39 40 41 |
# File 'lib/bones/rpc/celluloid/connection/reader.rb', line 34 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
43 44 45 |
# File 'lib/bones/rpc/celluloid/connection/reader.rb', line 43 def send() @connection.node.() end |