Commit 76f45528 authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Remove most of the event portability header

Summary: Now that the APIs are backed by NetworkSocket, most of the header is no longer required.

Reviewed By: yfeldblum

Differential Revision: D14594696

fbshipit-source-id: 40ff90e18a4d6ff7d1a9a48aac4d4931c84a362d
parent c4a117dd
......@@ -18,6 +18,7 @@
#include <folly/io/async/EventBase.h>
#include <folly/io/async/EventUtil.h>
#include <folly/io/async/Request.h>
#include <folly/net/NetworkSocket.h>
#include <assert.h>
#include <glog/logging.h>
......@@ -26,16 +27,24 @@ namespace folly {
AsyncTimeout::AsyncTimeout(TimeoutManager* timeoutManager)
: timeoutManager_(timeoutManager) {
folly_event_set(
&event_, -1, EV_TIMEOUT, &AsyncTimeout::libeventCallback, this);
event_set(
&event_,
NetworkSocket::invalid_handle_value,
EV_TIMEOUT,
&AsyncTimeout::libeventCallback,
this);
event_.ev_base = nullptr;
timeoutManager_->attachTimeoutManager(
this, TimeoutManager::InternalEnum::NORMAL);
}
AsyncTimeout::AsyncTimeout(EventBase* eventBase) : timeoutManager_(eventBase) {
folly_event_set(
&event_, -1, EV_TIMEOUT, &AsyncTimeout::libeventCallback, this);
event_set(
&event_,
NetworkSocket::invalid_handle_value,
EV_TIMEOUT,
&AsyncTimeout::libeventCallback,
this);
event_.ev_base = nullptr;
if (eventBase) {
timeoutManager_->attachTimeoutManager(
......@@ -47,23 +56,35 @@ AsyncTimeout::AsyncTimeout(
TimeoutManager* timeoutManager,
InternalEnum internal)
: timeoutManager_(timeoutManager) {
folly_event_set(
&event_, -1, EV_TIMEOUT, &AsyncTimeout::libeventCallback, this);
event_set(
&event_,
NetworkSocket::invalid_handle_value,
EV_TIMEOUT,
&AsyncTimeout::libeventCallback,
this);
event_.ev_base = nullptr;
timeoutManager_->attachTimeoutManager(this, internal);
}
AsyncTimeout::AsyncTimeout(EventBase* eventBase, InternalEnum internal)
: timeoutManager_(eventBase) {
folly_event_set(
&event_, -1, EV_TIMEOUT, &AsyncTimeout::libeventCallback, this);
event_set(
&event_,
NetworkSocket::invalid_handle_value,
EV_TIMEOUT,
&AsyncTimeout::libeventCallback,
this);
event_.ev_base = nullptr;
timeoutManager_->attachTimeoutManager(this, internal);
}
AsyncTimeout::AsyncTimeout() : timeoutManager_(nullptr) {
folly_event_set(
&event_, -1, EV_TIMEOUT, &AsyncTimeout::libeventCallback, this);
event_set(
&event_,
NetworkSocket::invalid_handle_value,
EV_TIMEOUT,
&AsyncTimeout::libeventCallback,
this);
event_.ev_base = nullptr;
}
......@@ -136,7 +157,7 @@ void AsyncTimeout::detachEventBase() {
void AsyncTimeout::libeventCallback(libevent_fd_t fd, short events, void* arg) {
AsyncTimeout* timeout = reinterpret_cast<AsyncTimeout*>(arg);
assert(libeventFdToFd(fd) == -1);
assert(fd == NetworkSocket::invalid_handle_value);
assert(events == EV_TIMEOUT);
// prevent unused variable warnings
(void)fd;
......
......@@ -23,7 +23,7 @@
namespace folly {
EventHandler::EventHandler(EventBase* eventBase, NetworkSocket fd) {
folly_event_set(&event_, fd.toFd(), 0, &EventHandler::libeventCallback, this);
event_set(&event_, fd.data, 0, &EventHandler::libeventCallback, this);
if (eventBase != nullptr) {
setEventBase(eventBase);
} else {
......@@ -125,13 +125,13 @@ void EventHandler::changeHandlerFD(NetworkSocket fd) {
ensureNotRegistered(__func__);
// event_set() resets event_base.ev_base, so manually restore it afterwards
struct event_base* evb = event_.ev_base;
folly_event_set(&event_, fd.toFd(), 0, &EventHandler::libeventCallback, this);
event_set(&event_, fd.data, 0, &EventHandler::libeventCallback, this);
event_.ev_base = evb; // don't use event_base_set(), since evb may be nullptr
}
void EventHandler::initHandler(EventBase* eventBase, NetworkSocket fd) {
ensureNotRegistered(__func__);
folly_event_set(&event_, fd.toFd(), 0, &EventHandler::libeventCallback, this);
event_set(&event_, fd.data, 0, &EventHandler::libeventCallback, this);
setEventBase(eventBase);
}
......
......@@ -36,19 +36,4 @@ using libevent_fd_t = evutil_socket_t;
#else
using libevent_fd_t = int;
#endif
inline libevent_fd_t getLibeventFd(int fd) {
return netops::detail::SocketFileDescriptorMap::fdToSocket(fd);
}
inline int libeventFdToFd(libevent_fd_t fd) {
return netops::detail::SocketFileDescriptorMap::socketToFd(fd);
}
using EventSetCallback = void (*)(libevent_fd_t, short, void*);
inline void
folly_event_set(event* e, int fd, short s, EventSetCallback f, void* arg) {
auto lfd = getLibeventFd(fd);
event_set(e, lfd, s, f, arg);
}
} // namespace folly
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