mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 23:53:54 -07:00
mutex fixes, server shutdown works again
This commit is contained in:
parent
d792c3ddc6
commit
671214c60e
9 changed files with 34 additions and 27 deletions
|
|
@ -128,7 +128,6 @@ int main(int argc, char *argv[])
|
|||
loggerThread = new QThread;
|
||||
logger = new ServerLogger;
|
||||
logger->moveToThread(loggerThread);
|
||||
QObject::connect(logger, SIGNAL(destroyed()), loggerThread, SLOT(quit()));
|
||||
|
||||
loggerThread->start();
|
||||
QMetaObject::invokeMethod(logger, "startLog", Qt::BlockingQueuedConnection, Q_ARG(QString, settings->value("server/logfile").toString()));
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ class Servatrice : public Server
|
|||
private slots:
|
||||
void statusUpdate();
|
||||
void shutdownTimeout();
|
||||
public slots:
|
||||
void scheduleShutdown(const QString &reason, int minutes);
|
||||
public:
|
||||
mutable QMutex dbMutex;
|
||||
Servatrice(QSettings *_settings, QObject *parent = 0);
|
||||
|
|
@ -110,7 +112,6 @@ public:
|
|||
QMap<QString, ServerInfo_User> getIgnoreList(const QString &name);
|
||||
bool isInBuddyList(const QString &whoseList, const QString &who);
|
||||
bool isInIgnoreList(const QString &whoseList, const QString &who);
|
||||
void scheduleShutdown(const QString &reason, int minutes);
|
||||
void incTxBytes(quint64 num);
|
||||
void incRxBytes(quint64 num);
|
||||
int getUserIdInDB(const QString &name);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ ServerLogger::ServerLogger(QObject *parent)
|
|||
ServerLogger::~ServerLogger()
|
||||
{
|
||||
flushBuffer();
|
||||
// This does not work with the destroyed() signal as this destructor is called after the main event loop is done.
|
||||
thread()->quit();
|
||||
}
|
||||
|
||||
void ServerLogger::startLog(const QString &logFileName)
|
||||
|
|
|
|||
|
|
@ -60,8 +60,9 @@ static const int protocolVersion = 13;
|
|||
ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent)
|
||||
: Server_ProtocolHandler(_server, parent), servatrice(_server), socket(_socket), messageInProgress(false)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
connect(socket, SIGNAL(readyRead()), this, SLOT(readClient()));
|
||||
connect(socket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(catchSocketError(QAbstractSocket::SocketError)));
|
||||
connect(this, SIGNAL(outputBufferChanged()), this, SLOT(flushOutputBuffer()), Qt::QueuedConnection);
|
||||
|
||||
|
|
@ -81,18 +82,19 @@ ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_s
|
|||
sendProtocolItem(*se);
|
||||
delete se;
|
||||
|
||||
deleteLater();
|
||||
success = false;
|
||||
}
|
||||
|
||||
server->addClient(this);
|
||||
|
||||
if (!success)
|
||||
prepareDestroy();
|
||||
}
|
||||
|
||||
ServerSocketInterface::~ServerSocketInterface()
|
||||
{
|
||||
logger->logMessage("ServerSocketInterface destructor", this);
|
||||
|
||||
prepareDestroy();
|
||||
|
||||
flushOutputBuffer();
|
||||
delete socket;
|
||||
socket = 0;
|
||||
|
|
@ -143,7 +145,7 @@ void ServerSocketInterface::catchSocketError(QAbstractSocket::SocketError socket
|
|||
{
|
||||
qDebug() << "Socket error:" << socketError;
|
||||
|
||||
deleteLater();
|
||||
prepareDestroy();
|
||||
}
|
||||
|
||||
void ServerSocketInterface::transmitProtocolItem(const ServerMessage &item)
|
||||
|
|
@ -623,7 +625,7 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
|
|||
for (int i = 0; i < userList.size(); ++i) {
|
||||
SessionEvent *se = userList[i]->prepareSessionEvent(event);
|
||||
userList[i]->sendProtocolItem(*se);
|
||||
userList[i]->deleteLater();
|
||||
userList[i]->prepareDestroy();
|
||||
delete se;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue