diff options
Diffstat (limited to 'lib/net.js')
-rw-r--r-- | lib/net.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/net.js b/lib/net.js index 35223c3396..4821665218 100644 --- a/lib/net.js +++ b/lib/net.js @@ -161,7 +161,8 @@ function Socket(options) { initSocketHandle(this); - this._pendingWrite = null; + this._pendingData = null; + this._pendingEncoding = ''; // handle strings directly this._writableState.decodeStrings = false; @@ -583,22 +584,20 @@ Socket.prototype.write = function(chunk, encoding, cb) { }; -Socket.prototype._write = function(dataEncoding, cb) { - // assert(Array.isArray(dataEncoding)); - var data = dataEncoding[0]; - var encoding = dataEncoding[1] || 'utf8'; - +Socket.prototype._write = function(data, encoding, cb) { // If we are still connecting, then buffer this for later. // The Writable logic will buffer up any more writes while // waiting for this one to be done. if (this._connecting) { - this._pendingWrite = dataEncoding; + this._pendingData = data; + this._pendingEncoding = encoding; this.once('connect', function() { - this._write(dataEncoding, cb); + this._write(data, encoding, cb); }); return; } - this._pendingWrite = null; + this._pendingData = null; + this._pendingEncoding = ''; timers.active(this); @@ -651,15 +650,16 @@ function createWriteReq(handle, data, encoding) { Socket.prototype.__defineGetter__('bytesWritten', function() { var bytes = this._bytesDispatched, state = this._writableState, - pending = this._pendingWrite; + data = this._pendingData, + encoding = this._pendingEncoding; state.buffer.forEach(function(el) { el = el[0]; bytes += Buffer.byteLength(el[0], el[1]); }); - if (pending) - bytes += Buffer.byteLength(pending[0], pending[1]); + if (data) + bytes += Buffer.byteLength(data, encoding); return bytes; }); |