From 2d84ad89630d6189242faee44ecce955efd03af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Fri, 26 Apr 2019 13:39:18 +0200 Subject: [PATCH 01/11] server: handle requests in a separate thread --- src/WSServer.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/WSServer.cpp b/src/WSServer.cpp index bec085b0..5230f482 100644 --- a/src/WSServer.cpp +++ b/src/WSServer.cpp @@ -166,24 +166,26 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message) return; } - std::string payload = message->get_payload(); + QtConcurrent::run([=]() { + std::string payload = message->get_payload(); - QMutexLocker locker(&_clMutex); - QVariantHash connProperties = _connectionProperties[hdl]; - locker.unlock(); + QMutexLocker locker(&_clMutex); + QVariantHash connProperties = _connectionProperties[hdl]; + locker.unlock(); - WSRequestHandler handler(connProperties); - std::string response = handler.processIncomingMessage(payload); + WSRequestHandler handler(connProperties); + std::string response = handler.processIncomingMessage(payload); - _server.send(hdl, response, websocketpp::frame::opcode::text); + _server.send(hdl, response, websocketpp::frame::opcode::text); - locker.relock(); - // In multithreaded processing this would be problematic to put back - // a copy of the connection properties, because there might conflicts - // between several simultaneous handlers. - // In our case, it's fine because all messages are processed in one thread. - _connectionProperties[hdl] = connProperties; - locker.unlock(); + locker.relock(); + // In multithreaded processing this would be problematic to put back + // a copy of the connection properties, because there might conflicts + // between several simultaneous handlers. + // In our case, it's fine because all messages are processed in one thread. + _connectionProperties[hdl] = connProperties; + locker.unlock(); + }); } void WSServer::onClose(connection_hdl hdl) From 6a10662bc4e9368ad40846b06f9767b989e347fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Fri, 26 Apr 2019 13:52:56 +0200 Subject: [PATCH 02/11] server: use a thread pool --- src/WSServer.cpp | 5 ++++- src/WSServer.h | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/WSServer.cpp b/src/WSServer.cpp index 5230f482..15fa0afd 100644 --- a/src/WSServer.cpp +++ b/src/WSServer.cpp @@ -25,6 +25,7 @@ with this program. If not, see #include #include #include +#include #include "WSServer.h" #include "obs-websocket.h" @@ -127,6 +128,8 @@ void WSServer::stop() _connections.clear(); _connectionProperties.clear(); + _threadPool.waitForDone(); + while (!_server.stopped()) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } @@ -166,7 +169,7 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message) return; } - QtConcurrent::run([=]() { + QtConcurrent::run(&_threadPool, [=]() { std::string payload = message->get_payload(); QMutexLocker locker(&_clMutex); diff --git a/src/WSServer.h b/src/WSServer.h index 8147ca4f..e9faf885 100644 --- a/src/WSServer.h +++ b/src/WSServer.h @@ -22,6 +22,7 @@ with this program. If not, see #include #include #include +#include #include #include @@ -54,6 +55,9 @@ public: void start(quint16 port); void stop(); void broadcast(std::string message); + QThreadPool* threadPool() { + return &_threadPool; + } private: static WSServerPtr _instance; @@ -71,4 +75,5 @@ private: std::set> _connections; std::map> _connectionProperties; QMutex _clMutex; + QThreadPool _threadPool; }; From 1bd3297055ea2b4a9139d474ccb5c241d5a9fc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Fri, 26 Apr 2019 13:55:21 +0200 Subject: [PATCH 03/11] server: update comment --- src/WSServer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WSServer.cpp b/src/WSServer.cpp index 15fa0afd..c4727466 100644 --- a/src/WSServer.cpp +++ b/src/WSServer.cpp @@ -182,10 +182,10 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message) _server.send(hdl, response, websocketpp::frame::opcode::text); locker.relock(); - // In multithreaded processing this would be problematic to put back + // In multithreaded processing this is be problematic to put back // a copy of the connection properties, because there might conflicts // between several simultaneous handlers. - // In our case, it's fine because all messages are processed in one thread. + // TODO conflicts handling _connectionProperties[hdl] = connProperties; locker.unlock(); }); From 0cf17cf3db4c00f37468a523564539664a8ee51b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20L?= Date: Sun, 28 Apr 2019 11:59:03 +0200 Subject: [PATCH 04/11] server: use shared connection properties instance --- src/WSRequestHandler.cpp | 4 ++-- src/WSRequestHandler.h | 5 +++-- src/WSRequestHandler_General.cpp | 4 ++-- src/WSServer.cpp | 13 +++---------- src/WSServer.h | 2 +- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/WSRequestHandler.cpp b/src/WSRequestHandler.cpp index 153812ab..c6bd5166 100644 --- a/src/WSRequestHandler.cpp +++ b/src/WSRequestHandler.cpp @@ -132,7 +132,7 @@ QSet WSRequestHandler::authNotRequired { "Authenticate" }; -WSRequestHandler::WSRequestHandler(QVariantHash& connProperties) : +WSRequestHandler::WSRequestHandler(QSharedPointer connProperties) : _messageId(0), _requestType(""), data(nullptr), @@ -174,7 +174,7 @@ HandlerResponse WSRequestHandler::processRequest(std::string& textMessage){ if (Config::Current()->AuthRequired && (!authNotRequired.contains(_requestType)) - && (_connProperties.value(PROP_AUTHENTICATED).toBool() == false)) + && (_connProperties->value(PROP_AUTHENTICATED).toBool() == false)) { return SendErrorResponse("Not Authenticated"); } diff --git a/src/WSRequestHandler.h b/src/WSRequestHandler.h index 19780c33..1ef1bb3f 100644 --- a/src/WSRequestHandler.h +++ b/src/WSRequestHandler.h @@ -23,6 +23,7 @@ with this program. If not, see #include #include #include +#include #include #include @@ -35,7 +36,7 @@ class WSRequestHandler : public QObject { Q_OBJECT public: - explicit WSRequestHandler(QVariantHash& connProperties); + explicit WSRequestHandler(QSharedPointer connProperties); ~WSRequestHandler(); std::string processIncomingMessage(std::string& textMessage); bool hasField(QString name); @@ -43,7 +44,7 @@ class WSRequestHandler : public QObject { private: const char* _messageId; const char* _requestType; - QVariantHash& _connProperties; + QSharedPointer _connProperties; OBSDataAutoRelease data; HandlerResponse processRequest(std::string& textMessage); diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index 5a6b97f0..a9f1598e 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -82,7 +82,7 @@ HandlerResponse WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { return req->SendErrorResponse("missing request parameters"); } - if (req->_connProperties.value(PROP_AUTHENTICATED).toBool() == true) { + if (req->_connProperties->value(PROP_AUTHENTICATED).toBool() == true) { return req->SendErrorResponse("already authenticated"); } @@ -95,7 +95,7 @@ HandlerResponse WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { return req->SendErrorResponse("Authentication Failed."); } - req->_connProperties.insert(PROP_AUTHENTICATED, true); + req->_connProperties->insert(PROP_AUTHENTICATED, true); return req->SendOKResponse(); } diff --git a/src/WSServer.cpp b/src/WSServer.cpp index c4727466..5f4486bd 100644 --- a/src/WSServer.cpp +++ b/src/WSServer.cpp @@ -142,7 +142,7 @@ void WSServer::broadcast(std::string message) QMutexLocker locker(&_clMutex); for (connection_hdl hdl : _connections) { if (Config::Current()->AuthRequired) { - bool authenticated = _connectionProperties[hdl].value(PROP_AUTHENTICATED).toBool(); + bool authenticated = _connectionProperties[hdl]->value(PROP_AUTHENTICATED).toBool(); if (!authenticated) { continue; } @@ -155,6 +155,7 @@ void WSServer::onOpen(connection_hdl hdl) { QMutexLocker locker(&_clMutex); _connections.insert(hdl); + _connectionProperties[hdl] = QSharedPointer(new QVariantHash()); locker.unlock(); QString clientIp = getRemoteEndpoint(hdl); @@ -173,21 +174,13 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message) std::string payload = message->get_payload(); QMutexLocker locker(&_clMutex); - QVariantHash connProperties = _connectionProperties[hdl]; + auto connProperties = _connectionProperties[hdl]; locker.unlock(); WSRequestHandler handler(connProperties); std::string response = handler.processIncomingMessage(payload); _server.send(hdl, response, websocketpp::frame::opcode::text); - - locker.relock(); - // In multithreaded processing this is be problematic to put back - // a copy of the connection properties, because there might conflicts - // between several simultaneous handlers. - // TODO conflicts handling - _connectionProperties[hdl] = connProperties; - locker.unlock(); }); } diff --git a/src/WSServer.h b/src/WSServer.h index e9faf885..4bb8bfde 100644 --- a/src/WSServer.h +++ b/src/WSServer.h @@ -73,7 +73,7 @@ private: server _server; quint16 _serverPort; std::set> _connections; - std::map> _connectionProperties; + std::map, std::owner_less> _connectionProperties; QMutex _clMutex; QThreadPool _threadPool; }; From 56fc6ae47cc1c342932fe51b4c51fe024b46e925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Thu, 2 May 2019 12:51:07 +0200 Subject: [PATCH 05/11] server: connection properties reference --- src/WSRequestHandler.cpp | 4 ++-- src/WSRequestHandler.h | 4 ++-- src/WSRequestHandler_General.cpp | 4 ++-- src/WSServer.cpp | 9 ++++++--- src/WSServer.h | 8 ++++---- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/WSRequestHandler.cpp b/src/WSRequestHandler.cpp index c6bd5166..153812ab 100644 --- a/src/WSRequestHandler.cpp +++ b/src/WSRequestHandler.cpp @@ -132,7 +132,7 @@ QSet WSRequestHandler::authNotRequired { "Authenticate" }; -WSRequestHandler::WSRequestHandler(QSharedPointer connProperties) : +WSRequestHandler::WSRequestHandler(QVariantHash& connProperties) : _messageId(0), _requestType(""), data(nullptr), @@ -174,7 +174,7 @@ HandlerResponse WSRequestHandler::processRequest(std::string& textMessage){ if (Config::Current()->AuthRequired && (!authNotRequired.contains(_requestType)) - && (_connProperties->value(PROP_AUTHENTICATED).toBool() == false)) + && (_connProperties.value(PROP_AUTHENTICATED).toBool() == false)) { return SendErrorResponse("Not Authenticated"); } diff --git a/src/WSRequestHandler.h b/src/WSRequestHandler.h index 1ef1bb3f..a5f1b410 100644 --- a/src/WSRequestHandler.h +++ b/src/WSRequestHandler.h @@ -36,7 +36,7 @@ class WSRequestHandler : public QObject { Q_OBJECT public: - explicit WSRequestHandler(QSharedPointer connProperties); + explicit WSRequestHandler(QVariantHash& connProperties); ~WSRequestHandler(); std::string processIncomingMessage(std::string& textMessage); bool hasField(QString name); @@ -44,7 +44,7 @@ class WSRequestHandler : public QObject { private: const char* _messageId; const char* _requestType; - QSharedPointer _connProperties; + QVariantHash& _connProperties; OBSDataAutoRelease data; HandlerResponse processRequest(std::string& textMessage); diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index a9f1598e..5a6b97f0 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -82,7 +82,7 @@ HandlerResponse WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { return req->SendErrorResponse("missing request parameters"); } - if (req->_connProperties->value(PROP_AUTHENTICATED).toBool() == true) { + if (req->_connProperties.value(PROP_AUTHENTICATED).toBool() == true) { return req->SendErrorResponse("already authenticated"); } @@ -95,7 +95,7 @@ HandlerResponse WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { return req->SendErrorResponse("Authentication Failed."); } - req->_connProperties->insert(PROP_AUTHENTICATED, true); + req->_connProperties.insert(PROP_AUTHENTICATED, true); return req->SendOKResponse(); } diff --git a/src/WSServer.cpp b/src/WSServer.cpp index 5f4486bd..386ff554 100644 --- a/src/WSServer.cpp +++ b/src/WSServer.cpp @@ -142,7 +142,7 @@ void WSServer::broadcast(std::string message) QMutexLocker locker(&_clMutex); for (connection_hdl hdl : _connections) { if (Config::Current()->AuthRequired) { - bool authenticated = _connectionProperties[hdl]->value(PROP_AUTHENTICATED).toBool(); + bool authenticated = _connectionProperties[hdl].value(PROP_AUTHENTICATED).toBool(); if (!authenticated) { continue; } @@ -155,7 +155,7 @@ void WSServer::onOpen(connection_hdl hdl) { QMutexLocker locker(&_clMutex); _connections.insert(hdl); - _connectionProperties[hdl] = QSharedPointer(new QVariantHash()); + _connectionProperties[hdl] = QVariantHash(); locker.unlock(); QString clientIp = getRemoteEndpoint(hdl); @@ -174,13 +174,16 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message) std::string payload = message->get_payload(); QMutexLocker locker(&_clMutex); - auto connProperties = _connectionProperties[hdl]; + QVariantHash& connProperties = _connectionProperties[hdl]; locker.unlock(); WSRequestHandler handler(connProperties); std::string response = handler.processIncomingMessage(payload); _server.send(hdl, response, websocketpp::frame::opcode::text); + + boost::atomic atomicTest; + atomicTest.load().insert("jambon", true); }); } diff --git a/src/WSServer.h b/src/WSServer.h index 4bb8bfde..5d97af1f 100644 --- a/src/WSServer.h +++ b/src/WSServer.h @@ -18,14 +18,14 @@ with this program. If not, see #pragma once +#include +#include #include #include #include #include #include - -#include -#include +#include #include #include @@ -73,7 +73,7 @@ private: server _server; quint16 _serverPort; std::set> _connections; - std::map, std::owner_less> _connectionProperties; + std::map> _connectionProperties; QMutex _clMutex; QThreadPool _threadPool; }; From bb9cf83744570d2075cfe65171b68841d41cb740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Thu, 2 May 2019 13:06:10 +0200 Subject: [PATCH 06/11] server: dedicated ConnectionProperties object --- CMakeLists.txt | 2 ++ src/ConnectionProperties.cpp | 29 +++++++++++++++++++++++++++++ src/ConnectionProperties.h | 28 ++++++++++++++++++++++++++++ src/WSRequestHandler.cpp | 4 ++-- src/WSRequestHandler.h | 6 ++++-- src/WSRequestHandler_General.cpp | 4 ++-- src/WSServer.cpp | 6 +++--- src/WSServer.h | 4 +++- src/obs-websocket.h | 1 - 9 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 src/ConnectionProperties.cpp create mode 100644 src/ConnectionProperties.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d3c1dae..19c8e88f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ find_package(Boost REQUIRED) set(obs-websocket_SOURCES src/obs-websocket.cpp src/WSServer.cpp + src/ConnectionProperties.cpp src/WSRequestHandler.cpp src/WSRequestHandler_General.cpp src/WSRequestHandler_Profiles.cpp @@ -50,6 +51,7 @@ set(obs-websocket_SOURCES set(obs-websocket_HEADERS src/obs-websocket.h src/WSServer.h + src/ConnectionProperties.h src/WSRequestHandler.h src/WSEvents.h src/Config.h diff --git a/src/ConnectionProperties.cpp b/src/ConnectionProperties.cpp new file mode 100644 index 00000000..567bac83 --- /dev/null +++ b/src/ConnectionProperties.cpp @@ -0,0 +1,29 @@ +/* +obs-websocket +Copyright (C) 2016-2019 Stéphane Lepin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see +*/ + +#include "ConnectionProperties.h" + +bool ConnectionProperties::isAuthenticated() +{ + return _authenticated; +} + +void ConnectionProperties::setAuthenticated(bool authenticated) +{ + _authenticated = authenticated; +} \ No newline at end of file diff --git a/src/ConnectionProperties.h b/src/ConnectionProperties.h new file mode 100644 index 00000000..93d83270 --- /dev/null +++ b/src/ConnectionProperties.h @@ -0,0 +1,28 @@ +/* +obs-websocket +Copyright (C) 2016-2019 Stéphane Lepin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see +*/ + +#pragma once + +class ConnectionProperties +{ +public: + bool isAuthenticated(); + void setAuthenticated(bool authenticated); +private: + bool _authenticated; +}; \ No newline at end of file diff --git a/src/WSRequestHandler.cpp b/src/WSRequestHandler.cpp index 153812ab..374a8ab7 100644 --- a/src/WSRequestHandler.cpp +++ b/src/WSRequestHandler.cpp @@ -132,7 +132,7 @@ QSet WSRequestHandler::authNotRequired { "Authenticate" }; -WSRequestHandler::WSRequestHandler(QVariantHash& connProperties) : +WSRequestHandler::WSRequestHandler(ConnectionProperties& connProperties) : _messageId(0), _requestType(""), data(nullptr), @@ -174,7 +174,7 @@ HandlerResponse WSRequestHandler::processRequest(std::string& textMessage){ if (Config::Current()->AuthRequired && (!authNotRequired.contains(_requestType)) - && (_connProperties.value(PROP_AUTHENTICATED).toBool() == false)) + && (!_connProperties.isAuthenticated())) { return SendErrorResponse("Not Authenticated"); } diff --git a/src/WSRequestHandler.h b/src/WSRequestHandler.h index a5f1b410..6824a385 100644 --- a/src/WSRequestHandler.h +++ b/src/WSRequestHandler.h @@ -28,6 +28,8 @@ with this program. If not, see #include #include +#include "ConnectionProperties.h" + #include "obs-websocket.h" typedef obs_data_t* HandlerResponse; @@ -36,7 +38,7 @@ class WSRequestHandler : public QObject { Q_OBJECT public: - explicit WSRequestHandler(QVariantHash& connProperties); + explicit WSRequestHandler(ConnectionProperties& connProperties); ~WSRequestHandler(); std::string processIncomingMessage(std::string& textMessage); bool hasField(QString name); @@ -44,7 +46,7 @@ class WSRequestHandler : public QObject { private: const char* _messageId; const char* _requestType; - QVariantHash& _connProperties; + ConnectionProperties& _connProperties; OBSDataAutoRelease data; HandlerResponse processRequest(std::string& textMessage); diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index 5a6b97f0..29bcc8b4 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -82,7 +82,7 @@ HandlerResponse WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { return req->SendErrorResponse("missing request parameters"); } - if (req->_connProperties.value(PROP_AUTHENTICATED).toBool() == true) { + if (req->_connProperties.isAuthenticated()) { return req->SendErrorResponse("already authenticated"); } @@ -95,7 +95,7 @@ HandlerResponse WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { return req->SendErrorResponse("Authentication Failed."); } - req->_connProperties.insert(PROP_AUTHENTICATED, true); + req->_connProperties.setAuthenticated(true); return req->SendOKResponse(); } diff --git a/src/WSServer.cpp b/src/WSServer.cpp index 386ff554..f810216e 100644 --- a/src/WSServer.cpp +++ b/src/WSServer.cpp @@ -142,7 +142,7 @@ void WSServer::broadcast(std::string message) QMutexLocker locker(&_clMutex); for (connection_hdl hdl : _connections) { if (Config::Current()->AuthRequired) { - bool authenticated = _connectionProperties[hdl].value(PROP_AUTHENTICATED).toBool(); + bool authenticated = _connectionProperties[hdl].isAuthenticated(); if (!authenticated) { continue; } @@ -155,7 +155,7 @@ void WSServer::onOpen(connection_hdl hdl) { QMutexLocker locker(&_clMutex); _connections.insert(hdl); - _connectionProperties[hdl] = QVariantHash(); + _connectionProperties[hdl] = ConnectionProperties(); locker.unlock(); QString clientIp = getRemoteEndpoint(hdl); @@ -174,7 +174,7 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message) std::string payload = message->get_payload(); QMutexLocker locker(&_clMutex); - QVariantHash& connProperties = _connectionProperties[hdl]; + ConnectionProperties& connProperties = _connectionProperties[hdl]; locker.unlock(); WSRequestHandler handler(connProperties); diff --git a/src/WSServer.h b/src/WSServer.h index 5d97af1f..0c4bdee5 100644 --- a/src/WSServer.h +++ b/src/WSServer.h @@ -30,6 +30,8 @@ with this program. If not, see #include #include +#include "ConnectionProperties.h" + #include "WSRequestHandler.h" QT_FORWARD_DECLARE_CLASS(QWebSocketServer) @@ -73,7 +75,7 @@ private: server _server; quint16 _serverPort; std::set> _connections; - std::map> _connectionProperties; + std::map> _connectionProperties; QMutex _clMutex; QThreadPool _threadPool; }; diff --git a/src/obs-websocket.h b/src/obs-websocket.h index be5756a1..08aed786 100644 --- a/src/obs-websocket.h +++ b/src/obs-websocket.h @@ -37,7 +37,6 @@ using OBSDataArrayAutoRelease = using OBSOutputAutoRelease = OBSRef; -#define PROP_AUTHENTICATED "wsclient_authenticated" #define OBS_WEBSOCKET_VERSION "4.6.0" #define blog(level, msg, ...) blog(level, "[obs-websocket] " msg, ##__VA_ARGS__) From d8b37328a1259c54cb49c664aeb01e8522016523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Thu, 2 May 2019 13:11:34 +0200 Subject: [PATCH 07/11] ConnProperties: atomic "authenticated" field --- src/ConnectionProperties.cpp | 9 +++++++-- src/ConnectionProperties.h | 5 ++++- src/WSServer.cpp | 1 - 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ConnectionProperties.cpp b/src/ConnectionProperties.cpp index 567bac83..485123de 100644 --- a/src/ConnectionProperties.cpp +++ b/src/ConnectionProperties.cpp @@ -18,12 +18,17 @@ with this program. If not, see #include "ConnectionProperties.h" +ConnectionProperties::ConnectionProperties() + : _authenticated(false) +{ +} + bool ConnectionProperties::isAuthenticated() { - return _authenticated; + return _authenticated.load(); } void ConnectionProperties::setAuthenticated(bool authenticated) { - _authenticated = authenticated; + _authenticated.store(authenticated); } \ No newline at end of file diff --git a/src/ConnectionProperties.h b/src/ConnectionProperties.h index 93d83270..5969fb88 100644 --- a/src/ConnectionProperties.h +++ b/src/ConnectionProperties.h @@ -18,11 +18,14 @@ with this program. If not, see #pragma once +#include + class ConnectionProperties { public: + explicit ConnectionProperties(); bool isAuthenticated(); void setAuthenticated(bool authenticated); private: - bool _authenticated; + boost::atomic _authenticated; }; \ No newline at end of file diff --git a/src/WSServer.cpp b/src/WSServer.cpp index f810216e..3b6e3db5 100644 --- a/src/WSServer.cpp +++ b/src/WSServer.cpp @@ -155,7 +155,6 @@ void WSServer::onOpen(connection_hdl hdl) { QMutexLocker locker(&_clMutex); _connections.insert(hdl); - _connectionProperties[hdl] = ConnectionProperties(); locker.unlock(); QString clientIp = getRemoteEndpoint(hdl); From cba2bf5cb83ba336cbcf7fc8d2e23e1e536e467c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Thu, 2 May 2019 13:16:39 +0200 Subject: [PATCH 08/11] ci(macos): fix obs build issue --- CI/install-build-obs-macos.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/CI/install-build-obs-macos.sh b/CI/install-build-obs-macos.sh index 8ac4c6f1..f3ddb018 100755 --- a/CI/install-build-obs-macos.sh +++ b/CI/install-build-obs-macos.sh @@ -37,6 +37,7 @@ cmake .. \ -DBUILD_CAPTIONS=true \ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 \ -DDISABLE_PLUGINS=true \ + -DENABLE_SCRIPTING=0 -DDepsPath=/tmp/obsdeps \ -DCMAKE_PREFIX_PATH=/usr/local/opt/qt/lib/cmake \ && make -j4 From 0b9750202917c12f0fce830c6d021c11ed28a107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Thu, 2 May 2019 13:17:38 +0200 Subject: [PATCH 09/11] ci(macos): fix oops --- CI/install-build-obs-macos.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CI/install-build-obs-macos.sh b/CI/install-build-obs-macos.sh index f3ddb018..0dc610aa 100755 --- a/CI/install-build-obs-macos.sh +++ b/CI/install-build-obs-macos.sh @@ -37,7 +37,7 @@ cmake .. \ -DBUILD_CAPTIONS=true \ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 \ -DDISABLE_PLUGINS=true \ - -DENABLE_SCRIPTING=0 + -DENABLE_SCRIPTING=0 \ -DDepsPath=/tmp/obsdeps \ -DCMAKE_PREFIX_PATH=/usr/local/opt/qt/lib/cmake \ && make -j4 From 3fdf77d29b8702a918522a966ca2cd7e30209065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Thu, 2 May 2019 13:22:04 +0200 Subject: [PATCH 10/11] ConnProperties: use std atomic --- src/ConnectionProperties.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ConnectionProperties.h b/src/ConnectionProperties.h index 5969fb88..a766ef6a 100644 --- a/src/ConnectionProperties.h +++ b/src/ConnectionProperties.h @@ -18,7 +18,7 @@ with this program. If not, see #pragma once -#include +#include class ConnectionProperties { @@ -27,5 +27,5 @@ public: bool isAuthenticated(); void setAuthenticated(bool authenticated); private: - boost::atomic _authenticated; + std::atomic _authenticated; }; \ No newline at end of file From bc1c6f7b9aeb56c36ff6e4f468a097831f28c76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Thu, 2 May 2019 13:29:23 +0200 Subject: [PATCH 11/11] remove boost atomic uses --- src/WSServer.cpp | 3 --- src/WSServer.h | 1 - 2 files changed, 4 deletions(-) diff --git a/src/WSServer.cpp b/src/WSServer.cpp index 3b6e3db5..6ca69393 100644 --- a/src/WSServer.cpp +++ b/src/WSServer.cpp @@ -180,9 +180,6 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message) std::string response = handler.processIncomingMessage(payload); _server.send(hdl, response, websocketpp::frame::opcode::text); - - boost::atomic atomicTest; - atomicTest.load().insert("jambon", true); }); } diff --git a/src/WSServer.h b/src/WSServer.h index 0c4bdee5..c65d16bd 100644 --- a/src/WSServer.h +++ b/src/WSServer.h @@ -25,7 +25,6 @@ with this program. If not, see #include #include #include -#include #include #include