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())
{
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
{
connect();
+ QObject::connect(command, SIGNAL(destroyed()), this, SLOT(removeDeletedFromQueue()));
enqueueCommand(command);
}
enqueueCommand(new RawCommand(command));
}
+void Client::cancel(AbstractCommand *command)
+{
+ commandQueue.removeAll(command);
+}
+
void Client::logout()
{
if (!m_sessionId.isEmpty())
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;
void send(AbstractCommand *command);
void sendRaw(QByteArray command);
+ void cancel(AbstractCommand *command);
signals:
void commandTimeout(const QByteArray &commandId);
+ void removeDeletedFromQueue();
+
private:
void enqueueCommand(AbstractCommand *command, bool first = false);
void enqueueControlCommand(AbstractCommand *command, bool first = false);