Commit ec4b2e04 authored by Jay Edgar's avatar Jay Edgar Committed by Facebook Github Bot

Use a static exception where it makes sense

Summary: Don't constanly rebuild exceptions that are always the same.

Reviewed By: jrahman

Differential Revision: D16016383

fbshipit-source-id: b0b24ed39e6c41f95c61369c90a3ac83abfd1a66
parent 7b691d80
......@@ -26,6 +26,7 @@
#include <memory>
#include <folly/Format.h>
#include <folly/Indestructible.h>
#include <folly/SocketAddress.h>
#include <folly/SpinLock.h>
#include <folly/io/Cursor.h>
......@@ -348,8 +349,9 @@ void AsyncSSLSocket::closeNow() {
DestructorGuard dg(this);
invokeHandshakeErr(AsyncSocketException(
AsyncSocketException::END_OF_FILE, "SSL connection closed locally"));
static const Indestructible<AsyncSocketException> ex(
AsyncSocketException::END_OF_FILE, "SSL connection closed locally");
invokeHandshakeErr(*ex);
// Close the socket.
AsyncSocket::closeNow();
......@@ -446,16 +448,16 @@ void AsyncSSLSocket::invalidState(HandshakeCB* callback) {
assert(!handshakeTimeout_.isScheduled());
sslState_ = STATE_ERROR;
AsyncSocketException ex(
static const Indestructible<AsyncSocketException> ex(
AsyncSocketException::INVALID_STATE,
"sslAccept() called with socket in invalid state");
handshakeEndTime_ = std::chrono::steady_clock::now();
if (callback) {
callback->handshakeErr(this, ex);
callback->handshakeErr(this, *ex);
}
failHandshake(__func__, ex);
failHandshake(__func__, *ex);
}
void AsyncSSLSocket::sslAccept(
......@@ -616,10 +618,10 @@ void AsyncSSLSocket::timeoutExpired(
} else if (state_ == StateEnum::CONNECTING) {
assert(sslState_ == STATE_CONNECTING);
DestructorGuard dg(this);
AsyncSocketException ex(
static const Indestructible<AsyncSocketException> ex(
AsyncSocketException::TIMED_OUT,
"Fallback connect timed out during TFO");
failHandshake(__func__, ex);
failHandshake(__func__, *ex);
} else {
assert(
state_ == StateEnum::ESTABLISHED &&
......@@ -778,19 +780,19 @@ void AsyncSSLSocket::sslConn(
ssl_.reset(ctx_->createSSL());
} catch (std::exception& e) {
sslState_ = STATE_ERROR;
AsyncSocketException ex(
static const Indestructible<AsyncSocketException> ex(
AsyncSocketException::INTERNAL_ERROR,
"error calling SSLContext::createSSL()");
LOG(ERROR) << "AsyncSSLSocket::sslConn(this=" << this << ", fd=" << fd_
<< "): " << e.what();
return failHandshake(__func__, ex);
return failHandshake(__func__, *ex);
}
if (!setupSSLBio()) {
sslState_ = STATE_ERROR;
AsyncSocketException ex(
static const Indestructible<AsyncSocketException> ex(
AsyncSocketException::INTERNAL_ERROR, "error creating SSL bio");
return failHandshake(__func__, ex);
return failHandshake(__func__, *ex);
}
applyVerificationOptions(ssl_);
......@@ -1079,9 +1081,9 @@ void AsyncSSLSocket::restartSSLAccept() {
}
if (sslState_ == STATE_ERROR) {
// go straight to fail if timeout expired during lookup
AsyncSocketException ex(
static const Indestructible<AsyncSocketException> ex(
AsyncSocketException::TIMED_OUT, "SSL accept timed out");
failHandshake(__func__, ex);
failHandshake(__func__, *ex);
return;
}
sslState_ = STATE_ACCEPTING;
......@@ -1100,19 +1102,19 @@ void AsyncSSLSocket::handleAccept() noexcept {
ssl_.reset(ctx_->createSSL());
} catch (std::exception& e) {
sslState_ = STATE_ERROR;
AsyncSocketException ex(
static const Indestructible<AsyncSocketException> ex(
AsyncSocketException::INTERNAL_ERROR,
"error calling SSLContext::createSSL()");
LOG(ERROR) << "AsyncSSLSocket::handleAccept(this=" << this
<< ", fd=" << fd_ << "): " << e.what();
return failHandshake(__func__, ex);
return failHandshake(__func__, *ex);
}
if (!setupSSLBio()) {
sslState_ = STATE_ERROR;
AsyncSocketException ex(
static const Indestructible<AsyncSocketException> ex(
AsyncSocketException::INTERNAL_ERROR, "error creating write bio");
return failHandshake(__func__, ex);
return failHandshake(__func__, *ex);
}
SSL_set_ex_data(ssl_.get(), getSSLExDataIndex(), this);
......
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