summaryrefslogtreecommitdiff
path: root/deps/libev/ev.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/libev/ev.h')
-rw-r--r--deps/libev/ev.h137
1 files changed, 83 insertions, 54 deletions
diff --git a/deps/libev/ev.h b/deps/libev/ev.h
index 96e735871a..9edf6564e9 100644
--- a/deps/libev/ev.h
+++ b/deps/libev/ev.h
@@ -1,7 +1,7 @@
/*
* libev native API header
*
- * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann <libev@schmorp.de>
+ * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
@@ -41,9 +41,13 @@
#define EV_H_
#ifdef __cplusplus
-extern "C" {
+# define EV_CPP(x) x
+#else
+# define EV_CPP(x)
#endif
+EV_CPP(extern "C" {)
+
/*****************************************************************************/
/* pre-4.0 compatibility */
@@ -99,6 +103,10 @@ extern "C" {
# define EV_FORK_ENABLE EV_FEATURE_WATCHERS
#endif
+#ifndef EV_CLEANUP_ENABLE
+# define EV_CLEANUP_ENABLE EV_FEATURE_WATCHERS
+#endif
+
#ifndef EV_SIGNAL_ENABLE
# define EV_SIGNAL_ENABLE EV_FEATURE_WATCHERS
#endif
@@ -150,14 +158,14 @@ typedef double ev_tstamp;
/* support multiple event loops? */
#if EV_MULTIPLICITY
struct ev_loop;
-# define EV_P struct ev_loop *loop
-# define EV_P_ EV_P,
-# define EV_A loop
-# define EV_A_ EV_A,
-# define EV_DEFAULT_UC ev_default_loop_uc ()
-# define EV_DEFAULT_UC_ EV_DEFAULT_UC,
-# define EV_DEFAULT ev_default_loop (0)
-# define EV_DEFAULT_ EV_DEFAULT,
+# define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */
+# define EV_P_ EV_P, /* a loop as first of multiple parameters */
+# define EV_A loop /* a loop as sole argument to a function call */
+# define EV_A_ EV_A, /* a loop as first of multiple arguments */
+# define EV_DEFAULT_UC ev_default_loop_uc_ () /* the default loop, if initialised, as sole arg */
+# define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */
+# define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */
+# define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */
#else
# define EV_P void
# define EV_P_
@@ -170,12 +178,14 @@ struct ev_loop;
# undef EV_EMBED_ENABLE
#endif
+/* EV_INLINE is used for functions in header files */
#if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3
# define EV_INLINE static inline
#else
# define EV_INLINE static
#endif
+/* EV_PROTOTYPES can be sued to switch of prototype declarations */
#ifndef EV_PROTOTYPES
# define EV_PROTOTYPES 1
#endif
@@ -183,18 +193,20 @@ struct ev_loop;
/*****************************************************************************/
#define EV_VERSION_MAJOR 4
-#define EV_VERSION_MINOR 0
+#define EV_VERSION_MINOR 3
/* eventmask, revents, events... */
enum {
- EV_UNDEF = -1, /* guaranteed to be invalid */
+ EV_UNDEF = 0xFFFFFFFF, /* guaranteed to be invalid */
EV_NONE = 0x00, /* no events */
EV_READ = 0x01, /* ev_io detected read will not block */
EV_WRITE = 0x02, /* ev_io detected write will not block */
EV__IOFDSET = 0x80, /* internal use only */
EV_IO = EV_READ, /* alias for type-detection */
EV_TIMER = 0x00000100, /* timer timed out */
+#if EV_COMPAT3
EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */
+#endif
EV_PERIODIC = 0x00000200, /* periodic timer timed out */
EV_SIGNAL = 0x00000400, /* signal was received */
EV_CHILD = 0x00000800, /* child/pid had status change */
@@ -204,7 +216,8 @@ enum {
EV_CHECK = 0x00008000, /* event loop finished poll */
EV_EMBED = 0x00010000, /* embedded event loop needs sweep */
EV_FORK = 0x00020000, /* event loop resumed in child */
- EV_ASYNC = 0x00040000, /* async intra-loop signal */
+ EV_CLEANUP = 0x00040000, /* event loop resumed in child */
+ EV_ASYNC = 0x00080000, /* async intra-loop signal */
EV_CUSTOM = 0x01000000, /* for use by user code */
EV_ERROR = 0x80000000 /* sent when an error occurs */
};
@@ -383,12 +396,22 @@ typedef struct ev_check
#if EV_FORK_ENABLE
/* the callback gets invoked before check in the child process when a fork was detected */
+/* revent EV_FORK */
typedef struct ev_fork
{
EV_WATCHER (ev_fork)
} ev_fork;
#endif
+#if EV_CLEANUP_ENABLE
+/* is invoked just before the loop gets destroyed */
+/* revent EV_CLEANUP */
+typedef struct ev_cleanup
+{
+ EV_WATCHER (ev_cleanup)
+} ev_cleanup;
+#endif
+
#if EV_EMBED_ENABLE
/* used to embed an event loop inside another */
/* the callback gets invoked when the event loop has handled events, and can be 0 */
@@ -404,6 +427,9 @@ typedef struct ev_embed
ev_periodic periodic; /* unused */
ev_idle idle; /* unused */
ev_fork fork; /* private */
+#if EV_CLEANUP_ENABLE
+ ev_cleanup cleanup; /* unused */
+#endif
} ev_embed;
#endif
@@ -442,6 +468,9 @@ union ev_any_watcher
#if EV_FORK_ENABLE
struct ev_fork fork;
#endif
+#if EV_CLEANUP_ENABLE
+ struct ev_cleanup cleanup;
+#endif
#if EV_EMBED_ENABLE
struct ev_embed embed;
#endif
@@ -462,7 +491,8 @@ enum {
#if EV_COMPAT3
EVFLAG_NOSIGFD = 0, /* compatibility to pre-3.9 */
#endif
- EVFLAG_SIGNALFD = 0x00200000U /* attempt to use signalfd */
+ EVFLAG_SIGNALFD = 0x00200000U, /* attempt to use signalfd */
+ EVFLAG_NOSIGMASK = 0x00400000U /* avoid modifying the signal mask */
};
/* method bits to be ored together */
@@ -473,7 +503,8 @@ enum {
EVBACKEND_KQUEUE = 0x00000008U, /* bsd */
EVBACKEND_DEVPOLL = 0x00000010U, /* solaris 8 */ /* NYI */
EVBACKEND_PORT = 0x00000020U, /* solaris 10 */
- EVBACKEND_ALL = 0x0000003FU
+ EVBACKEND_ALL = 0x0000003FU, /* all known backends */
+ EVBACKEND_MASK = 0x0000FFFFU /* all future backends */
};
#if EV_PROTOTYPES
@@ -502,41 +533,33 @@ void ev_set_allocator (void *(*cb)(void *ptr, long size));
void ev_set_syserr_cb (void (*cb)(const char *msg));
#if EV_MULTIPLICITY
+
+/* the default loop is the only one that handles signals and child watchers */
+/* you can call this as often as you like */
+struct ev_loop *ev_default_loop (unsigned int flags EV_CPP (= 0));
+
EV_INLINE struct ev_loop *
-ev_default_loop_uc (void)
+ev_default_loop_uc_ (void)
{
extern struct ev_loop *ev_default_loop_ptr;
return ev_default_loop_ptr;
}
-/* the default loop is the only one that handles signals and child watchers */
-/* you can call this as often as you like */
-EV_INLINE struct ev_loop *
-ev_default_loop (unsigned int flags)
+EV_INLINE int
+ev_is_default_loop (EV_P)
{
- struct ev_loop *loop = ev_default_loop_uc ();
-
- if (!loop)
- {
- extern struct ev_loop *ev_default_loop_init (unsigned int flags);
-
- loop = ev_default_loop_init (flags);
- }
-
- return loop;
+ return EV_A == EV_DEFAULT_UC;
}
/* create and destroy alternative loops that don't handle signals */
-struct ev_loop *ev_loop_new (unsigned int flags);
-void ev_loop_destroy (EV_P);
-void ev_loop_fork (EV_P);
+struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0));
ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */
#else
-int ev_default_loop (unsigned int flags); /* returns true when successful */
+int ev_default_loop (unsigned int flags EV_CPP (= 0)); /* returns true when successful */
EV_INLINE ev_tstamp
ev_now (void)
@@ -545,26 +568,24 @@ ev_now (void)
return ev_rt_now;
}
-#endif /* multiplicity */
+/* looks weird, but ev_is_default_loop (EV_A) still works if this exists */
EV_INLINE int
-ev_is_default_loop (EV_P)
+ev_is_default_loop (void)
{
-#if EV_MULTIPLICITY
- extern struct ev_loop *ev_default_loop_ptr;
-
- return !!(EV_A == ev_default_loop_ptr);
-#else
return 1;
-#endif
}
-void ev_default_destroy (void); /* destroy the default loop */
-/* this needs to be called after fork, to duplicate the default loop */
-/* if you create alternative loops you have to call ev_loop_fork on them */
+#endif /* multiplicity */
+
+/* destroy event loops, also works for the default loop */
+void ev_loop_destroy (EV_P);
+
+/* this needs to be called after fork, to duplicate the loop */
+/* when you want to re-use it in the child */
/* you can call it in either the parent or the child */
/* you can actually call it at any time, anywhere :) */
-void ev_default_fork (void);
+void ev_loop_fork (EV_P);
unsigned int ev_backend (EV_P); /* backend in use by loop */
@@ -593,8 +614,8 @@ enum {
};
#if EV_PROTOTYPES
-void ev_run (EV_P_ int flags);
-void ev_break (EV_P_ int how); /* set to 1 to break out of event loop, set to 2 to break out of all event loops */
+void ev_run (EV_P_ int flags EV_CPP (= 0));
+void ev_break (EV_P_ int how EV_CPP (= EVBREAK_ONE)); /* break out of the loop */
/*
* ref/unref can be used to add or remove a refcount on the mainloop. every watcher
@@ -656,6 +677,7 @@ void ev_resume (EV_P);
#define ev_check_set(ev) /* nop, yes, this is a serious in-joke */
#define ev_embed_set(ev,other_) do { (ev)->other = (other_); } while (0)
#define ev_fork_set(ev) /* nop, yes, this is a serious in-joke */
+#define ev_cleanup_set(ev) /* nop, yes, this is a serious in-joke */
#define ev_async_set(ev) /* nop, yes, this is a serious in-joke */
#define ev_io_init(ev,cb,fd,events) do { ev_init ((ev), (cb)); ev_io_set ((ev),(fd),(events)); } while (0)
@@ -669,6 +691,7 @@ void ev_resume (EV_P);
#define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0)
#define ev_embed_init(ev,cb,other) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(other)); } while (0)
#define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0)
+#define ev_cleanup_init(ev,cb) do { ev_init ((ev), (cb)); ev_cleanup_set ((ev)); } while (0)
#define ev_async_init(ev,cb) do { ev_init ((ev), (cb)); ev_async_set ((ev)); } while (0)
#define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */
@@ -699,6 +722,7 @@ void ev_resume (EV_P);
void ev_feed_event (EV_P_ void *w, int revents);
void ev_feed_fd_event (EV_P_ int fd, int revents);
#if EV_SIGNAL_ENABLE
+void ev_feed_signal (int signum);
void ev_feed_signal_event (EV_P_ int signum);
#endif
void ev_invoke (EV_P_ void *w, int revents);
@@ -758,6 +782,11 @@ void ev_fork_start (EV_P_ ev_fork *w);
void ev_fork_stop (EV_P_ ev_fork *w);
# endif
+# if EV_CLEANUP_ENABLE
+void ev_cleanup_start (EV_P_ ev_cleanup *w);
+void ev_cleanup_stop (EV_P_ ev_cleanup *w);
+# endif
+
# if EV_EMBED_ENABLE
/* only supported when loop to be embedded is in fact embeddable */
void ev_embed_start (EV_P_ ev_embed *w);
@@ -780,10 +809,12 @@ void ev_async_send (EV_P_ ev_async *w);
#if EV_PROTOTYPES
EV_INLINE void ev_loop (EV_P_ int flags) { ev_run (EV_A_ flags); }
EV_INLINE void ev_unloop (EV_P_ int how ) { ev_break (EV_A_ how ); }
+ EV_INLINE void ev_default_destroy (void) { ev_loop_destroy (EV_DEFAULT); }
+ EV_INLINE void ev_default_fork (void) { ev_loop_fork (EV_DEFAULT); }
#if EV_FEATURE_API
- EV_INLINE void ev_loop_count (EV_P) { ev_iteration (EV_A); }
- EV_INLINE void ev_loop_depth (EV_P) { ev_depth (EV_A); }
- EV_INLINE void ev_loop_verify (EV_P) { ev_verify (EV_A); }
+ EV_INLINE unsigned int ev_loop_count (EV_P) { return ev_iteration (EV_A); }
+ EV_INLINE unsigned int ev_loop_depth (EV_P) { return ev_depth (EV_A); }
+ EV_INLINE void ev_loop_verify (EV_P) { ev_verify (EV_A); }
#endif
#endif
#else
@@ -792,9 +823,7 @@ void ev_async_send (EV_P_ ev_async *w);
#endif
-#ifdef __cplusplus
-}
-#endif
+EV_CPP(})
#endif