Permalink
Browse files

don't insert bodies onto the deferred body queue multiple times

  • Loading branch information...
1 parent ba90dde commit bf3136d57933c93b540b8cb45c8aafb82061bcee @smparkes committed Apr 15, 2010
Showing with 27 additions and 5 deletions.
  1. +6 −1 lib/kibosh/response.rb
  2. +11 −4 lib/kibosh/session.rb
  3. +10 −0 lib/kibosh/session/stream.rb
View
@@ -48,12 +48,17 @@ def body
document = Nokogiri::XML::Document.new
body = document.create_element("body")
body.attributes.merge! :xmlns => 'http://jabber.org/protocol/httpbind'
+ # puts "new body #{body.object_id}"
document.root = body
end
end
def xml
- @body.document.to_xml :save_with => 0
+ # puts "sending resp #{self.object_id} body #{@body.object_id}"
+ v = @body.document.to_xml :save_with => 0
+ # @body["sent"] = "true"
+ # puts "sent #{@body}"
+ v
end
end
View
@@ -179,14 +179,16 @@ def respond body
# p "respond"
raise "hell" if !body
if response = @responses.shift
- # p "respond pop"
+ # puts "response pop #{response.object_id} #{body.object_id}"
raise "hell" if !response.deferred || response.delivered
response.body = body
response._deliver
body = nil
else
- # p "respond push"
- @bodies << body
+ raise "hell" if !body
+ # puts "body push #{body.object_id} #{@bodies.length}"
+ # puts caller(0)
+ @bodies << body unless @bodies.include? body
end
check_responses 0
body
@@ -195,17 +197,21 @@ def respond body
def defer response
# puts "defer: now "
raise "hell" if response.deliver_fired || response.deferred
+ # puts "b4 #{@bodies.length}"
if body = @bodies.shift
+ # puts "body pop #{body.object_id}"
streams[body["stream"]].lock body
response.body = body
else
- # puts "deferring: #{@responses.length}"
+ # puts "deferring: #{@responses.length} #{response.object_id} #{@bodies.length}"
response.deferred = true
response.on_close do
response._cancel!
+ # puts "response del #{response.object_id}"
@responses.delete response
check_responses 0
end
+ # puts "response push #{response.object_id}"
@responses << response
check_responses 0
end
@@ -223,6 +229,7 @@ def check_responses expect
(@responses.first.created_at + wait) <= now)
ran = true
deferred = @responses.shift
+ # puts "response pop #{deferred.object_id}"
document = Nokogiri::XML::Document.new
deferred.body = body = document.create_element("body")
body["xmlns"] = 'http://jabber.org/protocol/httpbind'
@@ -47,20 +47,30 @@ def body
begin
document = Nokogiri::XML::Document.new
body = document.create_element("body")
+ # puts "new body #{body.object_id}"
body["xmlns"] = 'http://jabber.org/protocol/httpbind'
body["stream"] = id
document.root = body
end
+ # puts "current body #{@body.object_id}"
+ # raise "hell" if @body["sent"]
+ @body
end
def body= body
raise "hell" if @body || !body.nil?
+ # puts "set body #{body.object_id}"
@body = body
end
def lock body
+ # puts "lock? #{body.object_id} #{@body.object_id} (#{body['sent']})"
+ # raise "hell" if body['sent']
if body.object_id == @body.object_id
+ # puts "locking #{@body}"
@body = nil
+ else
+ # puts "not locking #{@body}"
end
end

0 comments on commit bf3136d

Please sign in to comment.