mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
WebSocketSession: Add mutex for operations which change session parameters
This commit is contained in:
parent
4be9b995fb
commit
ffaac93ba6
@ -49,6 +49,7 @@ WebSocketProtocol::ProcessResult WebSocketProtocol::ProcessMessage(SessionPtr se
|
|||||||
} else if (messageType == "RequestBatch") {
|
} else if (messageType == "RequestBatch") {
|
||||||
;
|
;
|
||||||
} else if (messageType == "Identify") {
|
} else if (messageType == "Identify") {
|
||||||
|
std::unique_lock<std::mutex> sessionLock(session->OperationMutex);
|
||||||
if (session->IsIdentified()) {
|
if (session->IsIdentified()) {
|
||||||
if (!session->IgnoreInvalidMessages()) {
|
if (!session->IgnoreInvalidMessages()) {
|
||||||
ret.closeCode = WebSocketServer::WebSocketCloseCode::AlreadyIdentified;
|
ret.closeCode = WebSocketServer::WebSocketCloseCode::AlreadyIdentified;
|
||||||
@ -87,7 +88,7 @@ WebSocketProtocol::ProcessResult WebSocketProtocol::ProcessMessage(SessionPtr se
|
|||||||
ret.result["negotiatedRpcVersion"] = session->RpcVersion();
|
ret.result["negotiatedRpcVersion"] = session->RpcVersion();
|
||||||
return ret;
|
return ret;
|
||||||
} else if (messageType == "Reidentify") {
|
} else if (messageType == "Reidentify") {
|
||||||
;
|
std::unique_lock<std::mutex> sessionLock(session->OperationMutex);
|
||||||
} else {
|
} else {
|
||||||
if (!session->IgnoreInvalidMessages()) {
|
if (!session->IgnoreInvalidMessages()) {
|
||||||
ret.closeCode = WebSocketServer::WebSocketCloseCode::UnknownMessageType;
|
ret.closeCode = WebSocketServer::WebSocketCloseCode::UnknownMessageType;
|
||||||
|
@ -253,6 +253,7 @@ void WebSocketServer::onOpen(websocketpp::connection_hdl hdl)
|
|||||||
// Build new session
|
// Build new session
|
||||||
std::unique_lock<std::mutex> lock(_sessionMutex);
|
std::unique_lock<std::mutex> lock(_sessionMutex);
|
||||||
SessionPtr session = _sessions[hdl] = std::make_shared<WebSocketSession>();
|
SessionPtr session = _sessions[hdl] = std::make_shared<WebSocketSession>();
|
||||||
|
std::unique_lock<std::mutex> sessionLock(session->OperationMutex);
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
// Configure session details
|
// Configure session details
|
||||||
@ -284,6 +285,8 @@ void WebSocketServer::onOpen(websocketpp::connection_hdl hdl)
|
|||||||
helloMessage["authentication"]["salt"] = AuthenticationSalt;
|
helloMessage["authentication"]["salt"] = AuthenticationSalt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sessionLock.unlock();
|
||||||
|
|
||||||
// Send object to client
|
// Send object to client
|
||||||
websocketpp::lib::error_code errorCode;
|
websocketpp::lib::error_code errorCode;
|
||||||
auto sessionEncoding = session->Encoding();
|
auto sessionEncoding = session->Encoding();
|
||||||
|
@ -42,6 +42,8 @@ class WebSocketSession
|
|||||||
uint64_t EventSubscriptions();
|
uint64_t EventSubscriptions();
|
||||||
void SetEventSubscriptions(uint64_t subscriptions);
|
void SetEventSubscriptions(uint64_t subscriptions);
|
||||||
|
|
||||||
|
std::mutex OperationMutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex _remoteAddressMutex;
|
std::mutex _remoteAddressMutex;
|
||||||
std::string _remoteAddress;
|
std::string _remoteAddress;
|
||||||
|
Loading…
Reference in New Issue
Block a user