+ enum
+ {
+ AUTO = EVFLAG_AUTO,
+ NOENV = EVFLAG_NOENV,
+ FORKCHECK = EVFLAG_FORKCHECK,
+ SELECT = EVBACKEND_SELECT,
+ POLL = EVBACKEND_POLL,
+ EPOLL = EVBACKEND_EPOLL,
+ KQUEUE = EVBACKEND_KQUEUE,
+ DEVPOLL = EVBACKEND_DEVPOLL,
+ PORT = EVBACKEND_PORT
+ };
+
+ enum
+ {
+ NONBLOCK = EVLOOP_NONBLOCK,
+ ONESHOT = EVLOOP_ONESHOT
+ };
+
+ enum how_t
+ {
+ ONE = EVUNLOOP_ONE,
+ ALL = EVUNLOOP_ALL
+ };
+
+ struct bad_loop
+#if EV_USE_STDEXCEPT
+ : std::runtime_error
+#endif
+ {
+#if EV_USE_STDEXCEPT
+ bad_loop ()
+ : std::runtime_error ("libev event loop cannot be initialized, bad value of LIBEV_FLAGS?")
+ {
+ }
+#endif
+ };
+
+#ifdef EV_AX
+# undef EV_AX
+#endif
+
+#ifdef EV_AX_
+# undef EV_AX_
+#endif
+
+#if EV_MULTIPLICITY
+# define EV_AX raw_loop
+# define EV_AX_ raw_loop,
+#else
+# define EV_AX
+# define EV_AX_
+#endif
+
+ struct loop_ref
+ {
+
+ loop_ref (EV_P) throw (bad_loop)
+#if EV_MULTIPLICITY
+ : EV_AX (EV_A)
+#endif
+ {
+#if EV_MULTIPLICITY
+ if (!EV_AX)
+ throw bad_loop ();
+#endif
+ }
+
+ bool operator == (const loop_ref &other) const throw ()
+ {
+#if EV_MULTIPLICITY
+ return EV_AX == other.EV_AX;
+#else
+ return true;
+#endif
+ }
+
+ bool operator != (const loop_ref &other) const throw ()
+ {
+#if EV_MULTIPLICITY
+ return ! (*this == other);
+#else
+ return false;
+#endif
+ }
+
+#if EV_MULTIPLICITY
+ bool operator== (struct ev_loop *other) const throw ()
+ {
+ return this->EV_AX == other;
+ }
+
+ bool operator!= (struct ev_loop *other) const throw ()
+ {
+ return ! (*this == other);
+ }
+
+ bool operator== (const struct ev_loop *other) const throw ()
+ {
+ return this->EV_AX == other;
+ }
+
+ bool operator!= (const struct ev_loop *other) const throw ()
+ {
+ return (*this == other);
+ }
+
+ operator struct ev_loop * () const throw ()
+ {
+ return EV_AX;
+ }
+
+ operator const struct ev_loop * () const throw ()
+ {
+ return EV_AX;
+ }
+
+ bool is_default () const throw ()
+ {
+ return EV_AX == ev_default_loop (0);
+ }
+#endif
+
+ void loop (int flags = 0)
+ {
+ ev_loop (EV_AX_ flags);
+ }
+
+ void unloop (how_t how = ONE) throw ()
+ {
+ ev_unloop (EV_AX_ how);
+ }
+
+ void post_fork () throw ()
+ {
+#if EV_MULTIPLICITY
+ ev_loop_fork (EV_AX);
+#else
+ ev_default_fork ();
+#endif
+ }
+
+ unsigned int count () const throw ()
+ {
+ return ev_loop_count (EV_AX);
+ }
+
+ unsigned int backend () const throw ()
+ {
+ return ev_backend (EV_AX);
+ }
+
+ tstamp now () const throw ()
+ {
+ return ev_now (EV_AX);
+ }
+
+ void ref () throw ()
+ {
+ ev_ref (EV_AX);
+ }
+
+ void unref () throw ()
+ {
+ ev_unref (EV_AX);
+ }
+
+ void set_io_collect_interval (tstamp interval) throw ()
+ {
+ ev_set_io_collect_interval (EV_AX_ interval);
+ }
+
+ void set_timeout_collect_interval (tstamp interval) throw ()
+ {
+ ev_set_timeout_collect_interval (EV_AX_ interval);
+ }
+
+ // function callback
+ void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void* arg = 0) throw ()
+ {
+ ev_once (EV_AX_ fd, events, timeout, cb, arg);
+ }
+
+ // method callback
+ template<class K, void (K::*method)(int)>
+ void once (int fd, int events, tstamp timeout, K *object) throw ()
+ {
+ once (fd, events, timeout, method_thunk<K, method>, object);
+ }
+
+ template<class K, void (K::*method)(int)>
+ static void method_thunk (int revents, void* arg)
+ {
+ K *obj = static_cast<K *>(arg);
+ (obj->*method) (revents);
+ }
+
+ // const method callback
+ template<class K, void (K::*method)(int) const>
+ void once (int fd, int events, tstamp timeout, const K *object) throw ()
+ {
+ once (fd, events, timeout, const_method_thunk<K, method>, object);
+ }
+
+ template<class K, void (K::*method)(int) const>
+ static void const_method_thunk (int revents, void* arg)
+ {
+ K *obj = static_cast<K *>(arg);
+ (obj->*method) (revents);
+ }
+
+ // simple method callback
+ template<class K, void (K::*method)()>
+ void once (int fd, int events, tstamp timeout, K *object) throw ()
+ {
+ once (fd, events, timeout, method_noargs_thunk<K, method>, object);
+ }
+
+ template<class K, void (K::*method)()>
+ static void method_noargs_thunk (int revents, void* arg)
+ {
+ K *obj = static_cast<K *>(arg);
+ (obj->*method) ();
+ }
+
+ // simpler function callback
+ template<void (*cb)(int)>
+ void once (int fd, int events, tstamp timeout) throw ()
+ {
+ once (fd, events, timeout, simpler_func_thunk<cb>);
+ }
+
+ template<void (*cb)(int)>
+ static void simpler_func_thunk (int revents, void* arg)
+ {
+ (*cb) (revents);
+ }
+
+ // simplest function callback
+ template<void (*cb)()>
+ void once (int fd, int events, tstamp timeout) throw ()
+ {
+ once (fd, events, timeout, simplest_func_thunk<cb>);
+ }
+
+ template<void (*cb)()>
+ static void simplest_func_thunk (int revents, void* arg)
+ {
+ (*cb) ();
+ }
+
+ void feed_fd_event (int fd, int revents) throw ()
+ {
+ ev_feed_fd_event (EV_AX_ fd, revents);
+ }