added ipc.config.stopRetrying for clients
This commit is contained in:
parent
a1f3c5cbdb
commit
90e529874b
3 changed files with 24 additions and 10 deletions
|
@ -8,7 +8,8 @@ function init(config,log){
|
|||
socket : false,
|
||||
connect : connect,
|
||||
emit : emit,
|
||||
log : log
|
||||
log : log,
|
||||
retryCount:0
|
||||
}
|
||||
new pubsub(client);
|
||||
|
||||
|
@ -33,13 +34,6 @@ function connect(){
|
|||
//init client object for scope persistance especially inside of socket events.
|
||||
var client=this;
|
||||
|
||||
if(client.socket){
|
||||
if(client.socket.destroyed){
|
||||
client.log('Requested to connect or reconnect to a destroyed socket. Not attempting because socket distroyed'.notice);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
client.log('requested connection to '.debug, client.id.variable, client.path.variable);
|
||||
if(!this.path){
|
||||
client.log('\n\n######\nerror: '.error, client.id .info,' client has not specified socket path it wishes to connect to.'.error);
|
||||
|
@ -83,11 +77,30 @@ function connect(){
|
|||
'close',
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
client.isRetrying=true;
|
||||
|
||||
setTimeout(
|
||||
(
|
||||
function(client){
|
||||
return function(){
|
||||
client.isRetrying=false;
|
||||
client.connect();
|
||||
setTimeout(
|
||||
function(){
|
||||
if(!client.isRetrying)
|
||||
client.retryCount=0;
|
||||
},
|
||||
100
|
||||
)
|
||||
}
|
||||
}
|
||||
)(client),
|
||||
|
|
|
@ -26,7 +26,8 @@ var defaults={
|
|||
encoding : 'utf8',
|
||||
silent : false,
|
||||
maxConnections : 100,
|
||||
retry : 500
|
||||
retry : 500,
|
||||
stopRetrying : false,
|
||||
}
|
||||
|
||||
var ipc = {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "node-ipc",
|
||||
"version": "0.9.11",
|
||||
"version": "0.9.13",
|
||||
"description": "A nodejs module for local and remote Inter Process Communication (IPC), Neural Networking, and able to facilitate machine learning.",
|
||||
"main": "node-ipc.js",
|
||||
"directories": {
|
||||
|
|
Loading…
Reference in a new issue