parent
b9049d2f90
commit
a599aeb2a8
@ -25,7 +25,6 @@ var Process = process.binding('process_wrap').Process;
|
||||
var inherits = require('util').inherits;
|
||||
var constants; // if (!constants) constants = process.binding('constants');
|
||||
|
||||
var LF = '\n'.charCodeAt(0);
|
||||
var Pipe;
|
||||
|
||||
|
||||
@ -76,8 +75,8 @@ function setupChannel(target, channel) {
|
||||
|
||||
if (isWindows) {
|
||||
var setSimultaneousAccepts = function(handle) {
|
||||
var simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS
|
||||
&& process.env.NODE_MANY_ACCEPTS != '0') ? true : false;
|
||||
var simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS &&
|
||||
process.env.NODE_MANY_ACCEPTS != '0') ? true : false;
|
||||
|
||||
if (handle._simultaneousAccepts != simultaneousAccepts) {
|
||||
handle.setSimultaneousAccepts(simultaneousAccepts);
|
||||
@ -101,7 +100,7 @@ function setupChannel(target, channel) {
|
||||
var message = JSON.parse(json);
|
||||
|
||||
target.emit('message', message, recvHandle);
|
||||
start = i+1;
|
||||
start = i + 1;
|
||||
}
|
||||
jsonBuffer = jsonBuffer.slice(start);
|
||||
|
||||
@ -112,7 +111,7 @@ function setupChannel(target, channel) {
|
||||
};
|
||||
|
||||
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.
|
||||
if (channel.writeQueueSize > 1024 * 1024) {
|
||||
@ -129,7 +128,7 @@ function setupChannel(target, channel) {
|
||||
var writeReq = channel.write(buffer, 0, buffer.length, sendHandle);
|
||||
|
||||
if (!writeReq) {
|
||||
throw new Error(errno + " cannot write to IPC channel.");
|
||||
throw new Error(errno + 'cannot write to IPC channel.');
|
||||
}
|
||||
|
||||
writeReq.oncomplete = nop;
|
||||
@ -151,16 +150,16 @@ exports.fork = function(modulePath, args, options) {
|
||||
args.unshift(modulePath);
|
||||
|
||||
if (options.stdinStream) {
|
||||
throw new Error("stdinStream not allowed for fork()");
|
||||
throw new Error('stdinStream not allowed for fork()');
|
||||
}
|
||||
|
||||
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
|
||||
// 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.
|
||||
// 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 envPairs = [];
|
||||
var keys = Object.keys(env);
|
||||
for (var key in env) {
|
||||
envPairs.push(key + '=' + env[key]);
|
||||
}
|
||||
|
@ -81,11 +81,11 @@ function startMaster() {
|
||||
// Quickly try to kill all the workers.
|
||||
// TODO: be session leader - will cause auto SIGHUP to the children.
|
||||
eachWorker(function(worker) {
|
||||
debug("kill worker " + worker.pid);
|
||||
debug('kill worker ' + worker.pid);
|
||||
worker.kill();
|
||||
})
|
||||
});
|
||||
|
||||
console.error("Exception in cluster master process: " +
|
||||
console.error('Exception in cluster master process: ' +
|
||||
e.message + '\n' + e.stack);
|
||||
process.exit(1);
|
||||
});
|
||||
@ -96,21 +96,21 @@ function handleWorkerMessage(worker, message) {
|
||||
// This can only be called from the master.
|
||||
assert(cluster.isMaster);
|
||||
|
||||
debug("recv " + JSON.stringify(message));
|
||||
debug('recv ' + JSON.stringify(message));
|
||||
|
||||
switch (message.cmd) {
|
||||
case 'online':
|
||||
debug("Worker " + worker.pid + " online");
|
||||
debug('Worker ' + worker.pid + ' online');
|
||||
worker.online = true;
|
||||
break;
|
||||
|
||||
case 'queryServer':
|
||||
var key = message.address + ":" +
|
||||
message.port + ":" +
|
||||
var key = message.address + ':' +
|
||||
message.port + ':' +
|
||||
message.addressType;
|
||||
var response = { _queryId: message._queryId };
|
||||
|
||||
if (key in servers == false) {
|
||||
if (!(key in servers)) {
|
||||
// Create a new server.
|
||||
debug('create new server ' + key);
|
||||
servers[key] = net._createServerHandle(message.address,
|
||||
@ -136,7 +136,7 @@ function eachWorker(cb) {
|
||||
cb(workers[id]);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
cluster.fork = function() {
|
||||
@ -176,19 +176,19 @@ cluster.fork = function() {
|
||||
// Internal function. Called from src/node.js when worker process starts.
|
||||
cluster._startWorker = function() {
|
||||
assert(cluster.isWorker);
|
||||
workerId = parseInt(process.env.NODE_WORKER_ID);
|
||||
workerId = parseInt(process.env.NODE_WORKER_ID, 10);
|
||||
|
||||
queryMaster({ cmd: 'online' });
|
||||
|
||||
// Make callbacks from queryMaster()
|
||||
process.on('message', function(msg, handle) {
|
||||
debug("recv " + JSON.stringify(msg));
|
||||
debug('recv ' + JSON.stringify(msg));
|
||||
if (msg._queryId && msg._queryId in queryCallbacks) {
|
||||
var cb = queryCallbacks[msg._queryId];
|
||||
if (typeof cb == 'function') {
|
||||
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);
|
||||
|
||||
queryMaster({
|
||||
cmd: "queryServer",
|
||||
cmd: 'queryServer',
|
||||
address: address,
|
||||
port: port,
|
||||
addressType: addressType
|
||||
|
Loading…
x
Reference in New Issue
Block a user