Browse Source

jslint

Fixes #2306
v0.7.4-release
Andreas Madsen 13 years ago
committed by Ryan Dahl
parent
commit
a599aeb2a8
  1. 18
      lib/child_process.js
  2. 26
      lib/cluster.js

18
lib/child_process.js

@ -25,7 +25,6 @@ var Process = process.binding('process_wrap').Process;
var inherits = require('util').inherits; var inherits = require('util').inherits;
var constants; // if (!constants) constants = process.binding('constants'); var constants; // if (!constants) constants = process.binding('constants');
var LF = '\n'.charCodeAt(0);
var Pipe; var Pipe;
@ -76,8 +75,8 @@ function setupChannel(target, channel) {
if (isWindows) { if (isWindows) {
var setSimultaneousAccepts = function(handle) { var setSimultaneousAccepts = function(handle) {
var simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS var simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS &&
&& process.env.NODE_MANY_ACCEPTS != '0') ? true : false; process.env.NODE_MANY_ACCEPTS != '0') ? true : false;
if (handle._simultaneousAccepts != simultaneousAccepts) { if (handle._simultaneousAccepts != simultaneousAccepts) {
handle.setSimultaneousAccepts(simultaneousAccepts); handle.setSimultaneousAccepts(simultaneousAccepts);
@ -101,7 +100,7 @@ function setupChannel(target, channel) {
var message = JSON.parse(json); var message = JSON.parse(json);
target.emit('message', message, recvHandle); target.emit('message', message, recvHandle);
start = i+1; start = i + 1;
} }
jsonBuffer = jsonBuffer.slice(start); jsonBuffer = jsonBuffer.slice(start);
@ -112,7 +111,7 @@ function setupChannel(target, channel) {
}; };
target.send = function(message, sendHandle) { target.send = function(message, sendHandle) {
if (!target._channel) throw new Error("channel closed"); if (!target._channel) throw new Error('channel closed');
// For overflow protection don't write if channel queue is too deep. // For overflow protection don't write if channel queue is too deep.
if (channel.writeQueueSize > 1024 * 1024) { if (channel.writeQueueSize > 1024 * 1024) {
@ -129,7 +128,7 @@ function setupChannel(target, channel) {
var writeReq = channel.write(buffer, 0, buffer.length, sendHandle); var writeReq = channel.write(buffer, 0, buffer.length, sendHandle);
if (!writeReq) { if (!writeReq) {
throw new Error(errno + " cannot write to IPC channel."); throw new Error(errno + 'cannot write to IPC channel.');
} }
writeReq.oncomplete = nop; writeReq.oncomplete = nop;
@ -151,16 +150,16 @@ exports.fork = function(modulePath, args, options) {
args.unshift(modulePath); args.unshift(modulePath);
if (options.stdinStream) { if (options.stdinStream) {
throw new Error("stdinStream not allowed for fork()"); throw new Error('stdinStream not allowed for fork()');
} }
if (options.customFds) { if (options.customFds) {
throw new Error("customFds not allowed for fork()"); throw new Error('customFds not allowed for fork()');
} }
// Leave stdin open for the IPC channel. stdout and stderr should be the // Leave stdin open for the IPC channel. stdout and stderr should be the
// same as the parent's. // same as the parent's.
options.customFds = [ -1, 1, 2 ]; options.customFds = [-1, 1, 2];
// Just need to set this - child process won't actually use the fd. // Just need to set this - child process won't actually use the fd.
// For backwards compat - this can be changed to 'NODE_CHANNEL' before v0.6. // For backwards compat - this can be changed to 'NODE_CHANNEL' before v0.6.
@ -331,7 +330,6 @@ var spawn = exports.spawn = function(file, args, options) {
var env = (options ? options.env : null) || process.env; var env = (options ? options.env : null) || process.env;
var envPairs = []; var envPairs = [];
var keys = Object.keys(env);
for (var key in env) { for (var key in env) {
envPairs.push(key + '=' + env[key]); envPairs.push(key + '=' + env[key]);
} }

26
lib/cluster.js

@ -81,11 +81,11 @@ function startMaster() {
// Quickly try to kill all the workers. // Quickly try to kill all the workers.
// TODO: be session leader - will cause auto SIGHUP to the children. // TODO: be session leader - will cause auto SIGHUP to the children.
eachWorker(function(worker) { eachWorker(function(worker) {
debug("kill worker " + worker.pid); debug('kill worker ' + worker.pid);
worker.kill(); worker.kill();
}) });
console.error("Exception in cluster master process: " + console.error('Exception in cluster master process: ' +
e.message + '\n' + e.stack); e.message + '\n' + e.stack);
process.exit(1); process.exit(1);
}); });
@ -96,21 +96,21 @@ function handleWorkerMessage(worker, message) {
// This can only be called from the master. // This can only be called from the master.
assert(cluster.isMaster); assert(cluster.isMaster);
debug("recv " + JSON.stringify(message)); debug('recv ' + JSON.stringify(message));
switch (message.cmd) { switch (message.cmd) {
case 'online': case 'online':
debug("Worker " + worker.pid + " online"); debug('Worker ' + worker.pid + ' online');
worker.online = true; worker.online = true;
break; break;
case 'queryServer': case 'queryServer':
var key = message.address + ":" + var key = message.address + ':' +
message.port + ":" + message.port + ':' +
message.addressType; message.addressType;
var response = { _queryId: message._queryId }; var response = { _queryId: message._queryId };
if (key in servers == false) { if (!(key in servers)) {
// Create a new server. // Create a new server.
debug('create new server ' + key); debug('create new server ' + key);
servers[key] = net._createServerHandle(message.address, servers[key] = net._createServerHandle(message.address,
@ -136,7 +136,7 @@ function eachWorker(cb) {
cb(workers[id]); cb(workers[id]);
} }
} }
}; }
cluster.fork = function() { cluster.fork = function() {
@ -176,19 +176,19 @@ cluster.fork = function() {
// Internal function. Called from src/node.js when worker process starts. // Internal function. Called from src/node.js when worker process starts.
cluster._startWorker = function() { cluster._startWorker = function() {
assert(cluster.isWorker); assert(cluster.isWorker);
workerId = parseInt(process.env.NODE_WORKER_ID); workerId = parseInt(process.env.NODE_WORKER_ID, 10);
queryMaster({ cmd: 'online' }); queryMaster({ cmd: 'online' });
// Make callbacks from queryMaster() // Make callbacks from queryMaster()
process.on('message', function(msg, handle) { process.on('message', function(msg, handle) {
debug("recv " + JSON.stringify(msg)); debug('recv ' + JSON.stringify(msg));
if (msg._queryId && msg._queryId in queryCallbacks) { if (msg._queryId && msg._queryId in queryCallbacks) {
var cb = queryCallbacks[msg._queryId]; var cb = queryCallbacks[msg._queryId];
if (typeof cb == 'function') { if (typeof cb == 'function') {
cb(msg, handle); cb(msg, handle);
} }
delete queryCallbacks[msg._queryId] delete queryCallbacks[msg._queryId];
} }
}); });
}; };
@ -219,7 +219,7 @@ cluster._getServer = function(address, port, addressType, cb) {
assert(cluster.isWorker); assert(cluster.isWorker);
queryMaster({ queryMaster({
cmd: "queryServer", cmd: 'queryServer',
address: address, address: address,
port: port, port: port,
addressType: addressType addressType: addressType

Loading…
Cancel
Save