From 3e969f0f74a65c39453db352fcd723b61b6690bb Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 19 Mar 2010 11:46:35 -0700 Subject: [PATCH] Random net.js clean ups --- lib/net.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/net.js b/lib/net.js index 447c34b258..09d88da43d 100644 --- a/lib/net.js +++ b/lib/net.js @@ -416,12 +416,12 @@ Stream.prototype._writeString = function (data, encoding) { buffer = self._allocateSendBuffer(); } else { buffer = self.__writeQueueLast(); - if (buffer.used == buffer.length) { + if (buffer.length - buffer.used < 64) { buffer = self._allocateSendBuffer(); } } - encoding = encoding || 'ascii'; // default to ascii since it's faster + encoding = encoding || 'utf8'; // default to utf8 var charsWritten; var bytesWritten; @@ -473,7 +473,9 @@ Stream.prototype.write = function (data, encoding) { if (!self.writable) throw new Error('Stream is not writable'); if (self._writeQueue && self._writeQueue.length) { - return self._writeQueued(data, encoding); // slow + // slow + // There is already a write queue, so let's append to it. + return self._queueWrite(data, encoding); } else { // The most common case. There is no write queue. Just push the data @@ -492,7 +494,7 @@ Stream.prototype.write = function (data, encoding) { if (recvBuffer.length - recvBuffer.used < bytes) { // not enough room - go to slow case - return self._writeQueued(data, encoding); + return self._queueWrite(data, encoding); } var charsWritten; @@ -502,7 +504,7 @@ Stream.prototype.write = function (data, encoding) { // ascii recvBuffer.asciiWrite(data, recvBuffer.used); } - + buffer = recvBuffer; off = recvBuffer.used; len = bytes; @@ -545,8 +547,8 @@ Stream.prototype.write = function (data, encoding) { } } -Stream.prototype._writeQueued = function (data, encoding) { - //debug('_writeQueued'); +Stream.prototype._queueWrite = function (data, encoding) { + //debug('_queueWrite'); var self = this; if (self.__writeQueueLast() == END_OF_FILE) {