diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-01-24 18:49:32 +0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-01-24 18:57:50 +0400 |
commit | e806ad39d0cf13800e21edd7ffd56f707e92b08d (patch) | |
tree | 01308f23984925f587b44b90ab5b7ee6a230eaa4 /lib | |
parent | 5988872ff1f321388cfef0be6585ad6ba7f54884 (diff) |
net, tls, http: remove socket.ondrain
Replace the ondrain hack with a regular 'drain' listener. Speeds up the
bytes/1024 http benchmark by about 1.2%.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/http.js | 14 | ||||
-rw-r--r-- | lib/net.js | 2 | ||||
-rw-r--r-- | lib/tls.js | 3 |
3 files changed, 8 insertions, 11 deletions
diff --git a/lib/http.js b/lib/http.js index 470981bb853..ad1e71baebb 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1406,13 +1406,15 @@ exports.get = function(options, cb) { return req; }; + +function ondrain() { + if (this._httpMessage) this._httpMessage.emit('drain'); +} + + function httpSocketSetup(socket) { - // NOTE: be sure not to use ondrain elsewhere in this file! - socket.ondrain = function() { - if (socket._httpMessage) { - socket._httpMessage.emit('drain'); - } - }; + socket.removeListener('drain', ondrain); + socket.on('drain', ondrain); } diff --git a/lib/net.js b/lib/net.js index 8b9cba22fe3..a14a00c0a80 100644 --- a/lib/net.js +++ b/lib/net.js @@ -516,8 +516,6 @@ function afterWrite(status, handle, req, buffer) { self._pendingWriteReqs--; if (self._pendingWriteReqs == 0) { - // TODO remove all uses of ondrain - this is not a good hack. - if (self.ondrain) self.ondrain(); self.emit('drain'); } diff --git a/lib/tls.js b/lib/tls.js index faf81c06649..430ef2f259c 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -461,9 +461,6 @@ CryptoStream.prototype._pull = function() { debug('drain ' + (this === this.pair.cleartext ? 'clear' : 'encrypted')); var self = this; process.nextTick(function() { - if (typeof self.ondrain === 'function') { - self.ondrain(); - } self.emit('drain'); }); this._needDrain = false; |