mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
server: Refactor mutex lock handling
This commit is contained in:
parent
fcf1fa8aff
commit
191cfa08d5
15
WSServer.cpp
15
WSServer.cpp
@ -59,17 +59,17 @@ void WSServer::Start(quint16 port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WSServer::Stop() {
|
void WSServer::Stop() {
|
||||||
_clMutex.lock();
|
QMutexLocker locker(&_clMutex);
|
||||||
for(QWebSocket* pClient : _clients) {
|
for(QWebSocket* pClient : _clients) {
|
||||||
pClient->close();
|
pClient->close();
|
||||||
}
|
}
|
||||||
_clMutex.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
_wsServer->close();
|
_wsServer->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSServer::broadcast(QString message) {
|
void WSServer::broadcast(QString message) {
|
||||||
_clMutex.lock();
|
QMutexLocker locker(&_clMutex);
|
||||||
for(QWebSocket* pClient : _clients) {
|
for(QWebSocket* pClient : _clients) {
|
||||||
if (Config::Current()->AuthRequired
|
if (Config::Current()->AuthRequired
|
||||||
&& (pClient->property(PROP_AUTHENTICATED).toBool() == false)) {
|
&& (pClient->property(PROP_AUTHENTICATED).toBool() == false)) {
|
||||||
@ -78,7 +78,6 @@ void WSServer::broadcast(QString message) {
|
|||||||
}
|
}
|
||||||
pClient->sendTextMessage(message);
|
pClient->sendTextMessage(message);
|
||||||
}
|
}
|
||||||
_clMutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSServer::onNewConnection() {
|
void WSServer::onNewConnection() {
|
||||||
@ -91,9 +90,9 @@ void WSServer::onNewConnection() {
|
|||||||
|
|
||||||
pSocket->setProperty(PROP_AUTHENTICATED, false);
|
pSocket->setProperty(PROP_AUTHENTICATED, false);
|
||||||
|
|
||||||
_clMutex.lock();
|
QMutexLocker locker(&_clMutex);
|
||||||
_clients << pSocket;
|
_clients << pSocket;
|
||||||
_clMutex.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
QHostAddress clientAddr = pSocket->peerAddress();
|
QHostAddress clientAddr = pSocket->peerAddress();
|
||||||
QString clientIp = Utils::FormatIPAddress(clientAddr);
|
QString clientIp = Utils::FormatIPAddress(clientAddr);
|
||||||
@ -124,9 +123,9 @@ void WSServer::onSocketDisconnected() {
|
|||||||
if (pSocket) {
|
if (pSocket) {
|
||||||
pSocket->setProperty(PROP_AUTHENTICATED, false);
|
pSocket->setProperty(PROP_AUTHENTICATED, false);
|
||||||
|
|
||||||
_clMutex.lock();
|
QMutexLocker locker(&_clMutex);
|
||||||
_clients.removeAll(pSocket);
|
_clients.removeAll(pSocket);
|
||||||
_clMutex.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
pSocket->deleteLater();
|
pSocket->deleteLater();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user