mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
WebSocketServer: Add some error handling
This commit is contained in:
parent
fb01a28623
commit
a70e18a2bf
@ -104,7 +104,18 @@ void WebSocketServer::Stop()
|
|||||||
|
|
||||||
std::unique_lock<std::mutex> lock(_sessionMutex);
|
std::unique_lock<std::mutex> lock(_sessionMutex);
|
||||||
for (auto const& [hdl, session] : _sessions) {
|
for (auto const& [hdl, session] : _sessions) {
|
||||||
_server.close(hdl, websocketpp::close::status::going_away, "Server stopping.");
|
websocketpp::lib::error_code errorCode;
|
||||||
|
_server.pause_reading(hdl, errorCode);
|
||||||
|
if (errorCode) {
|
||||||
|
blog(LOG_INFO, "[Stop] Error: %s", errorCode.message().c_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
_server.close(hdl, websocketpp::close::status::going_away, "Server stopping.", errorCode);
|
||||||
|
if (errorCode) {
|
||||||
|
blog(LOG_INFO, "[Stop] Error: %s", errorCode.message().c_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
@ -125,7 +136,19 @@ void WebSocketServer::Stop()
|
|||||||
void WebSocketServer::InvalidateSession(websocketpp::connection_hdl hdl)
|
void WebSocketServer::InvalidateSession(websocketpp::connection_hdl hdl)
|
||||||
{
|
{
|
||||||
blog(LOG_INFO, "[InvalidateSession] Invalidating a session.");
|
blog(LOG_INFO, "[InvalidateSession] Invalidating a session.");
|
||||||
|
|
||||||
|
websocketpp::lib::error_code errorCode;
|
||||||
|
_server.pause_reading(hdl);
|
||||||
|
if (errorCode) {
|
||||||
|
blog(LOG_INFO, "[InvalidateSession] Error: %s", errorCode.message().c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_server.close(hdl, WebSocketCloseCode::SessionInvalidated, "Your session has been invalidated.");
|
_server.close(hdl, WebSocketCloseCode::SessionInvalidated, "Your session has been invalidated.");
|
||||||
|
if (errorCode) {
|
||||||
|
blog(LOG_INFO, "[InvalidateSession] Error: %s", errorCode.message().c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<WebSocketServer::WebSocketSessionState> WebSocketServer::GetWebSocketSessions()
|
std::vector<WebSocketServer::WebSocketSessionState> WebSocketServer::GetWebSocketSessions()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user