diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-01-10 15:25:19 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-01-10 15:25:19 +0000 |
commit | 20a9ef356173364f87cef69d4ee285172e7b1b9c (patch) | |
tree | 3263e43788cce784e58701e2d6b333cc047baf69 | |
parent | 0632c3fd75ec58c2d306a813d10a68817f050a30 (diff) | |
download | prosody-20a9ef356173364f87cef69d4ee285172e7b1b9c.tar.gz prosody-20a9ef356173364f87cef69d4ee285172e7b1b9c.zip |
net.server_event: Add server.hook_signal(signal_num, handler) to wrap libevent's signal-catching interface
-rw-r--r-- | net/server_event.lua | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/net/server_event.lua b/net/server_event.lua index 53198a12..2ce6add2 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -13,7 +13,6 @@ --]] - local SCRIPT_NAME = "server_event.lua" local SCRIPT_VERSION = "0.05" local SCRIPT_AUTHOR = "blastbeat" @@ -77,6 +76,7 @@ local base = event.new( ) local EV_READ = event.EV_READ local EV_WRITE = event.EV_WRITE local EV_TIMEOUT = event.EV_TIMEOUT +local EV_SIGNAL = event.EV_SIGNAL local EV_READWRITE = bitor( EV_READ, EV_WRITE ) @@ -786,6 +786,21 @@ function get_backend() return base:method(); end +-- We need to hold onto the events to stop them +-- being garbage-collected +local signal_events = {}; -- [signal_num] -> event object +function hook_signal(signal_num, handler) + local function _handler(event) + local ret = handler(); + if ret ~= false then -- Continue handling this signal? + return EV_SIGNAL; -- Yes + end + return -1; -- Close this event + end + signal_events[signal_num] = base:addevent(signal_num, EV_SIGNAL, _handler); + return signal_events[signal_num]; +end + return { cfg = cfg, @@ -800,6 +815,7 @@ return { setquitting = setquitting, closeall = closeallservers, get_backend = get_backend, + hook_signal = hook_signal, __NAME = SCRIPT_NAME, __DATE = LAST_MODIFIED, |