Unify connection status logging

This commit is contained in:
klzgrad 2018-01-29 00:16:04 -05:00
parent dc70703f4e
commit ba287cc0fc
2 changed files with 7 additions and 6 deletions

View File

@ -85,7 +85,7 @@ void NaiveClient::OnConnectComplete(int connection_id, int result) {
void NaiveClient::HandleConnectResult(NaiveClientConnection* connection, void NaiveClient::HandleConnectResult(NaiveClientConnection* connection,
int result) { int result) {
if (result != OK) { if (result != OK) {
Close(connection->id()); Close(connection->id(), result);
return; return;
} }
DoRun(connection); DoRun(connection);
@ -109,16 +109,17 @@ void NaiveClient::OnRunComplete(int connection_id, int result) {
void NaiveClient::HandleRunResult(NaiveClientConnection* connection, void NaiveClient::HandleRunResult(NaiveClientConnection* connection,
int result) { int result) {
LOG(INFO) << "Connection " << connection->id() Close(connection->id(), result);
<< " ended: " << ErrorToString(result);
Close(connection->id());
} }
void NaiveClient::Close(int connection_id) { void NaiveClient::Close(int connection_id, int reason) {
auto it = connection_by_id_.find(connection_id); auto it = connection_by_id_.find(connection_id);
if (it == connection_by_id_.end()) if (it == connection_by_id_.end())
return; return;
LOG(INFO) << "Connection " << connection_id
<< " closed: " << ErrorToShortString(reason);
// The call stack might have callbacks which still have the pointer of // The call stack might have callbacks which still have the pointer of
// connection. Instead of referencing connection with ID all the time, // connection. Instead of referencing connection with ID all the time,
// destroys the connection in next run loop to make sure any pending // destroys the connection in next run loop to make sure any pending

View File

@ -38,7 +38,7 @@ class NaiveClient {
void OnRunComplete(int connection_id, int result); void OnRunComplete(int connection_id, int result);
void HandleRunResult(NaiveClientConnection* connection, int result); void HandleRunResult(NaiveClientConnection* connection, int result);
void Close(int connection_id); void Close(int connection_id, int reason);
NaiveClientConnection* FindConnection(int connection_id); NaiveClientConnection* FindConnection(int connection_id);
bool HasClosedConnection(NaiveClientConnection* connection); bool HasClosedConnection(NaiveClientConnection* connection);