Commit 75752063 authored by Cristian Lumezanu's avatar Cristian Lumezanu Committed by Facebook GitHub Bot

Initialize state_ early when creating AsyncSocket from connected fd_

Summary: Move `state_` and `addr_` to the initializer list of the AsyncSocket constructor. This is necessary as there may be installed callbacks for AsyncSocket (e.g., using ConstructorCallback) that need these values early.

Reviewed By: yfeldblum

Differential Revision: D31761420

fbshipit-source-id: 2790cff1413835927be8610d7117208ef39e1cd1
parent cab1d598
......@@ -567,7 +567,9 @@ AsyncSocket::AsyncSocket(
uint32_t zeroCopyBufId,
const SocketAddress* peerAddress)
: zeroCopyBufId_(zeroCopyBufId),
state_(StateEnum::ESTABLISHED),
fd_(fd),
addr_(peerAddress ? *peerAddress : folly::SocketAddress()),
eventBase_(evb),
writeTimeout_(this, evb),
ioHandler_(this, evb, fd),
......@@ -577,10 +579,6 @@ AsyncSocket::AsyncSocket(
init();
disableTransparentFunctions(fd_, noTransparentTls_, noTSocks_);
setCloseOnExec();
state_ = StateEnum::ESTABLISHED;
if (peerAddress) {
addr_ = *peerAddress;
}
}
AsyncSocket::AsyncSocket(AsyncSocket* oldAsyncSocket)
......@@ -623,7 +621,6 @@ void AsyncSocket::init() {
if (eventBase_) {
eventBase_->dcheckIsInEventBaseThread();
}
shutdownFlags_ = 0;
eventFlags_ = EventHandler::NONE;
sendTimeout_ = 0;
maxReadsPerEvent_ = 16;
......
......@@ -1556,7 +1556,7 @@ class AsyncSocket : public AsyncTransport {
std::unordered_map<folly::IOBuf*, IOBufInfo> idZeroCopyBufInfoMap_;
StateEnum state_{StateEnum::UNINIT}; ///< StateEnum describing current state
uint8_t shutdownFlags_; ///< Shutdown state (ShutdownFlags)
uint8_t shutdownFlags_{0}; ///< Shutdown state (ShutdownFlags)
uint16_t eventFlags_; ///< EventBase::HandlerFlags settings
NetworkSocket fd_; ///< The socket file descriptor
mutable folly::SocketAddress addr_; ///< The address we tried to connect to
......
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