Changeset

2435:1ab73691b58e

net.server: When libevent backend is in use, override signal.signal to use server.hook_signal
author Matthew Wild <mwild1@gmail.com>
date Sun, 10 Jan 2010 15:26:36 +0000
parents 2434:4403d4473783
children 2436:ccc71b5d2e01
files net/server.lua
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/net/server.lua	Sun Jan 10 15:25:19 2010 +0000
+++ b/net/server.lua	Sun Jan 10 15:26:36 2010 +0000
@@ -23,6 +23,23 @@
 	function server.addtimer(f)
 		return add_task(1, function (...) f(...); return 1; end);
 	end
+	
+	-- Overwrite signal.signal() because we need to ask libevent to
+	-- handle them instead
+	local ok, signal = pcall(require, "util.signal");
+	if ok and signal then
+		local _signal_signal = signal.signal;
+		function signal.signal(signal_id, handler)
+			if type(signal_id) == "string" then
+				signal_id = signal[signal_id:upper()];
+			end
+			if type(signal_id) ~= "number" then
+				return false, "invalid-signal";
+			end
+			--_signal_signal(signal_id, handler);
+			return server.hook_signal(signal_id, handler);
+		end
+	end
 else
 	server = require "net.server_select";
 	package.loaded["net.server"] = server;