made server threaded, fixing issue #51

This commit is contained in:
Max-Wilhelm Bruker 2012-05-28 18:51:58 +02:00
parent b328c1ed4d
commit 520300dc86
14 changed files with 108 additions and 37 deletions

View file

@ -56,11 +56,21 @@ Server::~Server()
void Server::prepareDestroy()
{
clientsLock.lockForWrite();
while (!clients.isEmpty())
clients.first()->prepareDestroy();
clientsLock.lockForRead();
for (int i = 0; i < clients.size(); ++i)
QMetaObject::invokeMethod(clients.at(i), "prepareDestroy", Qt::QueuedConnection);
clientsLock.unlock();
// dirty :(
bool done = false;
do {
usleep(10000);
clientsLock.lockForRead();
if (clients.isEmpty())
done = true;
clientsLock.unlock();
} while (!done);
roomsLock.lockForWrite();
QMapIterator<int, Server_Room *> roomIterator(rooms);
while (roomIterator.hasNext())

View file

@ -23,6 +23,7 @@
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, Server_DatabaseInterface *_databaseInterface, QObject *parent)
: QObject(parent),
Server_AbstractUserInterface(_server),
deleted(false),
databaseInterface(_databaseInterface),
authState(NotLoggedIn),
acceptsUserListChanges(false),
@ -39,7 +40,9 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
void Server_ProtocolHandler::prepareDestroy()
{
qDebug("Server_ProtocolHandler::prepareDestroy");
if (deleted)
return;
deleted = true;
QMapIterator<int, Server_Room *> roomIterator(rooms);
while (roomIterator.hasNext())

View file

@ -43,7 +43,8 @@ class Server_ProtocolHandler : public QObject, public Server_AbstractUserInterfa
Q_OBJECT
protected:
QMap<int, Server_Room *> rooms;
bool deleted;
Server_DatabaseInterface *databaseInterface;
AuthenticationResult authState;
bool acceptsUserListChanges;