commit e8ad8616fca69aa49fc49eb22a4a9302fa2bc2d0
parent 6c964c2a261871dcf9978233901f6c48be7ed75f
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date: Sun, 6 Jun 2010 08:51:02 -0700
protocol debugging code
Diffstat:
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/lib/sup/protocol.rb b/lib/sup/protocol.rb
@@ -7,9 +7,12 @@ class EM::P::Redwood < EM::Connection
VERSION = 1
ENCODINGS = %w(marshal json)
+ attr_reader :debug
+
def initialize *args
@state = :negotiating
@version_buf = ""
+ @debug = false
super
end
@@ -26,7 +29,11 @@ class EM::P::Redwood < EM::Connection
receive_data x
end
else
- @filter.decode(data).each { |msg| receive_message *msg }
+ @filter.decode(data).each do |msg|
+ puts "#{self.class.name} received: #{msg.inspect}" if @debug
+ validate_message *msg
+ receive_message *msg
+ end
end
end
@@ -40,6 +47,8 @@ class EM::P::Redwood < EM::Connection
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
@@ -47,12 +56,18 @@ class EM::P::Redwood < EM::Connection
fail "unimplemented"
end
- def receive_message type, params
+ def receive_message type, tag, params
fail "unimplemented"
end
private
+ def validate_message type, tag, params
+ fail unless type.is_a? String or type.is_a? Symbol
+ fail unless tag.is_a? String or tag.is_a? Integer
+ fail unless params.is_a? Hash
+ end
+
def parse_version l
l =~ /^Redwood\s+(\d+)\s+([\w,]+)\s+([\w,]+)$/ or fail "unexpected banner #{l.inspect}"
version, encodings, extensions = $1.to_i, $2, $3