in squangle/mysql_client/Operation.cpp [695:730]
void ConnectOperation::socketActionable() {
DCHECK(isInEventBaseThread());
auto& handler = conn()->client()->getMysqlHandler();
MYSQL* mysql = conn()->mysql();
auto status = handler.tryConnect(mysql, conn_options_, conn_key_, flags_);
if (status == MysqlHandler::ERROR) {
snapshotMysqlErrors();
attemptFailed(OperationResult::Failed);
} else {
if (isDoneWithTcpHandShake() && tcp_timeout_handler_.isScheduled()) {
// cancel tcp connect timeout
tcp_timeout_handler_.cancelTimeout();
}
auto fd = mysql_get_socket_descriptor(mysql);
if (fd <= 0) {
LOG(ERROR) << "Unexpected invalid socket descriptor on completed, "
<< (status == MysqlHandler::DONE ? "errorless" : "pending")
<< " connect. fd=" << fd;
setAsyncClientError(
"mysql_get_socket_descriptor returned an invalid "
"descriptor");
attemptFailed(OperationResult::Failed);
} else if (status == MysqlHandler::DONE) {
auto socket = folly::NetworkSocket::fromFd(fd);
conn()->socketHandler()->changeHandlerFD(socket);
conn()->mysqlConnection()->setConnectionContext(connection_context_);
conn()->mysqlConnection()->connectionOpened();
attemptSucceeded(OperationResult::Succeeded);
} else {
conn()->socketHandler()->changeHandlerFD(
folly::NetworkSocket::fromFd(fd));
waitForSocketActionable();
}
}
}