From e806ad39d0cf13800e21edd7ffd56f707e92b08d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 24 Jan 2012 15:49:32 +0100 Subject: [PATCH] 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%. --- lib/http.js | 14 ++++++++------ lib/net.js | 2 -- 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;