WebSocketSession: Add mutex for operations which change session parameters

This commit is contained in:
tt2468 2021-04-30 08:56:08 -07:00
parent 4be9b995fb
commit ffaac93ba6
3 changed files with 7 additions and 1 deletions

View File

@ -49,6 +49,7 @@ WebSocketProtocol::ProcessResult WebSocketProtocol::ProcessMessage(SessionPtr se
} else if (messageType == "RequestBatch") {
;
} else if (messageType == "Identify") {
std::unique_lock<std::mutex> sessionLock(session->OperationMutex);
if (session->IsIdentified()) {
if (!session->IgnoreInvalidMessages()) {
ret.closeCode = WebSocketServer::WebSocketCloseCode::AlreadyIdentified;
@ -87,7 +88,7 @@ WebSocketProtocol::ProcessResult WebSocketProtocol::ProcessMessage(SessionPtr se
ret.result["negotiatedRpcVersion"] = session->RpcVersion();
return ret;
} else if (messageType == "Reidentify") {
;
std::unique_lock<std::mutex> sessionLock(session->OperationMutex);
} else {
if (!session->IgnoreInvalidMessages()) {
ret.closeCode = WebSocketServer::WebSocketCloseCode::UnknownMessageType;

View File

@ -253,6 +253,7 @@ void WebSocketServer::onOpen(websocketpp::connection_hdl hdl)
// Build new session
std::unique_lock<std::mutex> lock(_sessionMutex);
SessionPtr session = _sessions[hdl] = std::make_shared<WebSocketSession>();
std::unique_lock<std::mutex> sessionLock(session->OperationMutex);
lock.unlock();
// Configure session details
@ -284,6 +285,8 @@ void WebSocketServer::onOpen(websocketpp::connection_hdl hdl)
helloMessage["authentication"]["salt"] = AuthenticationSalt;
}
sessionLock.unlock();
// Send object to client
websocketpp::lib::error_code errorCode;
auto sessionEncoding = session->Encoding();

View File

@ -42,6 +42,8 @@ class WebSocketSession
uint64_t EventSubscriptions();
void SetEventSubscriptions(uint64_t subscriptions);
std::mutex OperationMutex;
private:
std::mutex _remoteAddressMutex;
std::string _remoteAddress;