|
@ -652,13 +652,20 @@ Object.defineProperty(Stream.prototype, 'readyState', { |
|
|
// something was queued. If data was queued, then the "drain" event will
|
|
|
// something was queued. If data was queued, then the "drain" event will
|
|
|
// signal when it has been finally flushed to socket.
|
|
|
// signal when it has been finally flushed to socket.
|
|
|
Stream.prototype.write = function (data, encoding, fd) { |
|
|
Stream.prototype.write = function (data, encoding, fd) { |
|
|
if (this._writeQueue && this._writeQueue.length) { |
|
|
if (this._connecting || (this._writeQueue && this._writeQueue.length)) { |
|
|
|
|
|
if (!this._writeQueue) { |
|
|
|
|
|
this._writeQueue = []; |
|
|
|
|
|
this._writeQueueEncoding = []; |
|
|
|
|
|
this._writeQueueFD = []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Slow. There is already a write queue, so let's append to it.
|
|
|
// Slow. There is already a write queue, so let's append to it.
|
|
|
if (this._writeQueueLast() === END_OF_FILE) { |
|
|
if (this._writeQueueLast() === END_OF_FILE) { |
|
|
throw new Error('Stream.end() called already; cannot write.'); |
|
|
throw new Error('Stream.end() called already; cannot write.'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (typeof data == 'string' && |
|
|
if (typeof data == 'string' && |
|
|
|
|
|
this._writeQueueEncoding.length && |
|
|
this._writeQueueEncoding[this._writeQueueEncoding.length-1] === encoding) { |
|
|
this._writeQueueEncoding[this._writeQueueEncoding.length-1] === encoding) { |
|
|
// optimization - concat onto last
|
|
|
// optimization - concat onto last
|
|
|
this._writeQueue[this._writeQueue.length-1] += data; |
|
|
this._writeQueue[this._writeQueue.length-1] += data; |
|
@ -864,6 +871,14 @@ function doConnect (socket, port, host) { |
|
|
socket.destroy(e); |
|
|
socket.destroy(e); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (socket._writeQueue && socket._writeQueue.length) { |
|
|
|
|
|
// Flush socket in case any writes are queued up while connecting.
|
|
|
|
|
|
// ugly
|
|
|
|
|
|
_doFlush.call(socket._writeWatcher); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} else if (errno != EINPROGRESS) { |
|
|
} else if (errno != EINPROGRESS) { |
|
|
socket.destroy(errnoException(errno, 'connect')); |
|
|
socket.destroy(errnoException(errno, 'connect')); |
|
|
} |
|
|
} |
|
@ -886,6 +901,7 @@ Stream.prototype.connect = function () { |
|
|
timeout.active(socket); |
|
|
timeout.active(socket); |
|
|
|
|
|
|
|
|
self._connecting = true; // set false in doConnect
|
|
|
self._connecting = true; // set false in doConnect
|
|
|
|
|
|
self.writable = true; |
|
|
|
|
|
|
|
|
var port = toPort(arguments[0]); |
|
|
var port = toPort(arguments[0]); |
|
|
if (port === false) { |
|
|
if (port === false) { |
|
|