From 90e529874b0186ea2408a58a7c707590477368f9 Mon Sep 17 00:00:00 2001 From: Brandon Miller Date: Sat, 1 Mar 2014 16:31:05 -0800 Subject: [PATCH] added ipc.config.stopRetrying for clients --- lib/client.js | 29 +++++++++++++++++++++-------- node-ipc.js | 3 ++- package.json | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/client.js b/lib/client.js index 33e9e0b..eb639a2 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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), diff --git a/node-ipc.js b/node-ipc.js index 59ec06b..8ac3687 100644 --- a/node-ipc.js +++ b/node-ipc.js @@ -26,7 +26,8 @@ var defaults={ encoding : 'utf8', silent : false, maxConnections : 100, - retry : 500 + retry : 500, + stopRetrying : false, } var ipc = { diff --git a/package.json b/package.json index 9962b43..42ff77b 100644 --- a/package.json +++ b/package.json @@ -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": {