X-Git-Url: https://git.llucax.com/software/eventxx.git/blobdiff_plain/f213eaa9d8bc2a003b3692ce67a85553ba445535..b2c39dd4dcf34dcc98f9dafb9d1127f6818a7601:/event?ds=inline diff --git a/event b/event index acb02c1..d2ec386 100644 --- a/event +++ b/event @@ -30,7 +30,7 @@ * This is a simple, direct, one-header inline C++ wrapper for libevent. * It's designed to be as close to use to libevent without compromising modern * C++ programming techniques and efficiency (since all implementation is - * trivial inline, theoretically it imposes no overhead at all). + * trivial and inline, theoretically, it imposes no overhead at all). * * * @section Usage @@ -292,7 +292,7 @@ struct event: basic_event event(int fd, short ev, F& handler, int priority = DEFAULT_PRIORITY) throw(invalid_priority) { - event_set(this, fd, ev, &wrapper, &handler); + event_set(this, fd, ev, &wrapper, reinterpret_cast< void* >(&handler)); if (priority != DEFAULT_PRIORITY && event_priority_set(this, priority)) throw invalid_priority(); @@ -302,7 +302,7 @@ struct event: basic_event event() {} static void wrapper(int fd, short ev, void* h) { - F& handler = *static_cast< F* >(h); + F& handler = *reinterpret_cast< F* >(h); handler(fd, ev); } @@ -365,7 +365,8 @@ struct timer: event< F > timer(F& handler, int priority = DEFAULT_PRIORITY) throw(invalid_priority) { - evtimer_set(this, &event< F >::wrapper, &handler); + evtimer_set(this, &event< F >::wrapper, + reinterpret_cast< void* >(&handler)); if (priority != DEFAULT_PRIORITY && event_priority_set(this, priority)) throw invalid_priority(); @@ -427,7 +428,8 @@ struct signal: event< F > signal(int signum, F& handler, int priority = DEFAULT_PRIORITY) throw(invalid_priority) { - signal_set(this, signum, &event< F >::wrapper, &handler); + signal_set(this, signum, &event< F >::wrapper, + reinterpret_cast< void* >(&handler)); if (priority != DEFAULT_PRIORITY && event_priority_set(this, priority)) throw invalid_priority(); @@ -522,7 +524,9 @@ struct dispatcher internal::event_base_priority_init(_event_base, npriorities); } +#ifdef EVENT_BASE_FREE_FIX ~dispatcher() throw() { event_base_free(_event_base); } +#endif /** * Adds an event to the dispatcher. @@ -563,7 +567,8 @@ struct dispatcher template < typename F > void add_once(int fd, short ev, F& handler) { - internal::event_once(fd, ev, &dispatcher::wrapper< F >, &handler, 0); + internal::event_once(fd, ev, &dispatcher::wrapper< F >, + reinterpret_cast< void* >(&handler), 0); } /** @@ -596,7 +601,9 @@ struct dispatcher template < typename F > void add_once(int fd, short ev, F& handler, const time& to) { - internal::event_once(fd, ev, &dispatcher::wrapper< F >, &handler, const_cast< time* >(&to)); // XXX HACK libevent don't use const + internal::event_once(fd, ev, &dispatcher::wrapper< F >, + reinterpret_cast< void* >(&handler), + const_cast< time* >(&to)); // XXX HACK libevent don't use const } /** @@ -628,7 +635,9 @@ struct dispatcher template < typename F > void add_once_timer(F& handler, const time& to) { - internal::event_once(-1, EV_TIMEOUT, &dispatcher::wrapper< F >, &handler, const_cast< time* >(&to)); // XXX HACK libevent don't use const + internal::event_once(-1, EV_TIMEOUT, &dispatcher::wrapper< F >, + reinterpret_cast< void* >(&handler), + const_cast< time* >(&to)); // XXX HACK libevent don't use const } /** @@ -694,7 +703,7 @@ struct dispatcher template < typename F > static void wrapper(int fd, short ev, void* h) { - F& handler = *static_cast< F* >(h); + F& handler = *reinterpret_cast< F* >(h); handler(fd, ev); }