From 0b92fa0e9326a395e3b5368091e2008be2ba8ae3 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 15 Oct 2011 03:27:25 +0200 Subject: [PATCH] net: fix connect queue bugs This commit fixes two bugs in the handling of write requests when the connect() call is still in progress. 1. The deferred write request's size was counted twice towards `.bytesWritten`. 2. The callback was not called. After connecting, `Socket.write()` was called with three arguments (data, encoding, cb) but it ignored the third argument. Coincidentally fixes test/simple/test-net-connect-buffer.js. --- lib/net.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/net.js b/lib/net.js index cb8e25ed60..4467654802 100644 --- a/lib/net.js +++ b/lib/net.js @@ -399,6 +399,12 @@ Socket.prototype.write = function(data, arg1, arg2) { return false; } + return this._write(data, encoding, cb); +}; + + +Socket.prototype._write = function(data, encoding, cb) { + // `encoding` is unused right now, `data` is always a buffer. var writeReq = this._handle.write(data); if (!writeReq) { @@ -557,7 +563,7 @@ function afterConnect(status, handle, req) { if (self._connectQueue) { debug('Drain the connect queue'); for (var i = 0; i < self._connectQueue.length; i++) { - self.write.apply(self, self._connectQueue[i]); + self._write.apply(self, self._connectQueue[i]); } self._connectQueueCleanUp(); }