<< fd << ")";
init();
fd_ = fd;
+ setCloseOnExec();
state_ = StateEnum::ESTABLISHED;
}
}
}
+void AsyncSocket::setCloseOnExec() {
+ int rv = fcntl(fd_, F_SETFD, FD_CLOEXEC);
+ if (rv != 0) {
+ throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR,
+ withAddr("failed to set close-on-exec flag"),
+ errno);
+ }
+}
+
void AsyncSocket::connect(ConnectCallback* callback,
const folly::SocketAddress& address,
int timeout,
}
ioHandler_.changeHandlerFD(fd_);
- // Set the FD_CLOEXEC flag so that the socket will be closed if the program
- // later forks and execs.
- int rv = fcntl(fd_, F_SETFD, FD_CLOEXEC);
- if (rv != 0) {
- throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR,
- withAddr("failed to set close-on-exec flag"),
- errno);
- }
+ setCloseOnExec();
// Put the socket in non-blocking mode
int flags = fcntl(fd_, F_GETFL, 0);
throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR,
withAddr("failed to get socket flags"), errno);
}
- rv = fcntl(fd_, F_SETFL, flags | O_NONBLOCK);
+ int rv = fcntl(fd_, F_SETFL, flags | O_NONBLOCK);
if (rv == -1) {
throw AsyncSocketException(
AsyncSocketException::INTERNAL_ERROR,
*/
int setNoDelay(bool noDelay);
+
+ /**
+ * Set the FD_CLOEXEC flag so that the socket will be closed if the program
+ * later forks and execs.
+ */
+ void setCloseOnExec();
+
/*
* Set the Flavor of Congestion Control to be used for this Socket
* Please check '/lib/modules/<kernel>/kernel/net/ipv4' for tcp_*.ko