]> Some of my projects - aniplayer-old.git/commitdiff
Client does not own AbstractCommand's and never attempts to delete them.
authorAPTX <marek321@gmail.com>
Fri, 26 Feb 2010 01:05:17 +0000 (02:05 +0100)
committerAPTX <marek321@gmail.com>
Fri, 26 Feb 2010 01:05:17 +0000 (02:05 +0100)
lib/anidbudpclient/client.cpp
lib/anidbudpclient/client.h

index 57ab5f49bd65339e3a5ec2e9bb7a24a5bbd1a72d..38d9172185064f79527626ee32d5989a35c6163e 100644 (file)
@@ -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;
index 6f5b85419cd3dfcb6b176e0c749bcc277fe9f924..854938fbdcdba796f071a6d60c28a1c0500c1125 100644 (file)
@@ -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);