mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
server: use a thread pool
This commit is contained in:
parent
2d84ad8963
commit
6a10662bc4
@ -25,6 +25,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
#include <QtWidgets/QMessageBox>
|
#include <QtWidgets/QMessageBox>
|
||||||
#include <QtConcurrent/QtConcurrent>
|
#include <QtConcurrent/QtConcurrent>
|
||||||
#include <obs-frontend-api.h>
|
#include <obs-frontend-api.h>
|
||||||
|
#include <util/platform.h>
|
||||||
|
|
||||||
#include "WSServer.h"
|
#include "WSServer.h"
|
||||||
#include "obs-websocket.h"
|
#include "obs-websocket.h"
|
||||||
@ -127,6 +128,8 @@ void WSServer::stop()
|
|||||||
_connections.clear();
|
_connections.clear();
|
||||||
_connectionProperties.clear();
|
_connectionProperties.clear();
|
||||||
|
|
||||||
|
_threadPool.waitForDone();
|
||||||
|
|
||||||
while (!_server.stopped()) {
|
while (!_server.stopped()) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
}
|
}
|
||||||
@ -166,7 +169,7 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QtConcurrent::run([=]() {
|
QtConcurrent::run(&_threadPool, [=]() {
|
||||||
std::string payload = message->get_payload();
|
std::string payload = message->get_payload();
|
||||||
|
|
||||||
QMutexLocker locker(&_clMutex);
|
QMutexLocker locker(&_clMutex);
|
||||||
|
@ -22,6 +22,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
#include <QtCore/QMutex>
|
#include <QtCore/QMutex>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
#include <QtCore/QVariantHash>
|
#include <QtCore/QVariantHash>
|
||||||
|
#include <QtCore/QThreadPool>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
@ -54,6 +55,9 @@ public:
|
|||||||
void start(quint16 port);
|
void start(quint16 port);
|
||||||
void stop();
|
void stop();
|
||||||
void broadcast(std::string message);
|
void broadcast(std::string message);
|
||||||
|
QThreadPool* threadPool() {
|
||||||
|
return &_threadPool;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static WSServerPtr _instance;
|
static WSServerPtr _instance;
|
||||||
@ -71,4 +75,5 @@ private:
|
|||||||
std::set<connection_hdl, std::owner_less<connection_hdl>> _connections;
|
std::set<connection_hdl, std::owner_less<connection_hdl>> _connections;
|
||||||
std::map<connection_hdl, QVariantHash, std::owner_less<connection_hdl>> _connectionProperties;
|
std::map<connection_hdl, QVariantHash, std::owner_less<connection_hdl>> _connectionProperties;
|
||||||
QMutex _clMutex;
|
QMutex _clMutex;
|
||||||
|
QThreadPool _threadPool;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user