Class: Cocaine::Connection

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/cocaine/asio/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hooksObject (readonly)

Returns the value of attribute hooks.



33
34
35
# File 'lib/cocaine/asio/connection.rb', line 33

def hooks
  @hooks
end

#stateObject (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_completedObject



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|
    message = Cocaine::ProtocolFactory.create(id, data)
    $log.debug "received message #{{:type => message.id, :session => session}}"
    @hooks.call :message, session, message
  end
end

#unbindObject



46
47
48
49
# File 'lib/cocaine/asio/connection.rb', line 46

def unbind
  @state = :disconnected
  @hooks.call :disconnected, error?
end