Class: Blur::Network::Connection

Inherits:
EM::Protocols::LineAndTextProtocol
  • Object
show all
Defined in:
library/blur/network/connection.rb

Overview

The Connection class inherits the LineAndText protocol bundled with the eventmachine library.

It merely acts as a receiving handler for all messages eventmachine throws at it through its lifetime.

See Also:

  • EventMachine::Protocols::LineAndTextProtocol
  • EventMachine::Connection

Instance Method Summary collapse

Constructor Details

#initialize(network) ⇒ Connection

EventMachine instantiates this class, and then sends event messages to that instance.



19
20
21
22
23
24
# File 'library/blur/network/connection.rb', line 19

def initialize network
  @network = network
  @connected = false

  super
end

Instance Method Details

#connection_completedObject

Called once the connection is finally established.



48
49
50
# File 'library/blur/network/connection.rb', line 48

def connection_completed
  @network.connected! unless @network.secure?
end

#established?Boolean

Check whether or not connection is established.



15
# File 'library/blur/network/connection.rb', line 15

def established?; @connected == true end

#post_initObject

Called when a new connection is being set up, all we're going to use it for is to enable SSL/TLS on our connection.



28
29
30
# File 'library/blur/network/connection.rb', line 28

def post_init
  start_tls if @network.secure?
end

#receive_line(line) ⇒ Object

Called when a line was received, the connection sends it to the network delegate which then sends it to the client.



34
35
36
37
# File 'library/blur/network/connection.rb', line 34

def receive_line line
  command = Command.parse line
  @network.got_command command
end

#ssl_handshake_completedObject

Called when the SSL handshake was completed with the remote server, the reason we tell the network that we're connected here is to ensure that the SSL/TLS encryption succeeded before we start talking nonsense to the server.



43
44
45
# File 'library/blur/network/connection.rb', line 43

def ssl_handshake_completed
  connected!
end

#unbindObject

Called just as the connection is being terminated, either by remote or local.



54
55
56
57
58
59
# File 'library/blur/network/connection.rb', line 54

def unbind
  @connected = false
  @network.disconnected!

  super
end