Browse Source

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.
v0.7.4-release
Ben Noordhuis 13 years ago
parent
commit
0b92fa0e93
  1. 8
      lib/net.js

8
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();
}

Loading…
Cancel
Save