--- libev/ev++.h 2008/01/19 00:39:38 1.31 +++ libev/ev++.h 2008/04/15 04:34:07 1.39 @@ -46,16 +46,12 @@ # include "ev.h" #endif -#ifndef EV_CXX_EXCEPTIONS -#define EV_CXX_EXCEPTIONS 1 +#ifndef EV_USE_STDEXCEPT +# define EV_USE_STDEXCEPT 1 #endif -#undef EV_THROW -#if EV_CXX_EXCEPTIONS -# include -# define EV_THROW(exception) throw (exception) -#else -# define EV_THROW(exception) +#if EV_USE_STDEXCEPT +# include #endif namespace ev { @@ -76,6 +72,7 @@ CHECK = EV_CHECK, PREPARE = EV_PREPARE, FORK = EV_FORK, + ASYNC = EV_ASYNC, EMBED = EV_EMBED, ERROR = EV_ERROR, }; @@ -105,15 +102,18 @@ ALL = EVUNLOOP_ALL }; -#if EV_CXX_EXCEPTIONS - struct bad_loop : std::runtime_error + struct bad_loop +#if EV_USE_STDEXCEPT + : std::runtime_error +#endif { +#if EV_USE_STDEXCEPT bad_loop () - : std::runtime_error ("loop can't be initialized") + : std::runtime_error ("libev event loop cannot be initialized, bad value of LIBEV_FLAGS?") { } - }; #endif + }; #ifdef EV_AX # undef EV_AX @@ -133,28 +133,23 @@ struct loop_ref { - - loop_ref (EV_P) + loop_ref (EV_P) throw () #if EV_MULTIPLICITY - EV_THROW (bad_loop) : EV_AX (EV_A) + : EV_AX (EV_A) #endif { -#if EV_MULTIPLICIY && EV_CXX_EXCEPTIONS - if (!EV_A) - throw bad_loop (); -#endif } - bool operator== (const loop_ref &other) const throw () + bool operator == (const loop_ref &other) const throw () { #if EV_MULTIPLICITY - return this->EV_AX == other.EV_AX; + return EV_AX == other.EV_AX; #else return true; #endif } - bool operator!= (const loop_ref &other) const throw () + bool operator != (const loop_ref &other) const throw () { #if EV_MULTIPLICITY return ! (*this == other); @@ -164,22 +159,22 @@ } #if EV_MULTIPLICITY - bool operator== (struct ev_loop *other) const throw () + bool operator == (struct ev_loop *other) const throw () { return this->EV_AX == other; } - bool operator!= (struct ev_loop *other) const throw () + bool operator != (struct ev_loop *other) const throw () { return ! (*this == other); } - bool operator== (const struct ev_loop *other) const throw () + bool operator == (const struct ev_loop *other) const throw () { return this->EV_AX == other; } - bool operator!= (const struct ev_loop *other) const throw () + bool operator != (const struct ev_loop *other) const throw () { return (*this == other); } @@ -345,12 +340,14 @@ }; #if EV_MULTIPLICITY - struct dynamic_loop: loop_ref + struct dynamic_loop : loop_ref { - dynamic_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) - : loop_ref (ev_loop_new (flags)) + dynamic_loop (unsigned int flags = AUTO) throw (bad_loop) + : loop_ref (ev_loop_new (flags)) { + if (!EV_AX) + throw bad_loop (); } ~dynamic_loop () throw () @@ -368,41 +365,31 @@ }; #endif - struct default_loop: loop_ref + struct default_loop : loop_ref { - - default_loop (unsigned int flags = AUTO) EV_THROW (bad_loop) + default_loop (unsigned int flags = AUTO) throw (bad_loop) #if EV_MULTIPLICITY - : loop_ref (ev_default_loop (flags)) + : loop_ref (ev_default_loop (flags)) +#endif { - } + if ( +#if EV_MULTIPLICITY + !EV_AX #else - { - #if EV_CXX_EXCEPTIONS - int r = - #endif - ev_default_loop (flags); - #if EV_CXX_EXCEPTIONS - if (!r) + !ev_default_loop (flags) +#endif + ) throw bad_loop (); - #endif } -#endif ~default_loop () throw () { ev_default_destroy (); -#if EV_MULTIPLICITY - EV_AX = 0; -#endif } private: - default_loop (const default_loop &); - - default_loop & operator= (const default_loop &); - + default_loop &operator = (const default_loop &); }; inline loop_ref get_default_loop () throw () @@ -577,13 +564,13 @@ #if EV_MULTIPLICITY #define EV_CONSTRUCT(cppstem,cstem) \ - (EV_PX = get_default_loop ()) throw () \ + (EV_PX = get_default_loop ()) throw () \ : base (EV_A) \ { \ } #else #define EV_CONSTRUCT(cppstem,cstem) \ - () throw () \ + () throw () \ { \ } #endif @@ -594,19 +581,19 @@ \ struct cppstem : base \ { \ - void start () throw () \ + void start () throw () \ { \ ev_ ## cstem ## _start (EV_A_ static_cast(this)); \ } \ \ - void stop () throw () \ + void stop () throw () \ { \ ev_ ## cstem ## _stop (EV_A_ static_cast(this)); \ } \ \ cppstem EV_CONSTRUCT(cppstem,cstem) \ \ - ~cppstem () throw () \ + ~cppstem () throw () \ { \ stop (); \ } \ @@ -617,7 +604,7 @@ \ cppstem (const cppstem &o); \ \ - cppstem & operator =(const cppstem &o); \ + cppstem &operator =(const cppstem &o); \ \ public: @@ -709,17 +696,17 @@ EV_END_WATCHER (sig, signal) EV_BEGIN_WATCHER (child, child) - void set (int pid) throw () + void set (int pid, int trace = 0) throw () { int active = is_active (); if (active) stop (); - ev_child_set (static_cast(this), pid); + ev_child_set (static_cast(this), pid, trace); if (active) start (); } - void start (int pid) throw () + void start (int pid, int trace = 0) throw () { - set (pid); + set (pid, trace); start (); } EV_END_WATCHER (child, child) @@ -762,10 +749,17 @@ #if EV_EMBED_ENABLE EV_BEGIN_WATCHER (embed, embed) - void start (struct ev_loop *embedded_loop) throw () + void set (struct ev_loop *embedded_loop) throw () { - stop (); + int active = is_active (); + if (active) stop (); ev_embed_set (static_cast(this), embedded_loop); + if (active) start (); + } + + void start (struct ev_loop *embedded_loop) throw () + { + set (embedded_loop); start (); } @@ -782,15 +776,28 @@ EV_END_WATCHER (fork, fork) #endif + #if EV_ASYNC_ENABLE + EV_BEGIN_WATCHER (async, async) + void set () throw () { } + + void send () throw () + { + ev_async_send (EV_A_ static_cast(this)); + } + + bool async_pending () throw () + { + return ev_async_pending (static_cast(this)); + } + EV_END_WATCHER (async, async) + #endif + #undef EV_PX #undef EV_PX_ #undef EV_CONSTRUCT #undef EV_BEGIN_WATCHER #undef EV_END_WATCHER - } -#undef EV_THROW - #endif