made server threading optional
This commit is contained in:
parent
c67bc65762
commit
a4097659d3
4 changed files with 18 additions and 12 deletions
|
@ -97,13 +97,6 @@
|
|||
<file>resources/counters/general.svg</file>
|
||||
<file>resources/counters/general_highlight.svg</file>
|
||||
|
||||
<file>resources/sounds/draw.raw</file>
|
||||
<file>resources/sounds/notification.raw</file>
|
||||
<file>resources/sounds/playcard.raw</file>
|
||||
<file>resources/sounds/shuffle.raw</file>
|
||||
<file>resources/sounds/tap.raw</file>
|
||||
<file>resources/sounds/untap.raw</file>
|
||||
|
||||
<file>resources/userlevels/normal.svg</file>
|
||||
<file>resources/userlevels/registered.svg</file>
|
||||
<file>resources/userlevels/judge.svg</file>
|
||||
|
|
|
@ -3,6 +3,7 @@ port=4747
|
|||
statusupdate=15000
|
||||
logfile=server.log
|
||||
id=1
|
||||
threaded=0
|
||||
|
||||
[authentication]
|
||||
method=none
|
||||
|
|
|
@ -26,11 +26,21 @@
|
|||
#include "serversocketinterface.h"
|
||||
#include "serversocketthread.h"
|
||||
#include "protocol.h"
|
||||
#include "server_logger.h"
|
||||
#include "main.h"
|
||||
|
||||
void Servatrice_TcpServer::incomingConnection(int socketDescriptor)
|
||||
{
|
||||
ServerSocketThread *sst = new ServerSocketThread(socketDescriptor, server, this);
|
||||
sst->start();
|
||||
if (threaded) {
|
||||
ServerSocketThread *sst = new ServerSocketThread(socketDescriptor, server, this);
|
||||
sst->start();
|
||||
} else {
|
||||
QTcpSocket *socket = new QTcpSocket;
|
||||
socket->setSocketDescriptor(socketDescriptor);
|
||||
logger->logMessage(QString("incoming connection: %1").arg(socket->peerAddress().toString()));
|
||||
|
||||
new ServerSocketInterface(server, socket);
|
||||
}
|
||||
}
|
||||
|
||||
Servatrice::Servatrice(QSettings *_settings, QObject *parent)
|
||||
|
@ -55,7 +65,8 @@ Servatrice::Servatrice(QSettings *_settings, QObject *parent)
|
|||
statusUpdateClock->start(statusUpdateTime);
|
||||
}
|
||||
|
||||
tcpServer = new Servatrice_TcpServer(this);
|
||||
bool threaded = settings->value("server/threaded", false).toInt();
|
||||
tcpServer = new Servatrice_TcpServer(this, threaded);
|
||||
int port = settings->value("server/port", 4747).toInt();
|
||||
qDebug() << "Starting server on port" << port;
|
||||
if (tcpServer->listen(QHostAddress::Any, port))
|
||||
|
|
|
@ -36,9 +36,10 @@ class Servatrice_TcpServer : public QTcpServer {
|
|||
Q_OBJECT
|
||||
private:
|
||||
Servatrice *server;
|
||||
bool threaded;
|
||||
public:
|
||||
Servatrice_TcpServer(Servatrice *_server, QObject *parent = 0)
|
||||
: QTcpServer(parent), server(_server) { }
|
||||
Servatrice_TcpServer(Servatrice *_server, bool _threaded, QObject *parent = 0)
|
||||
: QTcpServer(parent), server(_server), threaded(_threaded) { }
|
||||
protected:
|
||||
void incomingConnection(int socketDescriptor);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue