Class: Tortard::Bridge::Client

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/tortard/bridge/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bridgeObject

Returns the value of attribute bridge.



16
17
18
# File 'lib/tortard/bridge/client.rb', line 16

def bridge
  @bridge
end

Instance Method Details

#connectObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tortard/bridge/client.rb', line 22

def connect
	if bridge.ssl == :both || bridge.ssl == :external
		start_tls
	end

	EM.connect bridge.proxy.host, bridge.proxy.port, Connection do |c|
		c.client = self
		c.bridge = bridge

		@connection = c
	end
end

#connectedObject



47
48
49
50
51
52
53
54
55
# File 'lib/tortard/bridge/client.rb', line 47

def connected
	Tortard.log "connected to #{bridge.from}"

	buffer, @buffer = @buffer, nil

	buffer.each {|data|
		@connection.send_data data
	}
end

#disconnectObject



43
44
45
# File 'lib/tortard/bridge/client.rb', line 43

def disconnect
	close_connection_after_writing
end

#post_initObject



18
19
20
# File 'lib/tortard/bridge/client.rb', line 18

def post_init
	@buffer = []
end

#receive_data(data) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/tortard/bridge/client.rb', line 35

def receive_data (data)
	if @buffer
		@buffer << data
	else
		@connection.send_data data
	end
end

#received(data) ⇒ Object



57
58
59
# File 'lib/tortard/bridge/client.rb', line 57

def received (data)
	send_data data
end

#unbindObject



61
62
63
# File 'lib/tortard/bridge/client.rb', line 61

def unbind
	@connection.close_connection_after_writing if @connection
end