Software /
code /
prosody
Comparison
net/server_event.lua @ 2434:4403d4473783
net.server_event: Add server.hook_signal(signal_num, handler) to wrap libevent's signal-catching interface
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 10 Jan 2010 15:25:19 +0000 |
parent | 2375:31297a5641e3 |
child | 2453:44d4c69155e0 |
comparison
equal
deleted
inserted
replaced
2433:65b794860e1b | 2434:4403d4473783 |
---|---|
10 -- to do some of the above, use timeout events or something what will called from outside | 10 -- to do some of the above, use timeout events or something what will called from outside |
11 -- dont let garbagecollect eventcallbacks, as long they are running | 11 -- dont let garbagecollect eventcallbacks, as long they are running |
12 -- when using luasec, there are 4 cases of timeout errors: wantread or wantwrite during reading or writing | 12 -- when using luasec, there are 4 cases of timeout errors: wantread or wantwrite during reading or writing |
13 | 13 |
14 --]] | 14 --]] |
15 | |
16 | 15 |
17 local SCRIPT_NAME = "server_event.lua" | 16 local SCRIPT_NAME = "server_event.lua" |
18 local SCRIPT_VERSION = "0.05" | 17 local SCRIPT_VERSION = "0.05" |
19 local SCRIPT_AUTHOR = "blastbeat" | 18 local SCRIPT_AUTHOR = "blastbeat" |
20 local LAST_MODIFIED = "2009/11/20" | 19 local LAST_MODIFIED = "2009/11/20" |
75 local event = require "luaevent.core" | 74 local event = require "luaevent.core" |
76 local base = event.new( ) | 75 local base = event.new( ) |
77 local EV_READ = event.EV_READ | 76 local EV_READ = event.EV_READ |
78 local EV_WRITE = event.EV_WRITE | 77 local EV_WRITE = event.EV_WRITE |
79 local EV_TIMEOUT = event.EV_TIMEOUT | 78 local EV_TIMEOUT = event.EV_TIMEOUT |
79 local EV_SIGNAL = event.EV_SIGNAL | |
80 | 80 |
81 local EV_READWRITE = bitor( EV_READ, EV_WRITE ) | 81 local EV_READWRITE = bitor( EV_READ, EV_WRITE ) |
82 | 82 |
83 local interfacelist = ( function( ) -- holds the interfaces for sockets | 83 local interfacelist = ( function( ) -- holds the interfaces for sockets |
84 local array = { } | 84 local array = { } |
784 | 784 |
785 function get_backend() | 785 function get_backend() |
786 return base:method(); | 786 return base:method(); |
787 end | 787 end |
788 | 788 |
789 -- We need to hold onto the events to stop them | |
790 -- being garbage-collected | |
791 local signal_events = {}; -- [signal_num] -> event object | |
792 function hook_signal(signal_num, handler) | |
793 local function _handler(event) | |
794 local ret = handler(); | |
795 if ret ~= false then -- Continue handling this signal? | |
796 return EV_SIGNAL; -- Yes | |
797 end | |
798 return -1; -- Close this event | |
799 end | |
800 signal_events[signal_num] = base:addevent(signal_num, EV_SIGNAL, _handler); | |
801 return signal_events[signal_num]; | |
802 end | |
803 | |
789 return { | 804 return { |
790 | 805 |
791 cfg = cfg, | 806 cfg = cfg, |
792 base = base, | 807 base = base, |
793 loop = loop, | 808 loop = loop, |
798 addclient = addclient, | 813 addclient = addclient, |
799 wrapclient = wrapclient, | 814 wrapclient = wrapclient, |
800 setquitting = setquitting, | 815 setquitting = setquitting, |
801 closeall = closeallservers, | 816 closeall = closeallservers, |
802 get_backend = get_backend, | 817 get_backend = get_backend, |
818 hook_signal = hook_signal, | |
803 | 819 |
804 __NAME = SCRIPT_NAME, | 820 __NAME = SCRIPT_NAME, |
805 __DATE = LAST_MODIFIED, | 821 __DATE = LAST_MODIFIED, |
806 __AUTHOR = SCRIPT_AUTHOR, | 822 __AUTHOR = SCRIPT_AUTHOR, |
807 __VERSION = SCRIPT_VERSION, | 823 __VERSION = SCRIPT_VERSION, |