assert(events == EV_TIMEOUT);
// double check that ev_flags gets reset when the timeout is not running
- assert((timeout->event_.ev_flags & ~EVLIST_INTERNAL) == EVLIST_INIT);
+ assert((event_ref_flags(&timeout->event_) & ~EVLIST_INTERNAL) == EVLIST_INIT);
// this can't possibly fire if timeout->eventBase_ is nullptr
(void) timeout->timeoutManager_->bumpHandlingTime();
event_base_set(getLibeventBase(), ev);
if (internal == AsyncTimeout::InternalEnum::INTERNAL) {
// Set the EVLIST_INTERNAL flag
- ev->ev_flags |= EVLIST_INTERNAL;
+ event_ref_flags(ev) |= EVLIST_INTERNAL;
}
}
if (isHandlerRegistered()) {
// If the new events are the same are the same as the already registered
// flags, we don't have to do anything. Just return.
+ auto flags = event_ref_flags(&event_);
if (events == event_.ev_events &&
- static_cast<bool>(event_.ev_flags & EVLIST_INTERNAL) == internal) {
+ static_cast<bool>(flags & EVLIST_INTERNAL) == internal) {
return true;
}
// Set EVLIST_INTERNAL if this is an internal event
if (internal) {
- event_.ev_flags |= EVLIST_INTERNAL;
+ event_ref_flags(&event_) |= EVLIST_INTERNAL;
}
// Add the event.
}
bool EventHandler::isPending() const {
- if (event_.ev_flags & EVLIST_ACTIVE) {
+ if (event_ref_flags(&event_) & EVLIST_ACTIVE) {
if (event_.ev_res & EV_READ) {
return true;
}
*/
#pragma once
+#include <functional>
#include <event.h> // libevent
namespace folly {
+# if LIBEVENT_VERSION_NUMBER <= 0x02010101
+# define FOLLY_LIBEVENT_COMPAT_PLUCK(name) ev_##name
+# else
+# define FOLLY_LIBEVENT_COMPAT_PLUCK(name) ev_evcallback.evcb_##name
+# endif
+# define FOLLY_LIBEVENT_DEF_ACCESSORS(name) \
+ inline auto event_ref_##name(struct event* ev) -> \
+ decltype(std::ref(ev->FOLLY_LIBEVENT_COMPAT_PLUCK(name))) \
+ { return std::ref(ev->FOLLY_LIBEVENT_COMPAT_PLUCK(name)); } \
+ inline auto event_ref_##name(struct event const* ev) -> \
+ decltype(std::cref(ev->FOLLY_LIBEVENT_COMPAT_PLUCK(name))) \
+ { return std::cref(ev->FOLLY_LIBEVENT_COMPAT_PLUCK(name)); } \
+ //
+
+FOLLY_LIBEVENT_DEF_ACCESSORS(flags)
+
+# undef FOLLY_LIBEVENT_COMPAT_PLUCK
+# undef FOLLY_LIBEVENT_DEF_ACCESSORS
+
/**
* low-level libevent utility functions
*/
EVLIST_REGISTERED = (EVLIST_INSERTED | EVLIST_ACTIVE |
EVLIST_TIMEOUT | EVLIST_SIGNAL)
};
- return (ev->ev_flags & EVLIST_REGISTERED);
+ return (event_ref_flags(ev) & EVLIST_REGISTERED);
}
};