ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.h
(Generate patch)

Comparing libev/ev.h (file contents):
Revision 1.31 by root, Sun Nov 4 19:45:09 2007 UTC vs.
Revision 1.37 by root, Tue Nov 6 00:52:33 2007 UTC

96 96
97/* shared by all watchers */ 97/* shared by all watchers */
98#define EV_WATCHER(type) \ 98#define EV_WATCHER(type) \
99 int active; /* private */ \ 99 int active; /* private */ \
100 int pending; /* private */ \ 100 int pending; /* private */ \
101 int priority; /* ro */ \ 101 int priority; /* private */ \
102 EV_COMMON; /* rw */ \ 102 EV_COMMON; /* rw */ \
103 void (*cb)(EV_P_ struct type *, int revents); /* rw */ /* gets invoked with an eventmask */ 103 void (*cb)(EV_P_ struct type *, int revents); /* private */ /* gets invoked with an eventmask */
104 104
105#define EV_WATCHER_LIST(type) \ 105#define EV_WATCHER_LIST(type) \
106 EV_WATCHER (type); \ 106 EV_WATCHER (type); \
107 struct ev_watcher_list *next /* private */ 107 struct ev_watcher_list *next /* private */
108 108
195 EV_WATCHER_LIST (ev_child); 195 EV_WATCHER_LIST (ev_child);
196 196
197 int pid; /* ro */ 197 int pid; /* ro */
198 int rpid; /* rw, holds the received pid */ 198 int rpid; /* rw, holds the received pid */
199 int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */ 199 int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */
200};
201
202union ev_any_watcher
203{
204 struct ev_watcher w;
205 struct ev_watcher_list wl;
206 struct ev_io io;
207 struct ev_timer timer;
208 struct ev_periodic periodic;
209 struct ev_signal signal;
210 struct ev_idle idle;
211 struct ev_child child;
212 struct ev_prepare prepare;
213 struct ev_check check;
200}; 214};
201 215
202#define EVMETHOD_AUTO 0 /* consults environment */ 216#define EVMETHOD_AUTO 0 /* consults environment */
203#define EVMETHOD_SELECT 1 217#define EVMETHOD_SELECT 1
204#define EVMETHOD_POLL 2 218#define EVMETHOD_POLL 2
205#define EVMETHOD_EPOLL 4 219#define EVMETHOD_EPOLL 4
206#define EVMETHOD_KQUEUE 8 220#define EVMETHOD_KQUEUE 8
207#define EVMETHOD_DEVPOLL 16 /* NYI */ 221#define EVMETHOD_DEVPOLL 16 /* NYI */
208#define EVMETHOD_PORT 32 /* NYI */ 222#define EVMETHOD_PORT 32 /* NYI */
223#define EVMETHOD_WIN32 64 /* NYI */
209#define EVMETHOD_ANY ~0 /* any method, do not consult env */ 224#define EVMETHOD_ANY ~0 /* any method, do not consult env */
210 225
211#if EV_PROTOTYPES 226#if EV_PROTOTYPES
212int ev_version_major (void); 227int ev_version_major (void);
213int ev_version_minor (void); 228int ev_version_minor (void);
214 229
215ev_tstamp ev_time (void); 230ev_tstamp ev_time (void);
231
232/* Sets the allocation function to use, works like realloc.
233 * It is used to allocate and free memory.
234 * If it returns zero when memory needs to be allocated, the library might abort
235 * or take some potentially destructive action.
236 * The default is your system realloc function.
237 */
238void ev_set_allocator (void *(*cb)(void *ptr, long size));
239
240/* set the callback function to call on a
241 * retryable syscall error
242 * (such as failed select, poll, epoll_wait)
243 */
244void ev_set_syserr_cb (void (*cb)(const char *msg));
216 245
217# if EV_MULTIPLICITY 246# if EV_MULTIPLICITY
218/* the default loop is the only one that handles signals and child watchers */ 247/* the default loop is the only one that handles signals and child watchers */
219/* you can call this as often as you like */ 248/* you can call this as often as you like */
220struct ev_loop *ev_default_loop (int methods); /* returns default loop */ 249struct ev_loop *ev_default_loop (int methods); /* returns default loop */
261void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); 290void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg);
262#endif 291#endif
263 292
264/* these may evaluate ev multiple times, and the other arguments at most once */ 293/* these may evaluate ev multiple times, and the other arguments at most once */
265/* either use ev_watcher_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */ 294/* either use ev_watcher_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */
266#define ev_watcher_init(ev,cb_) do { (ev)->active = (ev)->pending = (ev)->priority = 0; (ev)->cb = (cb_); } while (0) 295#define ev_watcher_init(ev,cb_) do { \
296 ((struct ev_watcher *)(void *)(ev))->active = \
297 ((struct ev_watcher *)(void *)(ev))->pending = \
298 ((struct ev_watcher *)(void *)(ev))->priority = 0; \
299 (ev)->cb = (cb_); \
300} while (0)
267 301
268#define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) 302#define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0)
269#define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) 303#define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0)
270#define ev_periodic_set(ev,at_,interval_) do { (ev)->at = (at_); (ev)->interval = (interval_); } while (0) 304#define ev_periodic_set(ev,at_,interval_) do { (ev)->at = (at_); (ev)->interval = (interval_); } while (0)
271#define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) 305#define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0)
281#define ev_idle_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_idle_set ((ev)); } while (0) 315#define ev_idle_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_idle_set ((ev)); } while (0)
282#define ev_prepare_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0) 316#define ev_prepare_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0)
283#define ev_check_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_check_set ((ev)); } while (0) 317#define ev_check_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_check_set ((ev)); } while (0)
284#define ev_child_init(ev,cb,pid) do { ev_watcher_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0) 318#define ev_child_init(ev,cb,pid) do { ev_watcher_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0)
285 319
286#define ev_is_pending(ev) (0 + (ev)->pending) /* true when watcher is waiting for callback invocation */ 320#define ev_is_pending(ev) (0 + ((struct ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */
287#define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */ 321#define ev_is_active(ev) (0 + ((struct ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */
322
323#define ev_priority(ev) ((struct ev_watcher *)(void *)(ev))->priority /* rw */
324#define ev_cb(ev) (ev)->cb /* rw */
288#define ev_set_priority(ev,pri) (ev)->priority = pri 325#define ev_set_priority(ev,pri) ev_priority (ev) = (pri)
326#define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_)
289 327
290/* stopping (enabling, adding) a watcher does nothing if it is already running */ 328/* stopping (enabling, adding) a watcher does nothing if it is already running */
291/* stopping (disabling, deleting) a watcher does nothing unless its already running */ 329/* stopping (disabling, deleting) a watcher does nothing unless its already running */
292#if EV_PROTOTYPES 330#if EV_PROTOTYPES
293void ev_io_start (EV_P_ struct ev_io *w); 331void ev_io_start (EV_P_ struct ev_io *w);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines