Commit 5a74908e authored by Yair Gottdenker's avatar Yair Gottdenker Committed by Facebook GitHub Bot

changing AsyncServerSocket::acceptError to receive exception_wrapper

Reviewed By: yfeldblum

Differential Revision: D25514804

fbshipit-source-id: 7e6ad5c6063d2cf5047f656c0f2336b34576c60b
parent a9fdc51d
...@@ -96,16 +96,16 @@ AsyncServerSocket::RemoteAcceptor::Consumer::operator()( ...@@ -96,16 +96,16 @@ AsyncServerSocket::RemoteAcceptor::Consumer::operator()(
break; break;
} }
case MessageType::MSG_ERROR: { case MessageType::MSG_ERROR: {
std::runtime_error ex(msg.msg); auto ex = make_exception_wrapper<std::runtime_error>(msg.msg);
acceptor_.callback_->acceptError(ex); acceptor_.callback_->acceptError(std::move(ex));
break; break;
} }
default: { default: {
LOG(ERROR) << "invalid accept notification message type " LOG(ERROR) << "invalid accept notification message type "
<< int(msg.type); << int(msg.type);
std::runtime_error ex( auto ex = make_exception_wrapper<std::runtime_error>(
"received invalid accept notification message type"); "received invalid accept notification message type");
acceptor_.callback_->acceptError(ex); acceptor_.callback_->acceptError(std::move(ex));
} }
} }
return AtomicNotificationQueueTaskStatus::CONSUMED; return AtomicNotificationQueueTaskStatus::CONSUMED;
...@@ -1076,9 +1076,9 @@ void AsyncServerSocket::dispatchError(const char* msgstr, int errnoValue) { ...@@ -1076,9 +1076,9 @@ void AsyncServerSocket::dispatchError(const char* msgstr, int errnoValue) {
while (true) { while (true) {
// Short circuit if the callback is in the primary EventBase thread // Short circuit if the callback is in the primary EventBase thread
if (info->eventBase == nullptr || info->eventBase == this->eventBase_) { if (info->eventBase == nullptr || info->eventBase == this->eventBase_) {
std::runtime_error ex( auto ex = make_exception_wrapper<std::runtime_error>(
std::string(msgstr) + folly::to<std::string>(errnoValue)); std::string(msgstr) + folly::to<std::string>(errnoValue));
info->callback->acceptError(ex); info->callback->acceptError(std::move(ex));
return; return;
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
#include <folly/ExceptionWrapper.h>
#include <chrono> #include <chrono>
#include <exception> #include <exception>
#include <memory> #include <memory>
...@@ -169,7 +170,19 @@ class AsyncServerSocket : public DelayedDestruction, public AsyncSocketBase { ...@@ -169,7 +170,19 @@ class AsyncServerSocket : public DelayedDestruction, public AsyncSocketBase {
* *
* @param ex An exception representing the error. * @param ex An exception representing the error.
*/ */
virtual void acceptError(const std::exception& ex) noexcept = 0;
// TODO(T81599451): Remove the acceptError(const std::exception&)
// after migration and remove compile warning supression.
FOLLY_PUSH_WARNING
FOLLY_GNU_DISABLE_WARNING("-Woverloaded-virtual")
virtual void acceptError(exception_wrapper ew) noexcept {
auto ex = ew.get_exception<std::exception>();
FOLLY_SAFE_CHECK(ex, "no exception");
acceptError(*ex);
}
virtual void acceptError(const std::exception& /* unused */) noexcept {}
FOLLY_POP_WARNING
/** /**
* acceptStarted() will be called in the callback's EventBase thread * acceptStarted() will be called in the callback's EventBase thread
......
...@@ -189,11 +189,11 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback { ...@@ -189,11 +189,11 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback {
connectionAcceptedFn_(fd, clientAddr); connectionAcceptedFn_(fd, clientAddr);
} }
} }
void acceptError(const std::exception& ex) noexcept override { void acceptError(folly::exception_wrapper ex) noexcept override {
events_.emplace_back(ex.what()); events_.emplace_back(ex.what().toStdString());
if (acceptErrorFn_) { if (acceptErrorFn_) {
acceptErrorFn_(ex); acceptErrorFn_(*ex.get_exception());
} }
} }
void acceptStarted() noexcept override { void acceptStarted() noexcept override {
......
...@@ -56,8 +56,8 @@ class SSLServerAcceptCallbackBase : public AsyncServerSocket::AcceptCallback { ...@@ -56,8 +56,8 @@ class SSLServerAcceptCallbackBase : public AsyncServerSocket::AcceptCallback {
~SSLServerAcceptCallbackBase() override { EXPECT_EQ(STATE_SUCCEEDED, state); } ~SSLServerAcceptCallbackBase() override { EXPECT_EQ(STATE_SUCCEEDED, state); }
void acceptError(const std::exception& ex) noexcept override { void acceptError(folly::exception_wrapper ex) noexcept override {
LOG(WARNING) << "SSLServerAcceptCallbackBase::acceptError " << ex.what(); LOG(WARNING) << "SSLServerAcceptCallbackBase::acceptError " << ex;
state = STATE_FAILED; state = STATE_FAILED;
} }
......
...@@ -229,7 +229,7 @@ class ZeroCopyTestServer : public folly::AsyncServerSocket::AcceptCallback { ...@@ -229,7 +229,7 @@ class ZeroCopyTestServer : public folly::AsyncServerSocket::AcceptCallback {
clients_[client.get()] = client; clients_[client.get()] = client;
} }
void acceptError(const std::exception&) noexcept override {} void acceptError(folly::exception_wrapper) noexcept override {}
private: private:
folly::EventBase* evb_; folly::EventBase* evb_;
......
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