8000 fix #33 by enbyted · Pull Request #34 · foreversd/nssocket · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix #33 #34

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions lib/nssocket.js
8000
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var NsSocket = exports.NsSocket = function (socket, options) {
//
this._reconnect = options.reconnect || false;
this.retry = {
closed: true,
retries: 0,
max: options.maxRetries || 10,
interval: options.retryInterval || 5000,
Expand Down Expand Up @@ -205,6 +206,7 @@ NsSocket.prototype.setIdle = function setIdle(time) {
// #### forcibly destroys this nsSocket, unregister socket, remove all callbacks
//
NsSocket.prototype.destroy = function destroy() {
this.retry.closed = true; // Disable reconnection logic
if (this.socket) {
try {
this.socket.end(); // send FIN
Expand All @@ -229,6 +231,7 @@ NsSocket.prototype.destroy = function destroy() {
//
NsSocket.prototype.end = function end() {
this.connected = false;
this.retry.closed = true; // Disable reconnection logic

if (this.socket) {
try {
Expand Down Expand Up @@ -279,6 +282,8 @@ NsSocket.prototype.connect = function connect(/*port, host, callback*/) {
this.host = this.host || '127.0.0.1';
args = this.port ? [this.port, this.host] : [this.host];

this.retry.closed = false;

if (callback) {
args.push(callback);
}
Expand Down Expand Up @@ -309,6 +314,9 @@ NsSocket.prototype.connect = function connect(/*port, host, callback*/) {
NsSocket.prototype.reconnect = function reconnect() {
var self = this;

// Do not try to reconnect when user requested disconnect
if(self.retry.closed) return;

//
// Helper function containing the core reconnect logic
//
Expand Down
0