in eventstream_rpc/source/EventStreamClient.cpp [742:793]
void ClientConnection::s_onConnectionShutdown(
struct aws_event_stream_rpc_client_connection *connection,
int errorCode,
void *userData) noexcept
{
(void)connection;
/* The `userData` pointer is used to pass `this` of a `ClientConnection` object. */
auto *thisConnection = static_cast<ClientConnection *>(userData);
const std::lock_guard<std::recursive_mutex> lock(thisConnection->m_stateMutex);
if (thisConnection->m_closeReason.baseStatus == EVENT_STREAM_RPC_UNINITIALIZED && errorCode)
{
thisConnection->m_closeReason = {EVENT_STREAM_RPC_CRT_ERROR, errorCode};
}
thisConnection->m_underlyingConnection = nullptr;
if (thisConnection->m_closeReason.baseStatus != EVENT_STREAM_RPC_UNINITIALIZED &&
!thisConnection->m_onConnectCalled)
{
thisConnection->m_connectAckedPromise.set_value(thisConnection->m_closeReason);
}
thisConnection->m_clientState = DISCONNECTED;
if (thisConnection->m_onConnectCalled)
{
if (errorCode)
{
thisConnection->m_lifecycleHandler->OnDisconnectCallback({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
}
else
{
thisConnection->m_lifecycleHandler->OnDisconnectCallback({EVENT_STREAM_RPC_SUCCESS, 0});
}
thisConnection->m_onConnectCalled = false;
}
if (errorCode)
{
AWS_LOGF_ERROR(
AWS_LS_EVENT_STREAM_RPC_CLIENT,
"A CRT error occurred while shutting down the connection: %s",
Crt::ErrorDebugString(errorCode));
thisConnection->m_closedPromise.set_value({EVENT_STREAM_RPC_CRT_ERROR, errorCode});
}
else
{
thisConnection->m_closedPromise.set_value({EVENT_STREAM_RPC_SUCCESS, errorCode});
}
}