From: APTX Date: Fri, 26 Feb 2010 01:05:17 +0000 (+0100) Subject: Client does not own AbstractCommand's and never attempts to delete them. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=d6423f7c1dddd8f9c067e54f90df9881751409bb;p=aniplayer-old.git Client does not own AbstractCommand's and never attempts to delete them. --- diff --git a/lib/anidbudpclient/client.cpp b/lib/anidbudpclient/client.cpp index 57ab5f4..38d9172 100644 --- a/lib/anidbudpclient/client.cpp +++ b/lib/anidbudpclient/client.cpp @@ -138,17 +138,12 @@ Client::~Client() foreach (CommandData *cmd, sentCommands) { - if (cmd->command->waitForResult()) - { - delete cmd->command; - } - else + if (!cmd->command->waitForResult()) { // Send CLIENT_DESTROYED to indicate that no real reply will come. cmd->command->setRawReply(CLIENT_DESTROYED, "", this); } } - qDeleteAll(sentCommands); if (!m_sessionId.isEmpty()) { @@ -580,8 +575,8 @@ qDebug() << "LOGIN FIRST required, authing"; if (replyCode > 601 && replyCode < 700) { qDebug() << QString("SERVER ERROR %1").arg(replyCode); + emit connectionError(); } - emit connectionError(); break; } // tag + space + replyCode + space = 5 + 1 + 3 + 1 @@ -671,6 +666,7 @@ void Client::send(AbstractCommand *command) { connect(); + QObject::connect(command, SIGNAL(destroyed()), this, SLOT(removeDeletedFromQueue())); enqueueCommand(command); } @@ -680,6 +676,11 @@ qDebug() << QString("Sending RAW command: %1").arg(command.constData()); enqueueCommand(new RawCommand(command)); } +void Client::cancel(AbstractCommand *command) +{ + commandQueue.removeAll(command); +} + void Client::logout() { if (!m_sessionId.isEmpty()) @@ -771,6 +772,12 @@ qDebug() << QString("SENDING datagram:\n\t%1\nto: %2 ([%3]:%4)") socket->writeDatagram(datagram, m_hostAddress, m_hostPort); } +void Client::removeDeletedFromQueue() +{ + AbstractCommand *cmd = (AbstractCommand *) sender(); + cancel(cmd); +} + QByteArray Client::buildCmd(const QString &cmd, const QVariantMap &args) { QString result = cmd; diff --git a/lib/anidbudpclient/client.h b/lib/anidbudpclient/client.h index 6f5b854..854938f 100644 --- a/lib/anidbudpclient/client.h +++ b/lib/anidbudpclient/client.h @@ -103,6 +103,7 @@ public slots: void send(AbstractCommand *command); void sendRaw(QByteArray command); + void cancel(AbstractCommand *command); signals: @@ -149,6 +150,8 @@ private slots: void commandTimeout(const QByteArray &commandId); + void removeDeletedFromQueue(); + private: void enqueueCommand(AbstractCommand *command, bool first = false); void enqueueControlCommand(AbstractCommand *command, bool first = false);