From 437fd63c6ff097d6a09d162ef9b6a104d73fa723 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 26 Sep 2018 14:25:59 +0200 Subject: net.server: Call a 'onattach' callback when replacing listeners --- net/server_epoll.lua | 1 + net/server_event.lua | 4 ++++ net/server_select.lua | 3 +++ 3 files changed, 8 insertions(+) (limited to 'net') diff --git a/net/server_epoll.lua b/net/server_epoll.lua index 04922f6e..23b3f376 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -139,6 +139,7 @@ end function interface:setlistener(listeners) self:on("detach"); self.listeners = listeners; + self:on("attach"); end -- Call a listener callback diff --git a/net/server_event.lua b/net/server_event.lua index 6daf0944..8ee2f28d 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -424,7 +424,9 @@ function interface_mt:setlistener(listener) self.onreadtimeout = listener.onreadtimeout; self.onstatus = listener.onstatus; self.ondetach = listener.ondetach; + self.onattach = listener.onattach; self.ondrain = listener.ondrain; + self:onattach(); end -- Stub handlers @@ -446,6 +448,8 @@ function interface_mt:ondrain() end function interface_mt:ondetach() end +function interface_mt:onattach() +end function interface_mt:onstatus() end diff --git a/net/server_select.lua b/net/server_select.lua index 2cd095fe..1b535bb7 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -331,6 +331,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport drain = listeners.ondrain handler.onreadtimeout = listeners.onreadtimeout detach = listeners.ondetach + if listeners.onattach then + listeners.onattach(self) + end end handler.getstats = function( ) return readtraffic, sendtraffic -- cgit v1.2.3