Commit 1e2463c7 authored by Matthew Laux's avatar Matthew Laux Committed by Facebook GitHub Bot

Replace global AsyncSocketExceptions with lazy initialization functions

Summary: Avoid allocation during startup by creating the exception objects the first time getXXXX is called.

Reviewed By: yfeldblum

Differential Revision: D22128606

fbshipit-source-id: b5ba662dcfac9f859dc9c972d1906fe1c29c42cc
parent e559539b
...@@ -62,12 +62,17 @@ static constexpr bool msgErrQueueSupported = ...@@ -62,12 +62,17 @@ static constexpr bool msgErrQueueSupported =
false; false;
#endif // FOLLY_HAVE_MSG_ERRQUEUE #endif // FOLLY_HAVE_MSG_ERRQUEUE
const AsyncSocketException socketClosedLocallyEx( static AsyncSocketException const& getSocketClosedLocallyEx() {
AsyncSocketException::END_OF_FILE, static auto& ex = *new AsyncSocketException(
"socket closed locally"); AsyncSocketException::END_OF_FILE, "socket closed locally");
const AsyncSocketException socketShutdownForWritesEx( return ex;
AsyncSocketException::END_OF_FILE, }
"socket shutdown for writes");
static AsyncSocketException const& getSocketShutdownForWritesEx() {
static auto& ex = *new AsyncSocketException(
AsyncSocketException::END_OF_FILE, "socket shutdown for writes");
return ex;
}
// TODO: It might help performance to provide a version of BytesWriteRequest // TODO: It might help performance to provide a version of BytesWriteRequest
// that users could derive from, so we can avoid the extra allocation for each // that users could derive from, so we can avoid the extra allocation for each
...@@ -1314,9 +1319,9 @@ void AsyncSocket::closeNow() { ...@@ -1314,9 +1319,9 @@ void AsyncSocket::closeNow() {
doClose(); doClose();
} }
invokeConnectErr(socketClosedLocallyEx); invokeConnectErr(getSocketClosedLocallyEx());
failAllWrites(socketClosedLocallyEx); failAllWrites(getSocketClosedLocallyEx());
if (readCallback_) { if (readCallback_) {
ReadCallback* callback = readCallback_; ReadCallback* callback = readCallback_;
...@@ -1424,7 +1429,7 @@ void AsyncSocket::shutdownWriteNow() { ...@@ -1424,7 +1429,7 @@ void AsyncSocket::shutdownWriteNow() {
netops::shutdown(fd_, SHUT_WR); netops::shutdown(fd_, SHUT_WR);
// Immediately fail all write requests // Immediately fail all write requests
failAllWrites(socketShutdownForWritesEx); failAllWrites(getSocketShutdownForWritesEx());
return; return;
} }
case StateEnum::CONNECTING: { case StateEnum::CONNECTING: {
...@@ -1434,7 +1439,7 @@ void AsyncSocket::shutdownWriteNow() { ...@@ -1434,7 +1439,7 @@ void AsyncSocket::shutdownWriteNow() {
shutdownFlags_ |= SHUT_WRITE_PENDING; shutdownFlags_ |= SHUT_WRITE_PENDING;
// Immediately fail all write requests // Immediately fail all write requests
failAllWrites(socketShutdownForWritesEx); failAllWrites(getSocketShutdownForWritesEx());
return; return;
} }
case StateEnum::UNINIT: case StateEnum::UNINIT:
...@@ -1449,7 +1454,7 @@ void AsyncSocket::shutdownWriteNow() { ...@@ -1449,7 +1454,7 @@ void AsyncSocket::shutdownWriteNow() {
// the writes, we will never try to call connect, so shut everything down // the writes, we will never try to call connect, so shut everything down
shutdownFlags_ |= SHUT_WRITE; shutdownFlags_ |= SHUT_WRITE;
// Immediately fail all write requests // Immediately fail all write requests
failAllWrites(socketShutdownForWritesEx); failAllWrites(getSocketShutdownForWritesEx());
return; return;
case StateEnum::CLOSED: case StateEnum::CLOSED:
case StateEnum::ERROR: case StateEnum::ERROR:
......
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