This commit is contained in:
Ryan Dahl 2010-12-01 20:59:06 -08:00
parent e232f6e735
commit dd53ceebe4
7 changed files with 144 additions and 147 deletions

View File

@ -16,13 +16,13 @@ Stream.prototype.pipe = function (dest, options) {
} }
} }
source.on("data", ondata); source.on('data', ondata);
function ondrain() { function ondrain() {
if (source.readable) source.resume(); if (source.readable) source.resume();
} }
dest.on("drain", ondrain); dest.on('drain', ondrain);
/* /*
* If the 'end' option is not supplied, dest.end() will be called when * If the 'end' option is not supplied, dest.end() will be called when
@ -34,7 +34,7 @@ Stream.prototype.pipe = function (dest, options) {
dest.end(); dest.end();
} }
source.on("end", onend); source.on('end', onend);
} }
dest.on('close', function() { dest.on('close', function() {
@ -50,21 +50,21 @@ Stream.prototype.pipe = function (dest, options) {
if (!source.pause) { if (!source.pause) {
source.pause = function() { source.pause = function() {
source.emit("pause"); source.emit('pause');
}; };
} }
if (!source.resume) { if (!source.resume) {
source.resume = function() { source.resume = function() {
source.emit("resume"); source.emit('resume');
}; };
} }
dest.on("pause", function () { dest.on('pause', function() {
source.pause(); source.pause();
}); });
dest.on("resume", function () { dest.on('resume', function() {
if (source.readable) source.resume(); if (source.readable) source.resume();
}); });
}; };

View File

@ -18,9 +18,9 @@ StringDecoder.prototype.write = function (buffer) {
// if our last write ended with an incomplete multibyte character // if our last write ended with an incomplete multibyte character
if (this.charLength) { if (this.charLength) {
// determine how many remaining bytes this buffer has to offer for this char // determine how many remaining bytes this buffer has to offer for this char
var i = (buffer.length >= this.charLength - this.charReceived) var i = (buffer.length >= this.charLength - this.charReceived) ?
? this.charLength - this.charReceived this.charLength - this.charReceived :
: buffer.length; buffer.length;
// add the new bytes to the char buffer // add the new bytes to the char buffer
buffer.copy(this.charBuffer, this.charReceived, 0, i); buffer.copy(this.charBuffer, this.charReceived, 0, i);
@ -46,7 +46,8 @@ StringDecoder.prototype.write = function (buffer) {
// determine how many bytes we have to check at the end of this buffer // determine how many bytes we have to check at the end of this buffer
var i = (buffer.length >= 3) ? 3 : buffer.length; var i = (buffer.length >= 3) ? 3 : buffer.length;
// figure out if one of the last i bytes of our buffer announces an incomplete char // Figure out if one of the last i bytes of our buffer announces an
// incomplete char.
for (; i > 0; i--) { for (; i > 0; i--) {
c = buffer[buffer.length - i]; c = buffer[buffer.length - i];

View File

@ -1,8 +1,9 @@
var util = require("util"); var util = require('util');
var sysWarning; var sysWarning;
if (!sysWarning) { if (!sysWarning) {
sysWarning = "The 'sys' module is now called 'util'. It should have a similar interface."; sysWarning = 'The "sys" module is now called "util". ' +
'It should have a similar interface.';
// Uncomment in 2011 // Uncomment in 2011
//util.error(sysWarning); //util.error(sysWarning);
} }

View File

@ -5,12 +5,14 @@ var assert = process.assert;
* To enable debug statements for the timers do NODE_DEBUG=8 ./node script.js * To enable debug statements for the timers do NODE_DEBUG=8 ./node script.js
*/ */
var debugLevel = parseInt(process.env.NODE_DEBUG, 16); var debugLevel = parseInt(process.env.NODE_DEBUG, 16);
function debug () { var debug;
if (debugLevel & 0x8) { if (debugLevel & 0x8) {
require('util').error.apply(this, arguments); debug = function() { require('util').error.apply(this, arguments); };
} } else {
debug = function() { };
} }
// IDLE TIMEOUTS // IDLE TIMEOUTS
// //
// Because often many sockets will have the same idle timeout we will not // Because often many sockets will have the same idle timeout we will not
@ -79,7 +81,7 @@ function insert (item, msecs) {
// TODO - don't stop and start the watcher all the time. // TODO - don't stop and start the watcher all the time.
// just set its repeat // just set its repeat
var now = new Date(); var now = new Date();
debug("now: " + now); debug('now: ' + now);
var first; var first;
while (first = peek(list)) { while (first = peek(list)) {
var diff = now - first._idleStart; var diff = now - first._idleStart;

View File

@ -38,10 +38,10 @@ var inherits = require('util').inherits;
// cleartext.getCertificate() (by mirroring from pair.credentials.context) // cleartext.getCertificate() (by mirroring from pair.credentials.context)
function Server(/* [options], listener */) { function Server(/* [options], listener */) {
var options, listener; var options, listener;
if (typeof arguments[0] == "object") { if (typeof arguments[0] == 'object') {
options = arguments[0]; options = arguments[0];
listener = arguments[1]; listener = arguments[1];
} else if (typeof arguments[0] == "function") { } else if (typeof arguments[0] == 'function') {
options = {}; options = {};
listener = arguments[0]; listener = arguments[0];
} }
@ -52,9 +52,8 @@ function Server ( /* [options], listener */) {
// constructor call // constructor call
net.Server.call(this, function(socket) { net.Server.call(this, function(socket) {
var creds = crypto.createCredentials({ key: self.key, var creds = crypto.createCredentials(
cert: self.cert, { key: self.key, cert: self.cert, ca: self.ca });
ca: self.ca });
creds.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA'); creds.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA');
var pair = crypto.createPair(creds, var pair = crypto.createPair(creds,
@ -70,7 +69,7 @@ function Server ( /* [options], listener */) {
if (self.unauthorizedPeers) { if (self.unauthorizedPeers) {
self.emit('unauthorized', pair.cleartext, verifyError); self.emit('unauthorized', pair.cleartext, verifyError);
} else { } else {
console.error("REJECT PEER. verify error: %s", verifyError); console.error('REJECT PEER. verify error: %s', verifyError);
socket.destroy(); socket.destroy();
} }
} else { } else {
@ -80,13 +79,7 @@ function Server ( /* [options], listener */) {
pair.on('error', function(e) { pair.on('error', function(e) {
console.log('pair got error: ' + e); console.log('pair got error: ' + e);
// TODO better way to get error code.
if (/no shared cipher/.test(e.message)) {
;
} else {
self.emit('error', e); self.emit('error', e);
}
}); });
pair.cleartext.on('error', function(err) { pair.cleartext.on('error', function(err) {
@ -116,7 +109,7 @@ exports.createServer = function (options, listener) {
Server.prototype.setOptions = function(options) { Server.prototype.setOptions = function(options) {
if (typeof options.unauthorizedPeers == "boolean") { if (typeof options.unauthorizedPeers == 'boolean') {
this.unauthorizedPeers = options.unauthorizedPeers; this.unauthorizedPeers = options.unauthorizedPeers;
} else { } else {
this.unauthorizedPeers = false; this.unauthorizedPeers = false;

View File

@ -16,7 +16,7 @@ exports.puts = function () {
exports.debug = function(x) { exports.debug = function(x) {
process.binding('stdio').writeError("DEBUG: " + x + "\n"); process.binding('stdio').writeError('DEBUG: ' + x + '\n');
}; };
@ -31,7 +31,7 @@ var error = exports.error = function (x) {
* Echos the value of a value. Trys to print the value out * Echos the value of a value. Trys to print the value out
* in the best way possible given the different types. * in the best way possible given the different types.
* *
* @param {Object} value The object to print out * @param {Object} value The object to print out.
* @param {Boolean} showHidden Flag that shows hidden (not enumerable) * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
* properties of objects. * properties of objects.
* @param {Number} depth Depth in which to descend in object. Default is 2. * @param {Number} depth Depth in which to descend in object. Default is 2.
@ -57,15 +57,15 @@ exports.inspect = function (obj, showHidden, depth, colors) {
, 'red' : [31, 39] , 'red' : [31, 39]
, 'yellow' : [33, 39] , 'yellow' : [33, 39]
}; };
var style = { "special": "grey" var style = { 'special': 'grey'
, "number": "blue" , 'number': 'blue'
, "boolean": "blue" , 'boolean': 'blue'
, "undefined": "red" , 'undefined': 'red'
, "null": "red" , 'null': 'red'
, "string": "green" , 'string': 'green'
, "date": "magenta" , 'date': 'magenta'
//, "name": intentionally not styling //, "name": intentionally not styling
, "regexp": "cyan" , 'regexp': 'cyan'
}[styleType]; }[styleType];
if (style) { if (style) {
return '\033[' + styles[style][0] + 'm' + str + return '\033[' + styles[style][0] + 'm' + str +
@ -127,17 +127,17 @@ exports.inspect = function (obj, showHidden, depth, colors) {
// Determine the object type // Determine the object type
if (isArray(value)) { if (isArray(value)) {
type = 'Array'; type = 'Array';
braces = ["[", "]"]; braces = ['[', ']'];
} else { } else {
type = 'Object'; type = 'Object';
braces = ["{", "}"]; braces = ['{', '}'];
} }
// Make functions say that they are functions // Make functions say that they are functions
if (typeof value === 'function') { if (typeof value === 'function') {
base = (isRegExp(value)) ? ' ' + value : ' [Function' + (value.name ? ': ' + value.name : '') + ']'; base = (isRegExp(value)) ? ' ' + value : ' [Function' + (value.name ? ': ' + value.name : '') + ']';
} else { } else {
base = ""; base = '';
} }
// Make dates with properties first say the date // Make dates with properties first say the date
@ -151,9 +151,9 @@ exports.inspect = function (obj, showHidden, depth, colors) {
if (recurseTimes < 0) { if (recurseTimes < 0) {
if (isRegExp(value)) { if (isRegExp(value)) {
return stylize('' + value, "regexp"); return stylize('' + value, 'regexp');
} else { } else {
return stylize("[Object]", "special"); return stylize('[Object]', 'special');
} }
} }
@ -164,18 +164,18 @@ exports.inspect = function (obj, showHidden, depth, colors) {
if (value.__lookupGetter__) { if (value.__lookupGetter__) {
if (value.__lookupGetter__(key)) { if (value.__lookupGetter__(key)) {
if (value.__lookupSetter__(key)) { if (value.__lookupSetter__(key)) {
str = stylize("[Getter/Setter]", "special"); str = stylize('[Getter/Setter]', 'special');
} else { } else {
str = stylize("[Getter]", "special"); str = stylize('[Getter]', 'special');
} }
} else { } else {
if (value.__lookupSetter__(key)) { if (value.__lookupSetter__(key)) {
str = stylize("[Setter]", "special"); str = stylize('[Setter]', 'special');
} }
} }
} }
if (visible_keys.indexOf(key) < 0) { if (visible_keys.indexOf(key) < 0) {
name = "[" + key + "]"; name = '[' + key + ']';
} }
if (!str) { if (!str) {
if (seen.indexOf(value[key]) < 0) { if (seen.indexOf(value[key]) < 0) {
@ -206,16 +206,16 @@ exports.inspect = function (obj, showHidden, depth, colors) {
name = JSON.stringify('' + key); name = JSON.stringify('' + key);
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
name = name.substr(1, name.length - 2); name = name.substr(1, name.length - 2);
name = stylize(name, "name"); name = stylize(name, 'name');
} else { } else {
name = name.replace(/'/g, "\\'") name = name.replace(/'/g, "\\'")
.replace(/\\"/g, '"') .replace(/\\"/g, '"')
.replace(/(^"|"$)/g, "'"); .replace(/(^"|"$)/g, "'");
name = stylize(name, "string"); name = stylize(name, 'string');
} }
} }
return name + ": " + str; return name + ': ' + str;
}); });
seen.pop(); seen.pop();
@ -235,8 +235,8 @@ exports.inspect = function (obj, showHidden, depth, colors) {
+ ' ' + ' '
+ output.join(',\n ') + output.join(',\n ')
+ ' ' + ' '
+ braces[1] + braces[1];
;
} else { } else {
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
} }
@ -255,10 +255,10 @@ function isArray (ar) {
function isRegExp(re) { function isRegExp(re) {
var s = ""+re; var s = ''+ re;
return re instanceof RegExp // easy case return re instanceof RegExp // easy case
|| typeof(re) === "function" // duck-type for context-switching evalcx case || typeof(re) === 'function' // duck-type for context-switching evalcx case
&& re.constructor.name === "RegExp" && re.constructor.name === 'RegExp'
&& re.compile && re.compile
&& re.test && re.test
&& re.exec && re.exec
@ -268,7 +268,7 @@ function isRegExp (re) {
function isDate(d) { function isDate(d) {
if (d instanceof Date) return true; if (d instanceof Date) return true;
if (typeof d !== "object") return false; if (typeof d !== 'object') return false;
var properties = Date.prototype && Object.getOwnPropertyNames(Date.prototype); var properties = Date.prototype && Object.getOwnPropertyNames(Date.prototype);
var proto = d.__proto__ && Object.getOwnPropertyNames(d.__proto__); var proto = d.__proto__ && Object.getOwnPropertyNames(d.__proto__);
return JSON.stringify(proto) === JSON.stringify(properties); return JSON.stringify(proto) === JSON.stringify(properties);
@ -279,7 +279,7 @@ var pWarning;
exports.p = function() { exports.p = function() {
if (!pWarning) { if (!pWarning) {
pWarning = "util.p will be removed in future versions of Node. Use util.puts(util.inspect()) instead.\n"; pWarning = 'util.p will be removed in future versions of Node. Use util.puts(util.inspect()) instead.\n';
exports.error(pWarning); exports.error(pWarning);
} }
for (var i = 0, len = arguments.length; i < len; ++i) { for (var i = 0, len = arguments.length; i < len; ++i) {
@ -330,39 +330,39 @@ exports.pump = function (readStream, writeStream, callback) {
} }
} }
if (!readStream.pause) readStream.pause = function () {readStream.emit("pause");}; if (!readStream.pause) readStream.pause = function() {readStream.emit('pause');};
if (!readStream.resume) readStream.resume = function () {readStream.emit("resume");}; if (!readStream.resume) readStream.resume = function() {readStream.emit('resume');};
readStream.addListener("data", function (chunk) { readStream.addListener('data', function(chunk) {
if (writeStream.write(chunk) === false) readStream.pause(); if (writeStream.write(chunk) === false) readStream.pause();
}); });
writeStream.addListener("pause", function () { writeStream.addListener('pause', function() {
readStream.pause(); readStream.pause();
}); });
writeStream.addListener("drain", function () { writeStream.addListener('drain', function() {
readStream.resume(); readStream.resume();
}); });
writeStream.addListener("resume", function () { writeStream.addListener('resume', function() {
readStream.resume(); readStream.resume();
}); });
readStream.addListener("end", function () { readStream.addListener('end', function() {
writeStream.end(); writeStream.end();
}); });
readStream.addListener("close", function () { readStream.addListener('close', function() {
call(); call();
}); });
readStream.addListener("error", function (err) { readStream.addListener('error', function(err) {
writeStream.end(); writeStream.end();
call(err); call(err);
}); });
writeStream.addListener("error", function (err) { writeStream.addListener('error', function(err) {
readStream.destroy(); readStream.destroy();
call(err); call(err);
}); });
@ -378,8 +378,8 @@ exports.pump = function (readStream, writeStream, callback) {
* expected during bootstrapping (see mirror.js in r114903). * expected during bootstrapping (see mirror.js in r114903).
* *
* @param {function} ctor Constructor function which needs to inherit the * @param {function} ctor Constructor function which needs to inherit the
* prototype * prototype.
* @param {function} superCtor Constructor function to inherit prototype from * @param {function} superCtor Constructor function to inherit prototype from.
*/ */
exports.inherits = function(ctor, superCtor) { exports.inherits = function(ctor, superCtor) {
ctor.super_ = superCtor; ctor.super_ = superCtor;