Random net.js clean ups
This commit is contained in:
parent
0c64768cb4
commit
3e969f0f74
14
lib/net.js
14
lib/net.js
@ -416,12 +416,12 @@ Stream.prototype._writeString = function (data, encoding) {
|
|||||||
buffer = self._allocateSendBuffer();
|
buffer = self._allocateSendBuffer();
|
||||||
} else {
|
} else {
|
||||||
buffer = self.__writeQueueLast();
|
buffer = self.__writeQueueLast();
|
||||||
if (buffer.used == buffer.length) {
|
if (buffer.length - buffer.used < 64) {
|
||||||
buffer = self._allocateSendBuffer();
|
buffer = self._allocateSendBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
encoding = encoding || 'ascii'; // default to ascii since it's faster
|
encoding = encoding || 'utf8'; // default to utf8
|
||||||
|
|
||||||
var charsWritten;
|
var charsWritten;
|
||||||
var bytesWritten;
|
var bytesWritten;
|
||||||
@ -473,7 +473,9 @@ Stream.prototype.write = function (data, encoding) {
|
|||||||
if (!self.writable) throw new Error('Stream is not writable');
|
if (!self.writable) throw new Error('Stream is not writable');
|
||||||
|
|
||||||
if (self._writeQueue && self._writeQueue.length) {
|
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 {
|
} else {
|
||||||
// The most common case. There is no write queue. Just push the data
|
// 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) {
|
if (recvBuffer.length - recvBuffer.used < bytes) {
|
||||||
// not enough room - go to slow case
|
// not enough room - go to slow case
|
||||||
return self._writeQueued(data, encoding);
|
return self._queueWrite(data, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
var charsWritten;
|
var charsWritten;
|
||||||
@ -545,8 +547,8 @@ Stream.prototype.write = function (data, encoding) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream.prototype._writeQueued = function (data, encoding) {
|
Stream.prototype._queueWrite = function (data, encoding) {
|
||||||
//debug('_writeQueued');
|
//debug('_queueWrite');
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (self.__writeQueueLast() == END_OF_FILE) {
|
if (self.__writeQueueLast() == END_OF_FILE) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user