1 | /* |
1 | /* |
2 | * libevent compatibility layer |
2 | * libevent compatibility layer |
3 | * |
3 | * |
4 | * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008 Marc Alexander Lehmann <libev@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * modification, are permitted provided that the following conditions are |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * met: |
9 | * |
|
|
10 | * 1. Redistributions of source code must retain the above copyright notice, |
|
|
11 | * this list of conditions and the following disclaimer. |
|
|
12 | * |
|
|
13 | * 2. Redistributions in binary form must reproduce the above copyright |
|
|
14 | * notice, this list of conditions and the following disclaimer in the |
|
|
15 | * documentation and/or other materials provided with the distribution. |
|
|
16 | * |
|
|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
|
18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
|
|
19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
|
20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
|
|
21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
|
22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
|
23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
|
24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- |
|
|
25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
|
|
26 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
10 | * |
27 | * |
11 | * * Redistributions of source code must retain the above copyright |
28 | * Alternatively, the contents of this file may be used under the terms of |
12 | * notice, this list of conditions and the following disclaimer. |
29 | * the GNU General Public License ("GPL") version 2 or any later version, |
13 | * |
30 | * in which case the provisions of the GPL are applicable instead of |
14 | * * Redistributions in binary form must reproduce the above |
31 | * the above. If you wish to allow the use of your version of this file |
15 | * copyright notice, this list of conditions and the following |
32 | * only under the terms of the GPL and not to allow others to use your |
16 | * disclaimer in the documentation and/or other materials provided |
33 | * version of this file under the BSD license, indicate your decision |
17 | * with the distribution. |
34 | * by deleting the provisions above and replace them with the notice |
18 | * |
35 | * and other provisions required by the GPL. If you do not delete the |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
36 | * provisions above, a recipient may use your version of this file under |
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
37 | * either the BSD or the GPL. |
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
|
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
|
23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
|
24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
|
25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
|
26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
|
27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
|
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
|
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
30 | */ |
38 | */ |
31 | |
39 | |
32 | #include <stddef.h> |
40 | #include <stddef.h> |
33 | #include <stdlib.h> |
41 | #include <stdlib.h> |
|
|
42 | #include <assert.h> |
|
|
43 | |
|
|
44 | #ifndef WIN32 |
34 | #include <sys/time.h> |
45 | # include <sys/time.h> |
|
|
46 | #endif |
35 | |
47 | |
|
|
48 | #ifdef EV_EVENT_H |
|
|
49 | # include EV_EVENT_H |
|
|
50 | #else |
36 | #include "event.h" |
51 | # include "event.h" |
|
|
52 | #endif |
37 | |
53 | |
|
|
54 | #if EV_MULTIPLICITY |
|
|
55 | # define dLOOPev struct ev_loop *loop = (struct ev_loop *)ev->ev_base |
|
|
56 | # define dLOOPbase struct ev_loop *loop = (struct ev_loop *)base |
|
|
57 | #else |
|
|
58 | # define dLOOPev |
|
|
59 | # define dLOOPbase |
|
|
60 | #endif |
|
|
61 | |
|
|
62 | /* never accessed, will always be cast from/to ev_loop */ |
38 | struct event_base |
63 | struct event_base |
39 | { |
64 | { |
40 | int dummy; |
65 | int dummy; |
41 | }; |
66 | }; |
42 | |
67 | |
43 | static int x_actives; |
|
|
44 | |
|
|
45 | static struct event_base x_base, *x_cur; |
68 | static struct event_base *x_cur; |
46 | |
69 | |
47 | static void |
70 | static void |
48 | tv_set (struct timeval *tv, ev_tstamp at) |
71 | tv_set (struct timeval *tv, ev_tstamp at) |
49 | { |
72 | { |
50 | tv->tv_sec = (long)at; |
73 | tv->tv_sec = (long)at; |
… | |
… | |
72 | return "libev"; |
95 | return "libev"; |
73 | } |
96 | } |
74 | |
97 | |
75 | void *event_init (void) |
98 | void *event_init (void) |
76 | { |
99 | { |
77 | if (ev_init (0)) |
100 | #if EV_MULTIPLICITY |
78 | return x_cur = &x_base; |
101 | if (x_cur) |
|
|
102 | x_cur = (struct event_base *)ev_loop_new (EVFLAG_AUTO); |
|
|
103 | else |
|
|
104 | x_cur = (struct event_base *)ev_default_loop (EVFLAG_AUTO); |
|
|
105 | #else |
|
|
106 | assert (("multiple event bases not supported when not compiled with EV_MULTIPLICITY", !x_cur)); |
79 | |
107 | |
|
|
108 | x_cur = (struct event_base *)(long)ev_default_loop (EVFLAG_AUTO); |
|
|
109 | #endif |
|
|
110 | |
80 | return 0; |
111 | return x_cur; |
81 | } |
112 | } |
82 | |
113 | |
83 | void event_base_free (struct event_base *base) |
114 | void event_base_free (struct event_base *base) |
84 | { |
115 | { |
|
|
116 | dLOOPbase; |
|
|
117 | |
|
|
118 | #if EV_MULTIPLICITY |
|
|
119 | if (ev_default_loop (EVFLAG_AUTO) != loop) |
|
|
120 | ev_loop_destroy (loop); |
|
|
121 | #endif |
|
|
122 | } |
|
|
123 | |
|
|
124 | int event_dispatch (void) |
|
|
125 | { |
|
|
126 | return event_base_dispatch (x_cur); |
|
|
127 | } |
|
|
128 | |
|
|
129 | #ifdef EV_STANDALONE |
|
|
130 | void event_set_log_callback (event_log_cb cb) |
|
|
131 | { |
85 | /* nop */ |
132 | /* nop */ |
86 | } |
133 | } |
87 | |
134 | #endif |
88 | int event_dispatch (void) |
|
|
89 | { |
|
|
90 | return event_base_dispatch (x_cur); |
|
|
91 | } |
|
|
92 | |
|
|
93 | void event_set_log_callback (event_log_cb cb) |
|
|
94 | { |
|
|
95 | /* nop */ |
|
|
96 | } |
|
|
97 | |
135 | |
98 | int event_loop (int flags) |
136 | int event_loop (int flags) |
99 | { |
137 | { |
100 | return event_base_loop (x_cur, flags); |
138 | return event_base_loop (x_cur, flags); |
101 | } |
139 | } |
102 | |
140 | |
103 | int event_loopexit (struct timeval *tv) |
141 | int event_loopexit (struct timeval *tv) |
104 | { |
142 | { |
105 | event_base_loopexit (x_cur, tv); |
143 | return event_base_loopexit (x_cur, tv); |
106 | } |
144 | } |
107 | |
145 | |
108 | static void |
146 | static void |
109 | x_cb (struct event *ev, int revents) |
147 | x_cb (struct event *ev, int revents) |
110 | { |
148 | { |
|
|
149 | revents &= EV_READ | EV_WRITE | EV_TIMEOUT | EV_SIGNAL; |
|
|
150 | |
|
|
151 | ev->ev_res = revents; |
|
|
152 | ev->ev_callback (ev->ev_fd, (short)revents, ev->ev_arg); |
|
|
153 | } |
|
|
154 | |
|
|
155 | static void |
|
|
156 | x_cb_sig (EV_P_ struct ev_signal *w, int revents) |
|
|
157 | { |
|
|
158 | struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.sig)); |
|
|
159 | |
|
|
160 | if (revents & EV_ERROR) |
|
|
161 | event_del (ev); |
|
|
162 | |
|
|
163 | x_cb (ev, revents); |
|
|
164 | } |
|
|
165 | |
|
|
166 | static void |
|
|
167 | x_cb_io (EV_P_ struct ev_io *w, int revents) |
|
|
168 | { |
|
|
169 | struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.io)); |
|
|
170 | |
|
|
171 | if ((revents & EV_ERROR) || !(ev->ev_events & EV_PERSIST)) |
|
|
172 | event_del (ev); |
|
|
173 | |
|
|
174 | x_cb (ev, revents); |
|
|
175 | } |
|
|
176 | |
|
|
177 | static void |
|
|
178 | x_cb_to (EV_P_ struct ev_timer *w, int revents) |
|
|
179 | { |
|
|
180 | struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, to)); |
|
|
181 | |
|
|
182 | event_del (ev); |
|
|
183 | |
|
|
184 | x_cb (ev, revents); |
|
|
185 | } |
|
|
186 | |
|
|
187 | void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg) |
|
|
188 | { |
111 | if (ev->ev_events & EV_SIGNAL) |
189 | if (events & EV_SIGNAL) |
112 | { |
190 | ev_init (&ev->iosig.sig, x_cb_sig); |
113 | /* sig */ |
|
|
114 | if (ev_is_active (&ev->iosig.sig)) |
|
|
115 | { |
|
|
116 | ev_signal_stop (&ev->iosig.sig); |
|
|
117 | --x_actives; |
|
|
118 | } |
|
|
119 | } |
|
|
120 | else |
191 | else |
121 | { |
|
|
122 | /* io */ |
|
|
123 | if (!(ev->ev_events & EV_PERSIST) && ev_is_active (&ev->iosig.io)) |
|
|
124 | { |
|
|
125 | ev_io_stop (&ev->iosig.io); |
|
|
126 | --x_actives; |
|
|
127 | } |
|
|
128 | } |
|
|
129 | |
|
|
130 | revents &= EV_READ | EV_WRITE | EV_TIMEOUT | EV_SIGNAL; |
|
|
131 | |
|
|
132 | if (revents & EV_TIMEOUT) |
|
|
133 | --x_actives; |
|
|
134 | |
|
|
135 | ev->ev_res = revents; |
|
|
136 | ev->ev_callback (ev->ev_fd, revents, ev->ev_arg); |
|
|
137 | } |
|
|
138 | |
|
|
139 | static void |
|
|
140 | x_cb_io (struct ev_io *w, int revents) |
|
|
141 | { |
|
|
142 | x_cb ((struct event *)(((char *)w) - offsetof (struct event, iosig.io)), revents); |
|
|
143 | } |
|
|
144 | |
|
|
145 | static void |
|
|
146 | x_cb_to (struct ev_timer *w, int revents) |
|
|
147 | { |
|
|
148 | x_cb ((struct event *)(((char *)w) - offsetof (struct event, to)), revents); |
|
|
149 | } |
|
|
150 | |
|
|
151 | static void |
|
|
152 | x_cb_sig (struct ev_signal *w, int revents) |
|
|
153 | { |
|
|
154 | x_cb ((struct event *)(((char *)w) - offsetof (struct event, iosig.sig)), revents); |
|
|
155 | } |
|
|
156 | |
|
|
157 | void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg) |
|
|
158 | { |
|
|
159 | if (events & EV_SIGNAL) |
|
|
160 | ev_watcher_init (&ev->iosig.sig, x_cb_sig); |
|
|
161 | else |
|
|
162 | ev_watcher_init (&ev->iosig.io, x_cb_io); |
192 | ev_init (&ev->iosig.io, x_cb_io); |
163 | |
193 | |
164 | ev_watcher_init (&ev->to, x_cb_to); |
194 | ev_init (&ev->to, x_cb_to); |
165 | |
195 | |
166 | ev->ev_base = x_cur; |
196 | ev->ev_base = x_cur; /* not threadsafe, but its like libevent works */ |
167 | ev->ev_fd = fd; |
197 | ev->ev_fd = fd; |
168 | ev->ev_events = events; |
198 | ev->ev_events = events; |
169 | ev->ev_pri = 0; |
199 | ev->ev_pri = 0; |
170 | ev->ev_callback = cb; |
200 | ev->ev_callback = cb; |
171 | ev->ev_arg = arg; |
201 | ev->ev_arg = arg; |
172 | ev->ev_res = 0; |
202 | ev->ev_res = 0; |
|
|
203 | ev->ev_flags = EVLIST_INIT; |
173 | } |
204 | } |
174 | |
205 | |
175 | int event_once (int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) |
206 | int event_once (int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) |
176 | { |
207 | { |
177 | event_base_once (x_cur, fd, events, cb, arg, tv); |
208 | return event_base_once (x_cur, fd, events, cb, arg, tv); |
178 | } |
209 | } |
179 | |
210 | |
180 | int event_add (struct event *ev, struct timeval *tv) |
211 | int event_add (struct event *ev, struct timeval *tv) |
181 | { |
212 | { |
182 | /* disable all watchers */ |
213 | dLOOPev; |
183 | event_del (ev); |
|
|
184 | |
214 | |
185 | if (ev->ev_events & EV_SIGNAL) |
215 | if (ev->ev_events & EV_SIGNAL) |
186 | { |
216 | { |
|
|
217 | if (!ev_is_active (&ev->iosig.sig)) |
|
|
218 | { |
187 | ev_signal_set (&ev->iosig.sig, ev->ev_fd); |
219 | ev_signal_set (&ev->iosig.sig, ev->ev_fd); |
188 | ev_signal_start (&ev->iosig.sig); |
220 | ev_signal_start (EV_A_ &ev->iosig.sig); |
189 | ++x_actives; |
221 | |
|
|
222 | ev->ev_flags |= EVLIST_SIGNAL; |
|
|
223 | } |
190 | } |
224 | } |
191 | else if (ev->ev_events & (EV_READ | EV_WRITE)) |
225 | else if (ev->ev_events & (EV_READ | EV_WRITE)) |
192 | { |
226 | { |
|
|
227 | if (!ev_is_active (&ev->iosig.io)) |
|
|
228 | { |
193 | ev_io_set (&ev->iosig.io, ev->ev_fd, ev->ev_events & (EV_READ | EV_WRITE)); |
229 | ev_io_set (&ev->iosig.io, ev->ev_fd, ev->ev_events & (EV_READ | EV_WRITE)); |
194 | ev_io_start (&ev->iosig.io); |
230 | ev_io_start (EV_A_ &ev->iosig.io); |
195 | ++x_actives; |
231 | |
|
|
232 | ev->ev_flags |= EVLIST_INSERTED; |
|
|
233 | } |
196 | } |
234 | } |
197 | |
235 | |
198 | if (tv) |
236 | if (tv) |
199 | { |
237 | { |
200 | ev_timer_set (&ev->to, tv_get (tv), 0.); |
238 | ev->to.repeat = tv_get (tv); |
|
|
239 | ev_timer_again (EV_A_ &ev->to); |
|
|
240 | ev->ev_flags |= EVLIST_TIMEOUT; |
|
|
241 | } |
|
|
242 | else |
|
|
243 | { |
201 | ev_timer_start (&ev->to); |
244 | ev_timer_stop (EV_A_ &ev->to); |
202 | ++x_actives; |
245 | ev->ev_flags &= ~EVLIST_TIMEOUT; |
203 | } |
246 | } |
|
|
247 | |
|
|
248 | ev->ev_flags |= EVLIST_ACTIVE; |
204 | |
249 | |
205 | return 0; |
250 | return 0; |
206 | } |
251 | } |
207 | |
252 | |
208 | int event_del (struct event *ev) |
253 | int event_del (struct event *ev) |
209 | { |
254 | { |
|
|
255 | dLOOPev; |
|
|
256 | |
210 | if (ev->ev_events & EV_SIGNAL) |
257 | if (ev->ev_events & EV_SIGNAL) |
|
|
258 | ev_signal_stop (EV_A_ &ev->iosig.sig); |
|
|
259 | else if (ev->ev_events & (EV_READ | EV_WRITE)) |
|
|
260 | ev_io_stop (EV_A_ &ev->iosig.io); |
|
|
261 | |
|
|
262 | if (ev_is_active (&ev->to)) |
|
|
263 | ev_timer_stop (EV_A_ &ev->to); |
|
|
264 | |
|
|
265 | ev->ev_flags = EVLIST_INIT; |
|
|
266 | |
|
|
267 | return 0; |
|
|
268 | } |
|
|
269 | |
|
|
270 | void event_active (struct event *ev, int res, short ncalls) |
|
|
271 | { |
|
|
272 | dLOOPev; |
|
|
273 | |
|
|
274 | if (res & EV_TIMEOUT) |
|
|
275 | ev_feed_event (EV_A_ &ev->to, res & EV_TIMEOUT); |
|
|
276 | |
|
|
277 | if (res & EV_SIGNAL) |
|
|
278 | ev_feed_event (EV_A_ &ev->iosig.sig, res & EV_SIGNAL); |
|
|
279 | |
|
|
280 | if (res & (EV_READ | EV_WRITE)) |
|
|
281 | ev_feed_event (EV_A_ &ev->iosig.io, res & (EV_READ | EV_WRITE)); |
|
|
282 | } |
|
|
283 | |
|
|
284 | int event_pending (struct event *ev, short events, struct timeval *tv) |
|
|
285 | { |
|
|
286 | short revents = 0; |
|
|
287 | dLOOPev; |
|
|
288 | |
|
|
289 | if (ev->ev_events & EV_SIGNAL) |
211 | { |
290 | { |
212 | /* sig */ |
291 | /* sig */ |
213 | if (ev_is_active (&ev->iosig.sig)) |
292 | if (ev_is_active (&ev->iosig.sig) || ev_is_pending (&ev->iosig.sig)) |
214 | { |
293 | revents |= EV_SIGNAL; |
215 | ev_signal_stop (&ev->iosig.sig); |
|
|
216 | --x_actives; |
|
|
217 | } |
|
|
218 | } |
294 | } |
219 | else |
295 | else if (ev->ev_events & (EV_READ | EV_WRITE)) |
220 | { |
296 | { |
221 | /* io */ |
297 | /* io */ |
222 | if (ev_is_active (&ev->iosig.io)) |
298 | if (ev_is_active (&ev->iosig.io) || ev_is_pending (&ev->iosig.io)) |
223 | { |
|
|
224 | ev_io_stop (&ev->iosig.io); |
|
|
225 | --x_actives; |
|
|
226 | } |
|
|
227 | } |
|
|
228 | |
|
|
229 | if (ev_is_active (&ev->to)) |
|
|
230 | { |
|
|
231 | ev_timer_stop (&ev->to); |
|
|
232 | --x_actives; |
|
|
233 | } |
|
|
234 | |
|
|
235 | return 0; |
|
|
236 | } |
|
|
237 | |
|
|
238 | int event_pending (struct event *ev, short events, struct timeval *tv) |
|
|
239 | { |
|
|
240 | short revents; |
|
|
241 | |
|
|
242 | if (ev->ev_events & EV_SIGNAL) |
|
|
243 | { |
|
|
244 | /* sig */ |
|
|
245 | if (ev->iosig.sig.pending) |
|
|
246 | revents |= EV_SIGNAL; |
|
|
247 | } |
|
|
248 | else |
|
|
249 | { |
|
|
250 | /* io */ |
|
|
251 | if (ev->iosig.io.pending) |
|
|
252 | revents |= ev->ev_events & (EV_READ | EV_WRITE); |
299 | revents |= ev->ev_events & (EV_READ | EV_WRITE); |
253 | } |
300 | } |
254 | |
301 | |
255 | if (ev->to.pending) |
302 | if (ev->ev_events & EV_TIMEOUT || ev_is_active (&ev->to) || ev_is_pending (&ev->to)) |
256 | { |
303 | { |
257 | revents |= EV_TIMEOUT; |
304 | revents |= EV_TIMEOUT; |
258 | |
305 | |
259 | if (tv) |
306 | if (tv) |
260 | tv_set (tv, ev_now); /* not sure if this is right :) */ |
307 | tv_set (tv, ev_now (EV_A)); /* not sure if this is right :) */ |
261 | } |
308 | } |
262 | |
309 | |
263 | return events & revents; |
310 | return events & revents; |
264 | } |
311 | } |
265 | |
312 | |
… | |
… | |
282 | return 0; |
329 | return 0; |
283 | } |
330 | } |
284 | |
331 | |
285 | int event_base_loop (struct event_base *base, int flags) |
332 | int event_base_loop (struct event_base *base, int flags) |
286 | { |
333 | { |
287 | do |
334 | dLOOPbase; |
288 | { |
335 | |
289 | ev_loop (flags | EVLOOP_ONESHOT); |
336 | ev_loop (EV_A_ flags); |
290 | } |
|
|
291 | while (!(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) && x_actives && !ev_loop_done); |
|
|
292 | |
337 | |
293 | return 0; |
338 | return 0; |
294 | } |
339 | } |
295 | |
340 | |
296 | int event_base_dispatch (struct event_base *base) |
341 | int event_base_dispatch (struct event_base *base) |
297 | { |
342 | { |
298 | return event_base_loop (base, 0); |
343 | return event_base_loop (base, 0); |
299 | } |
344 | } |
300 | |
345 | |
301 | static void |
346 | static void |
302 | x_loopexit_cb (int revents, void *arg) |
347 | x_loopexit_cb (int revents, void *base) |
303 | { |
348 | { |
304 | ev_loop_done = 2; |
349 | dLOOPbase; |
|
|
350 | |
|
|
351 | ev_unloop (EV_A_ EVUNLOOP_ONE); |
305 | } |
352 | } |
306 | |
353 | |
307 | int event_base_loopexit (struct event_base *base, struct timeval *tv) |
354 | int event_base_loopexit (struct event_base *base, struct timeval *tv) |
308 | { |
355 | { |
309 | ev_tstamp after = tv_get (tv); |
356 | ev_tstamp after = tv_get (tv); |
|
|
357 | dLOOPbase; |
310 | |
358 | |
311 | ev_once (-1, 0, after >= 0. ? after : 0., x_loopexit_cb, (void *)base); |
359 | ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., x_loopexit_cb, (void *)base); |
|
|
360 | |
|
|
361 | return 0; |
312 | } |
362 | } |
313 | |
363 | |
314 | struct x_once |
364 | struct x_once |
315 | { |
365 | { |
316 | int fd; |
366 | int fd; |
… | |
… | |
319 | }; |
369 | }; |
320 | |
370 | |
321 | static void |
371 | static void |
322 | x_once_cb (int revents, void *arg) |
372 | x_once_cb (int revents, void *arg) |
323 | { |
373 | { |
324 | struct x_once *once = arg; |
374 | struct x_once *once = (struct x_once *)arg; |
325 | |
375 | |
326 | once->cb (once->fd, revents, once->arg); |
376 | once->cb (once->fd, (short)revents, once->arg); |
327 | free (once); |
377 | free (once); |
328 | } |
378 | } |
329 | |
379 | |
330 | int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) |
380 | int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) |
331 | { |
381 | { |
332 | struct x_once *once = malloc (sizeof (struct x_once)); |
382 | struct x_once *once = (struct x_once *)malloc (sizeof (struct x_once)); |
|
|
383 | dLOOPbase; |
333 | |
384 | |
334 | if (!once) |
385 | if (!once) |
335 | return -1; |
386 | return -1; |
336 | |
387 | |
337 | once->fd = fd; |
388 | once->fd = fd; |
338 | once->cb = cb; |
389 | once->cb = cb; |
339 | once->arg = arg; |
390 | once->arg = arg; |
340 | |
391 | |
341 | ev_once (fd, events & (EV_READ | EV_WRITE), tv_get (tv), x_once_cb, (void *)once); |
392 | ev_once (EV_A_ fd, events & (EV_READ | EV_WRITE), tv_get (tv), x_once_cb, (void *)once); |
342 | |
393 | |
343 | return 0; |
394 | return 0; |
344 | } |
395 | } |
345 | |
396 | |
346 | int event_base_priority_init (struct event_base *base, int npri) |
397 | int event_base_priority_init (struct event_base *base, int npri) |
347 | { |
398 | { |
348 | return 0; |
399 | /*dLOOPbase;*/ |
349 | } |
|
|
350 | |
400 | |
|
|
401 | return 0; |
|
|
402 | } |
|
|
403 | |