Browse Source

Random net.js clean ups

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
3e969f0f74
  1. 16
      lib/net.js

16
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) {

Loading…
Cancel
Save