added send buffer to limit socket operations to one thread

This commit is contained in:
Max-Wilhelm Bruker 2011-03-22 20:45:18 +01:00
parent 81a5d58d70
commit 45890b836b
5 changed files with 40 additions and 7 deletions

View file

@ -4,6 +4,7 @@
#include <QObject>
#include <QStringList>
#include <QMap>
#include <QMutex>
class Server_Game;
class Server_Room;
@ -22,6 +23,7 @@ private slots:
void gameClosing(int gameId);
void broadcastRoomUpdate();
public:
mutable QMutex serverMutex;
Server(QObject *parent = 0);
~Server();
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password);

View file

@ -17,6 +17,7 @@ Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
: QObject(parent), server(_server), authState(PasswordWrong), acceptsUserListChanges(false), acceptsRoomListChanges(false), userInfo(0), timeRunning(0), lastDataReceived(0)
{
connect(server, SIGNAL(pingClockTimeout()), this, SLOT(pingClockTimeout()));
connect(this, SIGNAL(sigGameCreated(Server_Game *)), this, SLOT(processSigGameCreated(Server_Game *)), Qt::QueuedConnection);
}
Server_ProtocolHandler::~Server_ProtocolHandler()
@ -430,6 +431,13 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
void Server_ProtocolHandler::gameCreated(Server_Game *game)
{
emit sigGameCreated(game);
}
void Server_ProtocolHandler::processSigGameCreated(Server_Game *game)
{
QMutexLocker locker(&game->gameMutex);
Server_Player *creator = game->getPlayers().values().first();
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));

View file

@ -91,7 +91,11 @@ private:
ResponseCode processCommandHelper(Command *command, CommandContainer *cont);
private slots:
void pingClockTimeout();
void processSigGameCreated(Server_Game *game);
signals:
void sigGameCreated(Server_Game *game);
public:
mutable QMutex protocolHandlerMutex;
Server_ProtocolHandler(Server *_server, QObject *parent = 0);
~Server_ProtocolHandler();
void playerRemovedFromGame(Server_Game *game);