From ba46c4c2bf6ab0bc7790e0d8917a55c31f279698 Mon Sep 17 00:00:00 2001 From: Marek Majkowski Date: Thu, 25 Aug 2011 15:07:34 +0100 Subject: [PATCH] Abstracted code responsible for killing polling connection after X bytes were send. --- src/trans-xhr.coffee | 15 ++------------- src/transport.coffee | 13 +++++++++++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/trans-xhr.coffee b/src/trans-xhr.coffee index 3d251a57..cb79f6fe 100644 --- a/src/trans-xhr.coffee +++ b/src/trans-xhr.coffee @@ -39,21 +39,10 @@ class XhrPollingReceiver extends transport.ResponseReceiver class XhrStreamingReceiver extends transport.ResponseReceiver protocol: "xhr" - - constructor: -> - @send_bytes = 0 - super + max_response_size: 128*1024 doSendFrame: (payload) -> - @send_bytes += payload.length + 1 - if @send_bytes > 128*1024 - if @session - @session.unregister() - r = super(payload + '\n') - if @send_bytes > 128*1024 - @response.end() - return r - + return super(payload + '\n') exports.app = diff --git a/src/transport.coffee b/src/transport.coffee index a500f43c..5921e512 100644 --- a/src/transport.coffee +++ b/src/transport.coffee @@ -189,18 +189,27 @@ class ConnectionReceiver extends GenericReceiver # Write stuff to response, using chunked encoding if possible. class ResponseReceiver extends GenericReceiver + max_response_size: undefined + constructor: (@response) -> + @curr_response_size = 0 try @response.connection.setKeepAlive(true, 5000) catch x super (@response) doSendFrame: (payload) -> + @curr_response_size += payload.length + r = false try @response.write(payload) - return true + r = true catch x - return false + if @max_response_size and @curr_response_size >= @max_response_size + if @session + @session.unregister() + @response.end() + return r didClose: -> super