var inherits = require('util').inherits;
var constants; // if (!constants) constants = process.binding('constants');
-var LF = '\n'.charCodeAt(0);
var Pipe;
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);
var message = JSON.parse(json);
target.emit('message', message, recvHandle);
- start = i+1;
+ start = i + 1;
}
jsonBuffer = jsonBuffer.slice(start);
};
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) {
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;
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.
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]);
}
// 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);
});
// 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,
cb(workers[id]);
}
}
-};
+}
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];
}
});
};
assert(cluster.isWorker);
queryMaster({
- cmd: "queryServer",
+ cmd: 'queryServer',
address: address,
port: port,
addressType: addressType