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

Move fd_ to the initializer list in AsyncSocket constructor

Summary: When constructing a new AsyncSocket, we can use an already connected file descriptor, which we assign to the `fd_` member variable. We move this assignment from the constructor body to the constructor initializer list to avoid a situation where an observer is unaware of an attached fd because `fd_` was assigned after the observer was created.

Reviewed By: yfeldblum

Differential Revision: D30261699

fbshipit-source-id: 5adbc744715355fba08f5430a77c9094e246899d
parent 2e2e7af8
......@@ -571,6 +571,7 @@ AsyncSocket::AsyncSocket(
uint32_t zeroCopyBufId,
const SocketAddress* peerAddress)
: zeroCopyBufId_(zeroCopyBufId),
fd_(fd),
eventBase_(evb),
writeTimeout_(this, evb),
ioHandler_(this, evb, fd),
......@@ -578,7 +579,6 @@ AsyncSocket::AsyncSocket(
VLOG(5) << "new AsyncSocket(" << this << ", evb=" << evb << ", fd=" << fd
<< ", zeroCopyBufId=" << zeroCopyBufId << ")";
init();
fd_ = fd;
disableTransparentFunctions(fd_, noTransparentTls_, noTSocks_);
setCloseOnExec();
state_ = StateEnum::ESTABLISHED;
......@@ -621,7 +621,6 @@ void AsyncSocket::init() {
shutdownFlags_ = 0;
state_ = StateEnum::UNINIT;
eventFlags_ = EventHandler::NONE;
fd_ = NetworkSocket();
sendTimeout_ = 0;
maxReadsPerEvent_ = 16;
connectCallback_ = nullptr;
......
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