Commit 99eb3f45 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by facebook-github-bot-4

Compatibility: libevent: accessors for struct event

Summary: [Folly] Compatibility: libevent: accessors for `struct event`.

Some libevent fields in `struct event` moved between `v1.4` and `v2`. Add some accessors which are defined per-libevent-version.

Reviewed By: @JoelMarcey

Differential Revision: D2447537
parent 21bbc9a9
......@@ -144,7 +144,7 @@ void AsyncTimeout::libeventCallback(int fd, short events, void* arg) {
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();
......
......@@ -797,7 +797,7 @@ void EventBase::attachTimeoutManager(AsyncTimeout* obj,
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;
}
}
......
......@@ -49,8 +49,9 @@ bool EventHandler::registerImpl(uint16_t events, bool 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;
}
......@@ -67,7 +68,7 @@ bool EventHandler::registerImpl(uint16_t events, bool internal) {
// 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.
......@@ -168,7 +169,7 @@ void EventHandler::setEventBase(EventBase* eventBase) {
}
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;
}
......
......@@ -20,10 +20,30 @@
*/
#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
*/
......@@ -35,7 +55,7 @@ class EventUtil {
EVLIST_REGISTERED = (EVLIST_INSERTED | EVLIST_ACTIVE |
EVLIST_TIMEOUT | EVLIST_SIGNAL)
};
return (ev->ev_flags & EVLIST_REGISTERED);
return (event_ref_flags(ev) & EVLIST_REGISTERED);
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment