From 6b8fa7a66b75f6ddb0d3aa8243fca9466f92f8b2 Mon Sep 17 00:00:00 2001 From: Darren Date: Tue, 29 Jan 2013 13:41:08 +0000 Subject: [PATCH] Closing the IrcConnection socket on a dispose --- server/irc/connection.js | 1 + server/irc/state.js | 11 +++++++---- server/irc/user.js | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/server/irc/connection.js b/server/irc/connection.js index 311c811..5cf64a4 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -202,6 +202,7 @@ IrcConnection.prototype.dispose = function () { */ IrcConnection.prototype.disposeSocket = function () { if (this.socket) { + this.socket.end(); this.socket.removeAllListeners(); this.socket = null; } diff --git a/server/irc/state.js b/server/irc/state.js index 768e62b..31ba483 100755 --- a/server/irc/state.js +++ b/server/irc/state.js @@ -4,6 +4,8 @@ var util = require('util'), IrcConnection = require('./connection.js').IrcConnection; var State = function (client, save_state) { + var that = this; + events.EventEmitter.call(this); this.client = client; this.save_state = save_state || false; @@ -11,17 +13,18 @@ var State = function (client, save_state) { this.irc_connections = []; this.next_connection = 0; - this.client.on('disconnect', function () { - if (!this.save_state) { - _.each(this.irc_connections, function (irc_connection, i, cons) { + this.client.on('destroy', function () { + if (!that.save_state) { + _.each(that.irc_connections, function (irc_connection, i, cons) { if (irc_connection) { irc_connection.end('QUIT :' + (global.config.quit_message || '')); irc_connection.dispose(); cons[i] = null; + console.log('killed irc_connection'); } }); - this.dispose(); + that.dispose(); } }); }; diff --git a/server/irc/user.js b/server/irc/user.js index 37e50b5..833bf89 100755 --- a/server/irc/user.js +++ b/server/irc/user.js @@ -30,7 +30,7 @@ module.exports = IrcUser; IrcUser.prototype.dispose = function () { - EventBinder.unbindIrcEvents('user:' + this.nick, this.irc_events); + EventBinder.unbindIrcEvents('user:' + this.nick, this.irc_events, this.irc_connection); this.irc_connection = undefined; }; -- 2.25.1