Wed, 07 Apr 2010 21:00:20 +0100
util.timer: When using libevent hold onto the event handle to stop it being collected (and the timer stopping). Fixes BOSH ghosts, thanks Flo, niekie, waqas.
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1514
diff
changeset
|
1 | -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
2 | -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
3 | -- Copyright (C) 2008-2010 Waqas Hussain |
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1514
diff
changeset
|
4 | -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1514
diff
changeset
|
5 | -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1514
diff
changeset
|
6 | -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1514
diff
changeset
|
7 | -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1514
diff
changeset
|
8 | |
1514
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
9 | |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
10 | local t_insert = table.insert; |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
11 | local ipairs = ipairs; |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
12 | |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
13 | module "eventmanager" |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
14 | |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
15 | local event_handlers = {}; |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
16 | |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
17 | function add_event_hook(name, handler) |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
18 | if not event_handlers[name] then |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
19 | event_handlers[name] = {}; |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
20 | end |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
21 | t_insert(event_handlers[name] , handler); |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
22 | end |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
23 | |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
24 | function fire_event(name, ...) |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
25 | local event_handlers = event_handlers[name]; |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
26 | if event_handlers then |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
27 | for name, handler in ipairs(event_handlers) do |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
28 | handler(...); |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
29 | end |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
30 | end |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
31 | end |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
32 | |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | return _M; |