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.id = 'goodbye';
|
||||||
ipc.config.retry= 1500;
|
ipc.config.retry= 1500;
|
||||||
|
ipc.config.maxRetries= 10;
|
||||||
|
|
||||||
ipc.connectToNet(
|
ipc.connectToNet(
|
||||||
'world',
|
'world',
|
||||||
|
|
|
@ -9,6 +9,7 @@ var ipc=require('../../../node-ipc');
|
||||||
|
|
||||||
ipc.config.id = 'hello';
|
ipc.config.id = 'hello';
|
||||||
ipc.config.retry= 1500;
|
ipc.config.retry= 1500;
|
||||||
|
ipc.config.maxRetries=10;
|
||||||
|
|
||||||
ipc.connectToNet(
|
ipc.connectToNet(
|
||||||
'world',
|
'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,
|
connect : connect,
|
||||||
emit : emit,
|
emit : emit,
|
||||||
log : log,
|
log : log,
|
||||||
retryCount:0
|
retriesRemaining:0
|
||||||
}
|
}
|
||||||
new pubsub(client);
|
new pubsub(client);
|
||||||
|
|
||||||
|
@ -70,6 +70,8 @@ function connect(){
|
||||||
'connect',
|
'connect',
|
||||||
function(){
|
function(){
|
||||||
client.trigger('connect');
|
client.trigger('connect');
|
||||||
|
client.retriesRemaining=client.config.maxRetries||0;
|
||||||
|
client.log('retrying reset')
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -78,13 +80,12 @@ function connect(){
|
||||||
function(){
|
function(){
|
||||||
client.log('connection closed'.notice ,client.id.variable , client.path.variable);
|
client.log('connection closed'.notice ,client.id.variable , client.path.variable);
|
||||||
|
|
||||||
if(client.config.stopRetrying || client.config.stopRetrying===0){
|
if(client.stopRetrying || client.retriesRemaining<1){
|
||||||
if(client.retryCount++>client.config.stopRetrying){
|
client.log(client.config.id.variable,'exceeded connection rety amount of'.warn,client.config.stopRetrying, " or stopRetrying flag set.");
|
||||||
client.log(client.config.id.variable,'exceeded connection rety amount of'.warn,client.config.stopRetrying);
|
|
||||||
client.socket.destroy();
|
client.socket.destroy();
|
||||||
|
client=undefined;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
client.isRetrying=true;
|
client.isRetrying=true;
|
||||||
|
|
||||||
|
@ -92,12 +93,13 @@ function connect(){
|
||||||
(
|
(
|
||||||
function(client){
|
function(client){
|
||||||
return function(){
|
return function(){
|
||||||
|
client.retriesRemaining--;
|
||||||
client.isRetrying=false;
|
client.isRetrying=false;
|
||||||
client.connect();
|
client.connect();
|
||||||
setTimeout(
|
setTimeout(
|
||||||
function(){
|
function(){
|
||||||
if(!client.isRetrying)
|
if(!client.isRetrying)
|
||||||
client.retryCount=0;
|
client.retriesRemaining=ipc.config.maxRetries;
|
||||||
},
|
},
|
||||||
100
|
100
|
||||||
)
|
)
|
||||||
|
|
|
@ -186,6 +186,9 @@ function init(path,config,log,port){
|
||||||
var e=JSON.parse(data.shift());
|
var e=JSON.parse(data.shift());
|
||||||
server.log('received event of : '.debug,e.type.data,e.data);
|
server.log('received event of : '.debug,e.type.data,e.data);
|
||||||
|
|
||||||
|
if(e.data.id)
|
||||||
|
sock.id=e.data.id;
|
||||||
|
|
||||||
server.trigger(
|
server.trigger(
|
||||||
e.type,
|
e.type,
|
||||||
e.data,
|
e.data,
|
||||||
|
|
|
@ -65,6 +65,8 @@ function disconnect(id){
|
||||||
if(!ipc.of[id])
|
if(!ipc.of[id])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ipc.of[id].stopRetrying=true;
|
||||||
|
|
||||||
ipc.of[id].off('*');
|
ipc.of[id].off('*');
|
||||||
if(ipc.of[id].socket){
|
if(ipc.of[id].socket){
|
||||||
if(ipc.of[id].socket.destroy)
|
if(ipc.of[id].socket.destroy)
|
||||||
|
|
Loading…
Reference in a new issue