[Groonga-commit] groonga/express-kotoumi [master] Remove message handlers attached to the connection when a socket.io client is disconnected

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Jan 30 12:49:18 JST 2013


YUKI Hiroshi	2013-01-30 12:49:18 +0900 (Wed, 30 Jan 2013)

  New Revision: 224a53fe663166578d520f566644bcecd9ff14f3
  https://github.com/groonga/express-kotoumi/commit/224a53fe663166578d520f566644bcecd9ff14f3

  Log:
    Remove message handlers attached to the connection when a socket.io client is disconnected

  Modified files:
    lib/frontend/socket.io-handler.js

  Modified: lib/frontend/socket.io-handler.js (+11 -1)
===================================================================
--- lib/frontend/socket.io-handler.js    2013-01-30 12:23:47 +0900 (ba94c12)
+++ lib/frontend/socket.io-handler.js    2013-01-30 12:49:18 +0900 (de3cab4)
@@ -54,10 +54,20 @@ exports.register = function(application, server, params) {
 
   var io = socketIo.listen(server);
   io.sockets.on('connection', function(socket) {
+    var messageHandlers = [];
     commands.concat(params.extraCommands || [])
       .forEach(function(command) {
         socket.on(command, createRequestHandler(command, socket));
-        connection.on('message', createResultHandler(command, socket));
+        var handler = createResultHandler(command, socket);
+        messageHandlers.push(handler);
+        connection.on('message', handler);
       });
+
+    socket.on('disconnect', function() {
+      messageHandlers.forEach(function(handler) {
+        connection.removeListener('message', handler);
+      });
+      socket.removeAllListeners();
+    });
   });
 }
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index