Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to use single socket #160

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
testing
.DS_Store
.idea
10 changes: 10 additions & 0 deletions lib/sockets/sock.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ function Socket() {
this.set('identity', String(process.pid));
this.set('retry timeout', 100);
this.set('retry max timeout', 5000);

//a single socket mode so that if a socket dies without event, a new connection can replace the old socket, to avoid a round robin socket selection on dead sockets
this.set('single_socket_mode',false);
}

/**
Expand Down Expand Up @@ -170,6 +173,13 @@ Socket.prototype.removeSocket = function(sock){
*/

Socket.prototype.addSocket = function(sock){
if(this.get('single_socket_mode') && this.socks.length > 0) {
var xSock = this.socks.pop(); //remove the last socket and replace with the new socket that just connected.
if(xSock)
xSock.destroy();

}

var parser = new Parser;
var i = this.socks.push(sock) - 1;
debug('%s add socket %d', this.type, i);
Expand Down