void JsonRpcConnection::SendMessage(const Dictionary::Ptr& message)
{
- m_WriteQueue.Enqueue(boost::bind(&JsonRpcConnection::SendMessageSync, JsonRpcConnection::Ptr(this), message), true);
+ if (!m_Stream->IsEof())
+ m_WriteQueue.Enqueue(boost::bind(&JsonRpcConnection::SendMessageSync, JsonRpcConnection::Ptr(this), message), true);
}
void JsonRpcConnection::SendMessageSync(const Dictionary::Ptr& message)
Log(LogWarning, "JsonRpcConnection")
<< info.str() << "\n" << DiagnosticInformation(ex);
- Disconnect();
+ Utility::QueueAsyncCallback(boost::bind(&JsonRpcConnection::Disconnect, JsonRpcConnection::Ptr(this)));
}
}
Log(LogWarning, "JsonRpcConnection")
<< "API client disconnected for identity '" << m_Identity << "'";
+ m_Stream->Close();
+
+ m_WriteQueue.Join();
+
if (m_Endpoint)
m_Endpoint->RemoveClient(this);
else {
ApiListener::Ptr listener = ApiListener::GetInstance();
listener->RemoveAnonymousClient(this);
}
-
- m_Stream->Close();
}
bool JsonRpcConnection::ProcessMessage(void)