--- libev/ev++.h 2008/01/22 17:56:29 1.33 +++ libev/ev++.h 2008/11/05 14:36:18 1.43 @@ -1,7 +1,7 @@ /* * libev simple C++ wrapper classes * - * Copyright (c) 2007 Marc Alexander Lehmann + * Copyright (c) 2007,2008 Marc Alexander Lehmann * All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- @@ -58,7 +58,8 @@ typedef ev_tstamp tstamp; - enum { + enum + { UNDEF = EV_UNDEF, NONE = EV_NONE, READ = EV_READ, @@ -72,27 +73,30 @@ CHECK = EV_CHECK, PREPARE = EV_PREPARE, FORK = EV_FORK, + ASYNC = EV_ASYNC, EMBED = EV_EMBED, +# undef ERROR // some systems stupidly #define ERROR ERROR = EV_ERROR, }; enum { - AUTO = EVFLAG_AUTO, - NOENV = EVFLAG_NOENV, + 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 + + 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 + ONESHOT = EVLOOP_ONESHOT }; enum how_t @@ -132,19 +136,12 @@ struct loop_ref { - - loop_ref (EV_P) + loop_ref (EV_P) throw () #if EV_MULTIPLICITY - throw (bad_loop) : EV_AX (EV_A) - { - if (!EV_AX) - throw bad_loop (); - } -#else - throw () + : EV_AX (EV_A) +#endif { } -#endif bool operator == (const loop_ref &other) const throw () { @@ -165,22 +162,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); } @@ -346,12 +343,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 () @@ -369,18 +368,21 @@ }; #endif - struct default_loop: loop_ref + struct default_loop : loop_ref { - default_loop (unsigned int flags = AUTO) throw (bad_loop) #if EV_MULTIPLICITY : loop_ref (ev_default_loop (flags)) #endif { -#ifndef EV_MULTIPLICITY - if (!ev_default_loop (flags)) - throw bad_loop (); + if ( +#if EV_MULTIPLICITY + !EV_AX +#else + !ev_default_loop (flags) #endif + ) + throw bad_loop (); } ~default_loop () throw () @@ -565,13 +567,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 @@ -582,19 +584,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 (); \ } \ @@ -605,7 +607,7 @@ \ cppstem (const cppstem &o); \ \ - cppstem & operator =(const cppstem &o); \ + cppstem &operator =(const cppstem &o); \ \ public: @@ -697,17 +699,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) @@ -750,10 +752,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 (); } @@ -770,15 +779,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