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