Software /
code /
prosody
Comparison
net/server.lua @ 4808:07d0a3a75c8a
net.server, net.timer, net.server_select: Rearrange dependencies between these three modules. server.addtimer() is no longer a public function (renamed to _addtimer) and is not available at all from server_event (compat code removed to prevent traceback) (thanks Nulani)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 03 May 2012 16:48:34 +0100 |
parent | 3461:447634564356 |
child | 4811:1d1fdfa29f06 |
comparison
equal
deleted
inserted
replaced
4807:2999f0fd1347 | 4808:07d0a3a75c8a |
---|---|
16 end | 16 end |
17 | 17 |
18 local server; | 18 local server; |
19 | 19 |
20 if use_luaevent then | 20 if use_luaevent then |
21 server = require "net.server_event"; | 21 server = require "net.server_select"; |
22 -- util.timer requires "net.server", so instead of having | 22 |
23 -- Lua look for, and load us again (causing a loop) - set this here | |
24 -- (usually it isn't set until we return, look down there...) | |
25 package.loaded["net.server"] = server; | |
26 | |
27 -- Backwards compatibility for timers, addtimer | |
28 -- called a function roughly every second | |
29 local add_task = require "util.timer".add_task; | |
30 function server.addtimer(f) | |
31 return add_task(1, function (...) f(...); return 1; end); | |
32 end | |
33 | |
34 -- Overwrite signal.signal() because we need to ask libevent to | 23 -- Overwrite signal.signal() because we need to ask libevent to |
35 -- handle them instead | 24 -- handle them instead |
36 local ok, signal = pcall(require, "util.signal"); | 25 local ok, signal = pcall(require, "util.signal"); |
37 if ok and signal then | 26 if ok and signal then |
38 local _signal_signal = signal.signal; | 27 local _signal_signal = signal.signal; |
46 return server.hook_signal(signal_id, handler); | 35 return server.hook_signal(signal_id, handler); |
47 end | 36 end |
48 end | 37 end |
49 else | 38 else |
50 server = require "net.server_select"; | 39 server = require "net.server_select"; |
51 package.loaded["net.server"] = server; | |
52 end | 40 end |
53 | 41 |
54 -- require "net.server" shall now forever return this, | 42 -- require "net.server" shall now forever return this, |
55 -- ie. server_select or server_event as chosen above. | 43 -- ie. server_select or server_event as chosen above. |
56 return server; | 44 return server; |