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