Class: Cocaine::Connection
- Defined in:
- lib/cocaine/asio/connection.rb
Instance Attribute Summary collapse
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #connection_completed ⇒ Object
-
#initialize(decoder = nil) ⇒ Connection
constructor
A new instance of Connection.
- #receive_data(raw_data) ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize(decoder = nil) ⇒ Connection
Returns a new instance of Connection.
35 36 37 38 39 |
# File 'lib/cocaine/asio/connection.rb', line 35 def initialize(decoder=nil) @decoder = decoder || Cocaine::Decoder.new @state = :connecting @hooks = HookManager.new end |
Instance Attribute Details
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
33 34 35 |
# File 'lib/cocaine/asio/connection.rb', line 33 def hooks @hooks end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
33 34 35 |
# File 'lib/cocaine/asio/connection.rb', line 33 def state @state end |
Instance Method Details
#connection_completed ⇒ Object
41 42 43 44 |
# File 'lib/cocaine/asio/connection.rb', line 41 def connection_completed @state = :connected @hooks.call :connected end |
#receive_data(raw_data) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/cocaine/asio/connection.rb', line 51 def receive_data(raw_data) @decoder.feed(raw_data) do |id, session, data| = Cocaine::ProtocolFactory.create(id, data) $log.debug "received message #{{:type => .id, :session => session}}" @hooks.call :message, session, end end |
#unbind ⇒ Object
46 47 48 49 |
# File 'lib/cocaine/asio/connection.rb', line 46 def unbind @state = :disconnected @hooks.call :disconnected, error? end |