evdispatch 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/License.txt +20 -0
- data/Manifest.txt +96 -0
- data/README.txt +73 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +15 -0
- data/ext/revdispatch/extconf.rb +31 -0
- data/ext/revdispatch/libevdispatch/Changelog +0 -0
- data/ext/revdispatch/libevdispatch/LICENSE +0 -0
- data/ext/revdispatch/libevdispatch/Makefile.am +10 -0
- data/ext/revdispatch/libevdispatch/Makefile.in +637 -0
- data/ext/revdispatch/libevdispatch/README +3 -0
- data/ext/revdispatch/libevdispatch/TODO +5 -0
- data/ext/revdispatch/libevdispatch/aclocal.m4 +7459 -0
- data/ext/revdispatch/libevdispatch/autogen.sh +11 -0
- data/ext/revdispatch/libevdispatch/confdefs.h +32 -0
- data/ext/revdispatch/libevdispatch/config.guess +1516 -0
- data/ext/revdispatch/libevdispatch/config.h.in +112 -0
- data/ext/revdispatch/libevdispatch/config.sub +1626 -0
- data/ext/revdispatch/libevdispatch/configure +21949 -0
- data/ext/revdispatch/libevdispatch/configure.ac +40 -0
- data/ext/revdispatch/libevdispatch/depcomp +584 -0
- data/ext/revdispatch/libevdispatch/install-sh +507 -0
- data/ext/revdispatch/libevdispatch/libev/Changes +54 -0
- data/ext/revdispatch/libevdispatch/libev/LICENSE +25 -0
- data/ext/revdispatch/libevdispatch/libev/Makefile.am +18 -0
- data/ext/revdispatch/libevdispatch/libev/Makefile.in +677 -0
- data/ext/revdispatch/libevdispatch/libev/README +130 -0
- data/ext/revdispatch/libevdispatch/libev/aclocal.m4 +7430 -0
- data/ext/revdispatch/libevdispatch/libev/autogen.sh +7 -0
- data/ext/revdispatch/libevdispatch/libev/config.guess +1516 -0
- data/ext/revdispatch/libevdispatch/libev/config.h.in +106 -0
- data/ext/revdispatch/libevdispatch/libev/config.sub +1626 -0
- data/ext/revdispatch/libevdispatch/libev/configure +21636 -0
- data/ext/revdispatch/libevdispatch/libev/configure.ac +18 -0
- data/ext/revdispatch/libevdispatch/libev/ev++.h +779 -0
- data/ext/revdispatch/libevdispatch/libev/ev.3 +3276 -0
- data/ext/revdispatch/libevdispatch/libev/ev.c +2547 -0
- data/ext/revdispatch/libevdispatch/libev/ev.h +608 -0
- data/ext/revdispatch/libevdispatch/libev/ev.pod +3192 -0
- data/ext/revdispatch/libevdispatch/libev/ev_epoll.c +182 -0
- data/ext/revdispatch/libevdispatch/libev/ev_kqueue.c +194 -0
- data/ext/revdispatch/libevdispatch/libev/ev_poll.c +135 -0
- data/ext/revdispatch/libevdispatch/libev/ev_port.c +163 -0
- data/ext/revdispatch/libevdispatch/libev/ev_select.c +244 -0
- data/ext/revdispatch/libevdispatch/libev/ev_vars.h +157 -0
- data/ext/revdispatch/libevdispatch/libev/ev_win32.c +125 -0
- data/ext/revdispatch/libevdispatch/libev/ev_wrap.h +144 -0
- data/ext/revdispatch/libevdispatch/libev/event.c +404 -0
- data/ext/revdispatch/libevdispatch/libev/event.h +152 -0
- data/ext/revdispatch/libevdispatch/libev/install-sh +294 -0
- data/ext/revdispatch/libevdispatch/libev/libev.m4 +28 -0
- data/ext/revdispatch/libevdispatch/libev/ltmain.sh +6930 -0
- data/ext/revdispatch/libevdispatch/libev/missing +336 -0
- data/ext/revdispatch/libevdispatch/libev/mkinstalldirs +111 -0
- data/ext/revdispatch/libevdispatch/ltmain.sh +6930 -0
- data/ext/revdispatch/libevdispatch/missing +367 -0
- data/ext/revdispatch/libevdispatch/src/Makefile.am +11 -0
- data/ext/revdispatch/libevdispatch/src/Makefile.in +486 -0
- data/ext/revdispatch/libevdispatch/src/ev_dispatch.cc +264 -0
- data/ext/revdispatch/libevdispatch/src/ev_dispatch.h +300 -0
- data/ext/revdispatch/libevdispatch/src/ev_http.cc +238 -0
- data/ext/revdispatch/libevdispatch/src/ev_http.h +65 -0
- data/ext/revdispatch/libevdispatch/test/Makefile.am +16 -0
- data/ext/revdispatch/libevdispatch/test/Makefile.in +513 -0
- data/ext/revdispatch/libevdispatch/test/helper.rb +94 -0
- data/ext/revdispatch/libevdispatch/test/key_test.cc +52 -0
- data/ext/revdispatch/libevdispatch/test/next_test.cc +86 -0
- data/ext/revdispatch/libevdispatch/test/next_test.rb +8 -0
- data/ext/revdispatch/libevdispatch/test/server.rb +9 -0
- data/ext/revdispatch/revdispatch.cc +151 -0
- data/ext/revdispatch/server.rb +60 -0
- data/ext/revdispatch/test.rb +100 -0
- data/lib/evdispatch/loop.rb +16 -0
- data/lib/evdispatch/version.rb +9 -0
- data/lib/evdispatch.rb +8 -0
- data/log/debug.log +0 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/extconf/revdispatch.rake +43 -0
- data/tasks/extconf.rake +13 -0
- data/tasks/website.rake +17 -0
- data/test/test_evdispatch.rb +11 -0
- data/test/test_helper.rb +3 -0
- data/test/test_revdispatch_extn.rb +14 -0
- data/website/index.html +128 -0
- data/website/index.txt +55 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +49 -0
- metadata +157 -0
@@ -0,0 +1,404 @@
|
|
1
|
+
/*
|
2
|
+
* libevent compatibility layer
|
3
|
+
*
|
4
|
+
* Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* Redistribution and use in source and binary forms, with or without modifica-
|
8
|
+
* tion, are permitted provided that the following conditions are 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.
|
27
|
+
*
|
28
|
+
* Alternatively, the contents of this file may be used under the terms of
|
29
|
+
* the GNU General Public License ("GPL") version 2 or any later version,
|
30
|
+
* in which case the provisions of the GPL are applicable instead of
|
31
|
+
* the above. If you wish to allow the use of your version of this file
|
32
|
+
* only under the terms of the GPL and not to allow others to use your
|
33
|
+
* version of this file under the BSD license, indicate your decision
|
34
|
+
* by deleting the provisions above and replace them with the notice
|
35
|
+
* and other provisions required by the GPL. If you do not delete the
|
36
|
+
* provisions above, a recipient may use your version of this file under
|
37
|
+
* either the BSD or the GPL.
|
38
|
+
*/
|
39
|
+
|
40
|
+
#include <stddef.h>
|
41
|
+
#include <stdlib.h>
|
42
|
+
#include <assert.h>
|
43
|
+
|
44
|
+
#ifndef WIN32
|
45
|
+
# include <sys/time.h>
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#ifdef EV_EVENT_H
|
49
|
+
# include EV_EVENT_H
|
50
|
+
#else
|
51
|
+
# include "event.h"
|
52
|
+
#endif
|
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 */
|
63
|
+
struct event_base
|
64
|
+
{
|
65
|
+
int dummy;
|
66
|
+
};
|
67
|
+
|
68
|
+
static struct event_base *x_cur;
|
69
|
+
|
70
|
+
static void
|
71
|
+
tv_set (struct timeval *tv, ev_tstamp at)
|
72
|
+
{
|
73
|
+
tv->tv_sec = (long)at;
|
74
|
+
tv->tv_usec = (long)((at - (ev_tstamp)tv->tv_sec) * 1e6);
|
75
|
+
}
|
76
|
+
|
77
|
+
static ev_tstamp
|
78
|
+
tv_get (struct timeval *tv)
|
79
|
+
{
|
80
|
+
if (tv)
|
81
|
+
return tv->tv_sec + tv->tv_usec * 1e-6;
|
82
|
+
else
|
83
|
+
return -1.;
|
84
|
+
}
|
85
|
+
|
86
|
+
#define EVENT_VERSION(a,b) # a "." # b
|
87
|
+
|
88
|
+
const char *event_get_version (void)
|
89
|
+
{
|
90
|
+
return EVENT_VERSION (EV_VERSION_MAJOR, EV_VERSION_MINOR);
|
91
|
+
}
|
92
|
+
|
93
|
+
const char *event_get_method (void)
|
94
|
+
{
|
95
|
+
return "libev";
|
96
|
+
}
|
97
|
+
|
98
|
+
void *event_init (void)
|
99
|
+
{
|
100
|
+
#if EV_MULTIPLICITY
|
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));
|
107
|
+
|
108
|
+
x_cur = (struct event_base *)(long)ev_default_loop (EVFLAG_AUTO);
|
109
|
+
#endif
|
110
|
+
|
111
|
+
return x_cur;
|
112
|
+
}
|
113
|
+
|
114
|
+
void event_base_free (struct event_base *base)
|
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
|
+
{
|
132
|
+
/* nop */
|
133
|
+
}
|
134
|
+
#endif
|
135
|
+
|
136
|
+
int event_loop (int flags)
|
137
|
+
{
|
138
|
+
return event_base_loop (x_cur, flags);
|
139
|
+
}
|
140
|
+
|
141
|
+
int event_loopexit (struct timeval *tv)
|
142
|
+
{
|
143
|
+
return event_base_loopexit (x_cur, tv);
|
144
|
+
}
|
145
|
+
|
146
|
+
static void
|
147
|
+
x_cb (struct event *ev, int revents)
|
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
|
+
{
|
189
|
+
if (events & EV_SIGNAL)
|
190
|
+
ev_init (&ev->iosig.sig, x_cb_sig);
|
191
|
+
else
|
192
|
+
ev_init (&ev->iosig.io, x_cb_io);
|
193
|
+
|
194
|
+
ev_init (&ev->to, x_cb_to);
|
195
|
+
|
196
|
+
ev->ev_base = x_cur; /* not threadsafe, but its like libevent works */
|
197
|
+
ev->ev_fd = fd;
|
198
|
+
ev->ev_events = events;
|
199
|
+
ev->ev_pri = 0;
|
200
|
+
ev->ev_callback = cb;
|
201
|
+
ev->ev_arg = arg;
|
202
|
+
ev->ev_res = 0;
|
203
|
+
ev->ev_flags = EVLIST_INIT;
|
204
|
+
}
|
205
|
+
|
206
|
+
int event_once (int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv)
|
207
|
+
{
|
208
|
+
return event_base_once (x_cur, fd, events, cb, arg, tv);
|
209
|
+
}
|
210
|
+
|
211
|
+
int event_add (struct event *ev, struct timeval *tv)
|
212
|
+
{
|
213
|
+
dLOOPev;
|
214
|
+
|
215
|
+
if (ev->ev_events & EV_SIGNAL)
|
216
|
+
{
|
217
|
+
if (!ev_is_active (&ev->iosig.sig))
|
218
|
+
{
|
219
|
+
ev_signal_set (&ev->iosig.sig, ev->ev_fd);
|
220
|
+
ev_signal_start (EV_A_ &ev->iosig.sig);
|
221
|
+
|
222
|
+
ev->ev_flags |= EVLIST_SIGNAL;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
else if (ev->ev_events & (EV_READ | EV_WRITE))
|
226
|
+
{
|
227
|
+
if (!ev_is_active (&ev->iosig.io))
|
228
|
+
{
|
229
|
+
ev_io_set (&ev->iosig.io, ev->ev_fd, ev->ev_events & (EV_READ | EV_WRITE));
|
230
|
+
ev_io_start (EV_A_ &ev->iosig.io);
|
231
|
+
|
232
|
+
ev->ev_flags |= EVLIST_INSERTED;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
if (tv)
|
237
|
+
{
|
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
|
+
{
|
244
|
+
ev_timer_stop (EV_A_ &ev->to);
|
245
|
+
ev->ev_flags &= ~EVLIST_TIMEOUT;
|
246
|
+
}
|
247
|
+
|
248
|
+
ev->ev_flags |= EVLIST_ACTIVE;
|
249
|
+
|
250
|
+
return 0;
|
251
|
+
}
|
252
|
+
|
253
|
+
int event_del (struct event *ev)
|
254
|
+
{
|
255
|
+
dLOOPev;
|
256
|
+
|
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
|
+
|
290
|
+
if (ev->ev_events & EV_SIGNAL)
|
291
|
+
{
|
292
|
+
/* sig */
|
293
|
+
if (ev_is_active (&ev->iosig.sig) || ev_is_pending (&ev->iosig.sig))
|
294
|
+
revents |= EV_SIGNAL;
|
295
|
+
}
|
296
|
+
else if (ev->ev_events & (EV_READ | EV_WRITE))
|
297
|
+
{
|
298
|
+
/* io */
|
299
|
+
if (ev_is_active (&ev->iosig.io) || ev_is_pending (&ev->iosig.io))
|
300
|
+
revents |= ev->ev_events & (EV_READ | EV_WRITE);
|
301
|
+
}
|
302
|
+
|
303
|
+
if (ev->ev_events & EV_TIMEOUT || ev_is_active (&ev->to) || ev_is_pending (&ev->to))
|
304
|
+
{
|
305
|
+
revents |= EV_TIMEOUT;
|
306
|
+
|
307
|
+
if (tv)
|
308
|
+
tv_set (tv, ev_now (EV_A)); /* not sure if this is right :) */
|
309
|
+
}
|
310
|
+
|
311
|
+
return events & revents;
|
312
|
+
}
|
313
|
+
|
314
|
+
int event_priority_init (int npri)
|
315
|
+
{
|
316
|
+
return event_base_priority_init (x_cur, npri);
|
317
|
+
}
|
318
|
+
|
319
|
+
int event_priority_set (struct event *ev, int pri)
|
320
|
+
{
|
321
|
+
ev->ev_pri = pri;
|
322
|
+
|
323
|
+
return 0;
|
324
|
+
}
|
325
|
+
|
326
|
+
int event_base_set (struct event_base *base, struct event *ev)
|
327
|
+
{
|
328
|
+
ev->ev_base = base;
|
329
|
+
|
330
|
+
return 0;
|
331
|
+
}
|
332
|
+
|
333
|
+
int event_base_loop (struct event_base *base, int flags)
|
334
|
+
{
|
335
|
+
dLOOPbase;
|
336
|
+
|
337
|
+
ev_loop (EV_A_ flags);
|
338
|
+
|
339
|
+
return 0;
|
340
|
+
}
|
341
|
+
|
342
|
+
int event_base_dispatch (struct event_base *base)
|
343
|
+
{
|
344
|
+
return event_base_loop (base, 0);
|
345
|
+
}
|
346
|
+
|
347
|
+
static void
|
348
|
+
x_loopexit_cb (int revents, void *base)
|
349
|
+
{
|
350
|
+
dLOOPbase;
|
351
|
+
|
352
|
+
ev_unloop (EV_A_ EVUNLOOP_ONE);
|
353
|
+
}
|
354
|
+
|
355
|
+
int event_base_loopexit (struct event_base *base, struct timeval *tv)
|
356
|
+
{
|
357
|
+
ev_tstamp after = tv_get (tv);
|
358
|
+
dLOOPbase;
|
359
|
+
|
360
|
+
ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., x_loopexit_cb, (void *)base);
|
361
|
+
|
362
|
+
return -1;
|
363
|
+
}
|
364
|
+
|
365
|
+
struct x_once
|
366
|
+
{
|
367
|
+
int fd;
|
368
|
+
void (*cb)(int, short, void *);
|
369
|
+
void *arg;
|
370
|
+
};
|
371
|
+
|
372
|
+
static void
|
373
|
+
x_once_cb (int revents, void *arg)
|
374
|
+
{
|
375
|
+
struct x_once *once = (struct x_once *)arg;
|
376
|
+
|
377
|
+
once->cb (once->fd, (short)revents, once->arg);
|
378
|
+
free (once);
|
379
|
+
}
|
380
|
+
|
381
|
+
int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv)
|
382
|
+
{
|
383
|
+
struct x_once *once = (struct x_once *)malloc (sizeof (struct x_once));
|
384
|
+
dLOOPbase;
|
385
|
+
|
386
|
+
if (!once)
|
387
|
+
return -1;
|
388
|
+
|
389
|
+
once->fd = fd;
|
390
|
+
once->cb = cb;
|
391
|
+
once->arg = arg;
|
392
|
+
|
393
|
+
ev_once (EV_A_ fd, events & (EV_READ | EV_WRITE), tv_get (tv), x_once_cb, (void *)once);
|
394
|
+
|
395
|
+
return 0;
|
396
|
+
}
|
397
|
+
|
398
|
+
int event_base_priority_init (struct event_base *base, int npri)
|
399
|
+
{
|
400
|
+
/*dLOOPbase;*/
|
401
|
+
|
402
|
+
return 0;
|
403
|
+
}
|
404
|
+
|
@@ -0,0 +1,152 @@
|
|
1
|
+
/*
|
2
|
+
* libevent compatibility header, only core events supported
|
3
|
+
*
|
4
|
+
* Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* Redistribution and use in source and binary forms, with or without modifica-
|
8
|
+
* tion, are permitted provided that the following conditions are 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.
|
27
|
+
*
|
28
|
+
* Alternatively, the contents of this file may be used under the terms of
|
29
|
+
* the GNU General Public License ("GPL") version 2 or any later version,
|
30
|
+
* in which case the provisions of the GPL are applicable instead of
|
31
|
+
* the above. If you wish to allow the use of your version of this file
|
32
|
+
* only under the terms of the GPL and not to allow others to use your
|
33
|
+
* version of this file under the BSD license, indicate your decision
|
34
|
+
* by deleting the provisions above and replace them with the notice
|
35
|
+
* and other provisions required by the GPL. If you do not delete the
|
36
|
+
* provisions above, a recipient may use your version of this file under
|
37
|
+
* either the BSD or the GPL.
|
38
|
+
*/
|
39
|
+
|
40
|
+
#ifndef EVENT_H__
|
41
|
+
#define EVENT_H__
|
42
|
+
|
43
|
+
#ifdef EV_H
|
44
|
+
# include EV_H
|
45
|
+
#else
|
46
|
+
# include "ev.h"
|
47
|
+
#endif
|
48
|
+
|
49
|
+
#ifdef __cplusplus
|
50
|
+
extern "C" {
|
51
|
+
#endif
|
52
|
+
|
53
|
+
struct event_base;
|
54
|
+
|
55
|
+
#define EVLIST_TIMEOUT 0x01
|
56
|
+
#define EVLIST_INSERTED 0x02
|
57
|
+
#define EVLIST_SIGNAL 0x04
|
58
|
+
#define EVLIST_ACTIVE 0x08
|
59
|
+
#define EVLIST_INTERNAL 0x10
|
60
|
+
#define EVLIST_INIT 0x80
|
61
|
+
|
62
|
+
struct event
|
63
|
+
{
|
64
|
+
/* libev watchers we map onto */
|
65
|
+
union {
|
66
|
+
struct ev_io io;
|
67
|
+
struct ev_signal sig;
|
68
|
+
} iosig;
|
69
|
+
struct ev_timer to;
|
70
|
+
|
71
|
+
/* compatibility slots */
|
72
|
+
struct event_base *ev_base;
|
73
|
+
void (*ev_callback)(int, short, void *arg);
|
74
|
+
void *ev_arg;
|
75
|
+
int ev_fd;
|
76
|
+
int ev_pri;
|
77
|
+
int ev_res;
|
78
|
+
int ev_flags;
|
79
|
+
short ev_events;
|
80
|
+
};
|
81
|
+
|
82
|
+
#define EV_PERSIST 0x10
|
83
|
+
|
84
|
+
#define EVENT_SIGNAL(ev) ((int) (ev)->ev_fd)
|
85
|
+
#define EVENT_FD(ev) ((int) (ev)->ev_fd)
|
86
|
+
|
87
|
+
#define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT)
|
88
|
+
|
89
|
+
#define evtimer_add(ev,tv) event_add (ev, tv)
|
90
|
+
#define evtimer_set(ev,cb,data) event_set (ev, -1, 0, cb, data)
|
91
|
+
#define evtimer_del(ev) event_del (ev)
|
92
|
+
#define evtimer_pending(ev,tv) event_pending (ev, EV_TIMEOUT, tv)
|
93
|
+
#define evtimer_initialized(ev) event_initialized (ev)
|
94
|
+
|
95
|
+
#define timeout_add(ev,tv) evtimer_add (ev, tv)
|
96
|
+
#define timeout_set(ev,cb,data) evtimer_set (ev, cb, data)
|
97
|
+
#define timeout_del(ev) evtimer_del (ev)
|
98
|
+
#define timeout_pending(ev,tv) evtimer_pending (ev, tv)
|
99
|
+
#define timeout_initialized(ev) evtimer_initialized (ev)
|
100
|
+
|
101
|
+
#define signal_add(ev,tv) event_add (ev, tv)
|
102
|
+
#define signal_set(ev,sig,cb,data) event_set (ev, sig, EV_SIGNAL | EV_PERSIST, cb, data)
|
103
|
+
#define signal_del(ev) event_del (ev)
|
104
|
+
#define signal_pending(ev,tv) event_pending (ev, EV_SIGNAL, tv)
|
105
|
+
#define signal_initialized(ev) event_initialized (ev)
|
106
|
+
|
107
|
+
const char *event_get_version (void);
|
108
|
+
const char *event_get_method (void);
|
109
|
+
|
110
|
+
void *event_init (void);
|
111
|
+
void event_base_free (struct event_base *base);
|
112
|
+
|
113
|
+
#define EVLOOP_ONCE EVLOOP_ONESHOT
|
114
|
+
int event_loop (int);
|
115
|
+
int event_loopexit (struct timeval *tv);
|
116
|
+
int event_dispatch (void);
|
117
|
+
|
118
|
+
#define _EVENT_LOG_DEBUG 0
|
119
|
+
#define _EVENT_LOG_MSG 1
|
120
|
+
#define _EVENT_LOG_WARN 2
|
121
|
+
#define _EVENT_LOG_ERR 3
|
122
|
+
typedef void (*event_log_cb)(int severity, const char *msg);
|
123
|
+
void event_set_log_callback(event_log_cb cb);
|
124
|
+
|
125
|
+
void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg);
|
126
|
+
int event_once (int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv);
|
127
|
+
|
128
|
+
int event_add (struct event *ev, struct timeval *tv);
|
129
|
+
int event_del (struct event *ev);
|
130
|
+
void event_active (struct event *ev, int res, short ncalls); /* ncalls is being ignored */
|
131
|
+
|
132
|
+
int event_pending (struct event *ev, short, struct timeval *tv);
|
133
|
+
|
134
|
+
int event_priority_init (int npri);
|
135
|
+
int event_priority_set (struct event *ev, int pri);
|
136
|
+
|
137
|
+
int event_base_set (struct event_base *base, struct event *ev);
|
138
|
+
int event_base_loop (struct event_base *base, int);
|
139
|
+
int event_base_loopexit (struct event_base *base, struct timeval *tv);
|
140
|
+
int event_base_dispatch (struct event_base *base);
|
141
|
+
int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv);
|
142
|
+
int event_base_priority_init (struct event_base *base, int fd);
|
143
|
+
|
144
|
+
/* next line is different in the libevent+libev version */
|
145
|
+
/*libevent-include*/
|
146
|
+
|
147
|
+
#ifdef __cplusplus
|
148
|
+
}
|
149
|
+
#endif
|
150
|
+
|
151
|
+
#endif
|
152
|
+
|