Class: EM::P::Redwood
- Inherits:
-
Connection
- Object
- Connection
- EM::P::Redwood
show all
- Defined in:
- lib/sup/protocol.rb
Defined Under Namespace
Classes: JSONFilter, MarshalFilter
Constant Summary
collapse
- VERSION =
1
- ENCODINGS =
%w(marshal json)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Redwood
Returns a new instance of Redwood.
12
13
14
15
16
17
|
# File 'lib/sup/protocol.rb', line 12
def initialize *args
@state = :negotiating
@version_buf = ""
@debug = false
super
end
|
Instance Attribute Details
Returns the value of attribute debug.
10
11
12
|
# File 'lib/sup/protocol.rb', line 10
def debug
@debug
end
|
Instance Method Details
#connection_established ⇒ Object
40
41
|
# File 'lib/sup/protocol.rb', line 40
def connection_established
end
|
#receive_data(data) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/sup/protocol.rb', line 19
def receive_data data
if @state == :negotiating
@version_buf << data
if i = @version_buf.index("\n")
l = @version_buf.slice!(0..i)
receive_version *parse_version(l.strip)
x = @version_buf
@version_buf = nil
@state = :established
connection_established
receive_data x
end
else
@filter.decode(data).each do |msg|
puts "#{self.class.name} received: #{msg.inspect}" if @debug
validate_message *msg
receive_message *msg
end
end
end
|
#receive_message(type, tag, params) ⇒ Object
59
60
61
|
# File 'lib/sup/protocol.rb', line 59
def receive_message type, tag, params
fail "unimplemented"
end
|
#receive_version(l) ⇒ Object
55
56
57
|
# File 'lib/sup/protocol.rb', line 55
def receive_version l
fail "unimplemented"
end
|
#send_message(type, tag, params = {}) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/sup/protocol.rb', line 48
def send_message type, tag, params={}
fail "attempted to send message during negotiation" unless @state == :established
puts "#{self.class.name} sent: #{[type, tag, params].inspect}" if @debug
validate_message type, tag, params
send_data @filter.encode([type,tag,params])
end
|
#send_version(encodings, extensions) ⇒ Object
43
44
45
46
|
# File 'lib/sup/protocol.rb', line 43
def send_version encodings, extensions
fail if encodings.empty?
send_data "Redwood #{VERSION} #{encodings * ','} #{extensions.empty? ? :none : (extensions * ',')}\n"
end
|