fixed retry mechinisim to allow specific retry count
This commit is contained in:
parent
874df2fbfb
commit
83d372edb7
7 changed files with 26 additions and 11 deletions
|
@ -9,6 +9,7 @@ var ipc=require('../../../node-ipc');
|
|||
|
||||
ipc.config.id = 'goodbye';
|
||||
ipc.config.retry= 1500;
|
||||
ipc.config.maxRetries= 10;
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
|
|
|
@ -9,6 +9,7 @@ var ipc=require('../../../node-ipc');
|
|||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
ipc.config.maxRetries=10;
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
|
|
|
@ -23,6 +23,13 @@ ipc.serveNet(
|
|||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'socket.disconnected',
|
||||
function(data,socket){
|
||||
console.log(arguments)
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ ipc.serveNet(
|
|||
);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -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,12 +80,11 @@ 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);
|
||||
client.socket.destroy();
|
||||
return;
|
||||
}
|
||||
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
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
|
@ -318,7 +321,7 @@ function init(path,config,log,port){
|
|||
return;
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,9 @@ function log(){
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue