Permalink
Browse files

change coding style

  • Loading branch information...
1 parent 40629e8 commit ce7e656513604e1af67bc0eb24bff28155d64c38 @windyrobin committed Nov 30, 2011
Showing with 82 additions and 82 deletions.
  1. +15 −15 master.js
  2. +24 −25 tcpMaster.js
  3. +22 −21 tcpWorker.js
  4. +21 −21 worker.js
View
@@ -1,11 +1,11 @@
-var net = require("net");
-var cp = require("child_process");
+var net = require('net');
+var cp = require('child_process');
-const PORT = 3458;
-const WORKER_NUMBER = 5;
-const GRACE_EXIT_TIME = 2000;//2s
-const WORKER_PATH = __dirname + "/worker.js";
-const WORKER_HEART_BEAT = 10*1000;//10s, update memory ,etc
+var PORT = 3458;
+var WORKER_NUMBER = 5;
+var GRACE_EXIT_TIME = 2000;//2s
+var WORKER_PATH = __dirname + '/worker.js';
+var WORKER_HEART_BEAT = 10*1000;//10s, update memory ,etc
function output(str){
console.log(str);
@@ -30,15 +30,15 @@ function startWorker(handle){
*/
}
-var exit_timer = null;
-function about_exit(){
- if(exit_timer) return;
+var exitTimer = null;
+function aboutExit(){
+ if(exitTimer) return;
childs.forEach(function(c){
c.kill();
})
- exit_timer = setTimeout(function(){
- output("master exit...");
+ exitTimer = setTimeout(function(){
+ output('master exit...');
process.exit(0);
}, GRACE_EXIT_TIME);
@@ -56,8 +56,8 @@ void main(function(){
startServer();
- output("master is running...");
- process.on("SIGINT" , about_exit);
- process.on("SIGTERM" , about_exit);
+ output('master is running...');
+ process.on('SIGINT' , aboutExit);
+ process.on('SIGTERM' , aboutExit);
});
View
@@ -1,11 +1,11 @@
-var cp = require("child_process");
-var TCP = process.binding("tcp_wrap").TCP;
+var cp = require('child_process');
+var TCP = process.binding('tcp_wrap').TCP;
-const PORT = 3458;
-const WORKER_NUMBER = 5;
-const GRACE_EXIT_TIME = 2000;//2s
-const WORKER_PATH = __dirname + "/tcpWorker.js";
-const WORKER_HEART_BEAT = 10*1000;//10s, update memory ,etc
+var PORT = 3458;
+var WORKER_NUMBER = 5;
+var GRACE_EXIT_TIME = 2000;//2s
+var WORKER_PATH = __dirname + '/tcpWorker.js';
+var WORKER_HEART_BEAT = 10*1000;//10s, update memory ,etc
function main(fn){
fn();
@@ -16,9 +16,8 @@ function output(str){
}
var childs = [];
-var last_child_pos = 0;
+var lastChildPos = 0;
function startWorker(){
- worker_succ_count = 0;
for(var i=0; i<WORKER_NUMBER; i++){
var c = cp.fork(WORKER_PATH);
childs.push(c);
@@ -32,33 +31,33 @@ function startWorker(){
}
var server = null;
-var exit_timer = null;
-function about_exit(){
- if(exit_timer) return;
+var exitTimer = null;
+function aboutExit(){
+ if(exitTimer) return;
server.close();
childs.forEach(function(c){
c.kill();
})
- exit_timer = setTimeout(function(){
- output("master exit...");
+ exitTimer = setTimeout(function(){
+ output('master exit...');
//log.destroy();
process.exit(0);
}, GRACE_EXIT_TIME);
}
-//const ADDRESS = "127.0.0.1";
-const ADDRESS = "0.0.0.0";
-const BACK_LOG = 128;
+//var ADDRESS = '127.0.0.1';
+var ADDRESS = '0.0.0.0';
+var BACK_LOG = 128;
function onconnection(handle){
- //output("master on connection");
- last_child_pos++;
- if(last_child_pos >= WORKER_NUMBER){
- last_child_pos = 0;
+ //output('master on connection');
+ lastChildPos++;
+ if(lastChildPos >= WORKER_NUMBER){
+ lastChildPos = 0;
}
- childs[last_child_pos].send({"handle" : true}, handle);
+ childs[lastChildPos].send({'handle' : true}, handle);
handle.close();
}
@@ -74,8 +73,8 @@ void main(function(){
startServer();
startWorker();
- output("master is running...");
- process.on("SIGINT" , about_exit);
- process.on("SIGTERM" , about_exit);
+ output('master is running...');
+ process.on('SIGINT' , aboutExit);
+ process.on('SIGTERM' , aboutExit);
});
View
@@ -1,5 +1,5 @@
-var net = require("net");
-var http = require("http");
+var net = require('net');
+var http = require('http');
function output(str){
console.log(str);
@@ -8,19 +8,19 @@ function output(str){
function main(fn){
fn();
}
-const GRACE_EXIT_TIME = 1500;
+var GRACE_EXIT_TIME = 1500;
var server = null;
-var exit_timer = null;
-var child_req_count = 0;
+var exitTimer = null;
+var childReqCount = 0;
-function about_exit(){
- if(exit_timer) return;
+function aboutExit(){
+ if(exitTimer) return;
//server.close();
- exit_timer = setTimeout(function(){
- output("worker will exit...");
- output("child req total : " + child_req_count);
+ exitTimer = setTimeout(function(){
+ output('worker will exit...');
+ output('child req total : ' + childReqCount);
process.exit(0);
},GRACE_EXIT_TIME);
@@ -39,32 +39,33 @@ function onhandle(self, handle){
socket.resume();
self.connections++;
socket.server = self;
- self.emit("connection", socket);
- socket.emit("connect");
+ self.emit('connection', socket);
+ socket.emit('connect');
+ //output('get a connection');
}
void main(function(){
- process.on("SIGINT" ,about_exit)
- process.on("SIGTERM" ,about_exit)
+ process.on('SIGINT' ,aboutExit)
+ process.on('SIGTERM' ,aboutExit)
server = http.createServer(function(req, res){
var r, i;
for(i=0; i<10000; i++){
r = Math.random();
}
- res.writeHead(200 ,{"content-type" : "text/html"});
- res.end("hello,world");
- child_req_count++;
+ res.writeHead(200 ,{'content-type' : 'text/html'});
+ res.end('hello,world');
+ childReqCount++;
});
- process.on("message",function(m ,handle){
+ process.on('message',function(m ,handle){
if(handle){
onhandle(server, handle);
}
- if(m.status == "update"){
- process.send({"status" : process.memoryUsage()});
+ if(m.status == 'update'){
+ process.send({'status' : process.memoryUsage()});
}
});
- output("worker is running...");
+ output('worker is running...');
});
View
@@ -1,4 +1,4 @@
-var http = require("http");
+var http = require('http');
function output(str){
console.log(str);
@@ -8,54 +8,54 @@ function main(fn){
fn();
}
-const GRACE_EXIT_TIME = 1500;
+var GRACE_EXIT_TIME = 1500;
var server = null;
-var exit_timer = null;
-var child_req_count = 0;
+var exitTimer = null;
+var childReqCount = 0;
-function about_exit(){
- if(exit_timer) return;
+function aboutExit(){
+ if(exitTimer) return;
server.close();
- exit_timer = setTimeout(function(){
- output("worker will exit...");
- output("child req total : " + child_req_count);
+ exitTimer = setTimeout(function(){
+ output('worker will exit...');
+ output('child req total : ' + childReqCount);
process.exit(0);
},GRACE_EXIT_TIME);
}
void main(function(){
- process.on("SIGINT" ,about_exit)
- process.on("SIGTERM" ,about_exit)
+ process.on('SIGINT' ,aboutExit)
+ process.on('SIGTERM' ,aboutExit)
server = http.createServer(function(req, res){
var i,r;
for(i=0; i<10000; i++){
r = Math.random();
}
- res.writeHead(200 ,{"content-type" : "text/html"});
- res.end("hello,world");
- child_req_count++;
+ res.writeHead(200 ,{'content-type' : 'text/html'});
+ res.end('hello,world');
+ childReqCount++;
});
- process.on("message",function(m ,handle){
+ process.on('message',function(m ,handle){
if(handle){
server.listen(handle, function(err){
if(err){
- output("worker listen error");
+ output('worker listen error');
}else{
- process.send({"listenOK" : true});
- output("worker listen ok");
+ process.send({'listenOK' : true});
+ output('worker listen ok');
}
});
}
- if(m.status == "update"){
- process.send({"status" : process.memoryUsage()});
+ if(m.status == 'update'){
+ process.send({'status' : process.memoryUsage()});
}
});
- output("worker is running...");
+ output('worker is running...');
});

0 comments on commit ce7e656

Please sign in to comment.