plugins/mod_muc_unique: Fix undefined global access (thanks Lance)
[prosody.git] / net / server_select.lua
index 06deec322a491912814c145cca2851166362e6ee..9b8e41d9b682e5f5fb1b8da4e18be7b077269922 100644 (file)
@@ -286,6 +286,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
        local disconnect = listeners.ondisconnect
        local drain = listeners.ondrain
        local onreadtimeout = listeners.onreadtimeout;
+       local detach = listeners.ondetach
 
        local bufferqueue = { } -- buffer array
        local bufferqueuelen = 0        -- end of buffer array
@@ -317,11 +318,15 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
        handler.onreadtimeout = onreadtimeout;
 
        handler.setlistener = function( self, listeners )
+               if detach then
+                       detach(self) -- Notify listener that it is no longer responsible for this connection
+               end
                dispatch = listeners.onincoming
                disconnect = listeners.ondisconnect
                status = listeners.onstatus
                drain = listeners.ondrain
                handler.onreadtimeout = listeners.onreadtimeout
+               detach = listeners.ondetach
        end
        handler.getstats = function( )
                return readtraffic, sendtraffic