|
|
@ -2,8 +2,7 @@ var sys = require("sys"); |
|
|
|
var fs = require("fs"); |
|
|
|
var events = require("events"); |
|
|
|
|
|
|
|
var debugLevel = 0; |
|
|
|
if ('NODE_DEBUG' in process.ENV) debugLevel = 1; |
|
|
|
var debugLevel = process.env['NODE_DEBUG'] ? 1 : 0; |
|
|
|
function debug () { |
|
|
|
if (debugLevel > 0) sys.error.apply(this, arguments); |
|
|
|
} |
|
|
@ -102,7 +101,7 @@ var timeout = new (function () { |
|
|
|
// the main function - creates lists on demand and the watchers associated
|
|
|
|
// with them.
|
|
|
|
function insert (socket, msecs) { |
|
|
|
socket._idleStart = process.now; |
|
|
|
socket._idleStart = new Date(); |
|
|
|
socket._idleTimeout = msecs; |
|
|
|
|
|
|
|
if (!msecs) return; |
|
|
@ -122,13 +121,14 @@ var timeout = new (function () { |
|
|
|
debug('timeout callback ' + msecs); |
|
|
|
// TODO - don't stop and start the watcher all the time.
|
|
|
|
// just set its repeat
|
|
|
|
var now = process.now; |
|
|
|
var now = new Date(); |
|
|
|
debug("now: " + now); |
|
|
|
var first; |
|
|
|
while (first = peek(list)) { |
|
|
|
var diff = now - first._idleStart; |
|
|
|
if (diff < msecs) { |
|
|
|
list.again(msecs - diff); |
|
|
|
debug(msecs + ' list wait'); |
|
|
|
debug(msecs + ' list wait because diff is ' + diff); |
|
|
|
return; |
|
|
|
} else { |
|
|
|
remove(first); |
|
|
@ -190,7 +190,7 @@ var timeout = new (function () { |
|
|
|
insert(socket, msecs); |
|
|
|
} else { |
|
|
|
// inline append
|
|
|
|
socket._idleStart = process.now; |
|
|
|
socket._idleStart = new Date(); |
|
|
|
socket._idleNext._idlePrev = socket._idlePrev; |
|
|
|
socket._idlePrev._idleNext = socket._idleNext; |
|
|
|
socket._idleNext = list._idleNext; |
|
|
@ -280,7 +280,7 @@ function initStream (self) { |
|
|
|
allocNewPool(); |
|
|
|
} |
|
|
|
|
|
|
|
//debug('pool.used ' + pool.used);
|
|
|
|
debug('pool.used ' + pool.used); |
|
|
|
var bytesRead; |
|
|
|
|
|
|
|
try { |
|
|
@ -293,7 +293,7 @@ function initStream (self) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//debug('bytesRead ' + bytesRead + '\n');
|
|
|
|
debug('bytesRead ' + bytesRead + '\n'); |
|
|
|
|
|
|
|
if (bytesRead == 0) { |
|
|
|
self.readable = false; |
|
|
@ -449,12 +449,12 @@ Stream.prototype._writeString = function (data, encoding) { |
|
|
|
buffer.used += bytesWritten; |
|
|
|
self._writeQueueSize += bytesWritten; |
|
|
|
|
|
|
|
//debug('charsWritten ' + charsWritten);
|
|
|
|
//debug('buffer.used ' + buffer.used);
|
|
|
|
debug('charsWritten ' + charsWritten); |
|
|
|
debug('buffer.used ' + buffer.used); |
|
|
|
|
|
|
|
// If we didn't finish, then recurse with the rest of the string.
|
|
|
|
if (charsWritten < data.length) { |
|
|
|
//debug('recursive write');
|
|
|
|
debug('recursive write'); |
|
|
|
self._writeString(data.slice(charsWritten), encoding); |
|
|
|
} |
|
|
|
}; |
|
|
@ -499,8 +499,6 @@ Stream.prototype.write = function (data, encoding) { |
|
|
|
encoding = (encoding || 'utf8').toLowerCase(); |
|
|
|
var bytes = Buffer.byteLength(data, encoding); |
|
|
|
|
|
|
|
//debug('write string :' + JSON.stringify(data));
|
|
|
|
|
|
|
|
if (!pool) allocNewPool(); |
|
|
|
|
|
|
|
if (pool.length - pool.used < bytes) { |
|
|
@ -620,7 +618,6 @@ Stream.prototype.flush = function () { |
|
|
|
|
|
|
|
timeout.active(self); |
|
|
|
|
|
|
|
|
|
|
|
if (bytesWritten === null) { |
|
|
|
// EAGAIN
|
|
|
|
debug('write EAGAIN'); |
|
|
|