Closing the IrcConnection socket on a dispose
authorDarren <darren@darrenwhitlen.com>
Tue, 29 Jan 2013 13:41:08 +0000 (13:41 +0000)
committerDarren <darren@darrenwhitlen.com>
Thu, 31 Jan 2013 14:58:44 +0000 (14:58 +0000)
server/irc/connection.js
server/irc/state.js
server/irc/user.js

index 311c811b1965bbed6643ca44484d2acd282b99eb..5cf64a4b750a285ff01185c1ed449f3de1201bdd 100644 (file)
@@ -202,6 +202,7 @@ IrcConnection.prototype.dispose = function () {
  */
 IrcConnection.prototype.disposeSocket = function () {
     if (this.socket) {
+        this.socket.end();
         this.socket.removeAllListeners();
         this.socket = null;
     }
index 768e62bbaa0ec2bde65f29ed096cb25e183f0a25..31ba4831bd76f9a9132e312a14a4c67361661e1e 100755 (executable)
@@ -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();
         }
     });
 };
index 37e50b5d15e0dce6b48bb40c1382885349bb8038..833bf890b3d28122a9fc02a5ab3ecac6e3204e98 100755 (executable)
@@ -30,7 +30,7 @@ module.exports = IrcUser;
 \r
 \r
 IrcUser.prototype.dispose = function () {\r
-    EventBinder.unbindIrcEvents('user:' + this.nick, this.irc_events);\r
+    EventBinder.unbindIrcEvents('user:' + this.nick, this.irc_events, this.irc_connection);\r
     this.irc_connection = undefined;\r
 };\r
 \r