fixed retry mechinisim to allow specific retry count

This commit is contained in:
Brandon Nozaki Miller 2014-08-27 20:41:12 -07:00
parent 874df2fbfb
commit 83d372edb7
7 changed files with 26 additions and 11 deletions

View file

@ -9,6 +9,7 @@ var ipc=require('../../../node-ipc');
ipc.config.id = 'goodbye';
ipc.config.retry= 1500;
ipc.config.maxRetries= 10;
ipc.connectToNet(
'world',

View file

@ -9,6 +9,7 @@ var ipc=require('../../../node-ipc');
ipc.config.id = 'hello';
ipc.config.retry= 1500;
ipc.config.maxRetries=10;
ipc.connectToNet(
'world',

View file

@ -23,6 +23,13 @@ ipc.serveNet(
);
}
);
ipc.server.on(
'socket.disconnected',
function(data,socket){
console.log(arguments)
}
);
}
);

View file

@ -40,7 +40,6 @@ ipc.serveNet(
);
}
);
}
);

View file

@ -9,7 +9,7 @@ function init(config,log){
connect : connect,
emit : emit,
log : log,
retryCount:0
retriesRemaining:0
}
new pubsub(client);
@ -70,6 +70,8 @@ function connect(){
'connect',
function(){
client.trigger('connect');
client.retriesRemaining=client.config.maxRetries||0;
client.log('retrying reset')
}
);
@ -78,13 +80,12 @@ function connect(){
function(){
client.log('connection closed'.notice ,client.id.variable , client.path.variable);
if(client.config.stopRetrying || client.config.stopRetrying===0){
if(client.retryCount++>client.config.stopRetrying){
client.log(client.config.id.variable,'exceeded connection rety amount of'.warn,client.config.stopRetrying);
if(client.stopRetrying || client.retriesRemaining<1){
client.log(client.config.id.variable,'exceeded connection rety amount of'.warn,client.config.stopRetrying, " or stopRetrying flag set.");
client.socket.destroy();
client=undefined;
return;
}
}
client.isRetrying=true;
@ -92,12 +93,13 @@ function connect(){
(
function(client){
return function(){
client.retriesRemaining--;
client.isRetrying=false;
client.connect();
setTimeout(
function(){
if(!client.isRetrying)
client.retryCount=0;
client.retriesRemaining=ipc.config.maxRetries;
},
100
)

View file

@ -186,6 +186,9 @@ function init(path,config,log,port){
var e=JSON.parse(data.shift());
server.log('received event of : '.debug,e.type.data,e.data);
if(e.data.id)
sock.id=e.data.id;
server.trigger(
e.type,
e.data,

View file

@ -65,6 +65,8 @@ function disconnect(id){
if(!ipc.of[id])
return;
ipc.of[id].stopRetrying=true;
ipc.of[id].off('*');
if(ipc.of[id].socket){
if(ipc.of[id].socket.destroy)