From 64762b6fad471644767b663566d727bb3febf95c Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Tue, 15 Jul 2014 22:53:18 -0400 Subject: [PATCH] Delete pending commands on reset * If an exception is raised in the Ruby process, it's possible for Reset to be sent to the server while the previous command is still running. This ensures that pending commands are stopped when handling Reset. --- src/Connection.cpp | 11 ++++++++--- src/Connection.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Connection.cpp b/src/Connection.cpp index dc33139..ba16338 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -17,6 +17,7 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par m_commandFactory = new CommandFactory(m_manager, this); m_commandParser = new CommandParser(socket, m_commandFactory, this); m_pageSuccess = true; + m_pendingCommand = NULL; connect(m_socket, SIGNAL(readyRead()), m_commandParser, SLOT(checkNext())); connect(m_commandParser, SIGNAL(commandReady(Command *)), this, SLOT(commandReady(Command *))); connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool))); @@ -28,10 +29,13 @@ void Connection::commandReady(Command *command) { } void Connection::startCommand(Command *command) { + if (m_pendingCommand) { + m_pendingCommand->deleteLater(); + } if (m_pageSuccess) { - command = new TimeoutCommand(new PageLoadingCommand(command, m_manager, this), m_manager, this); - connect(command, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *))); - command->start(); + m_pendingCommand = new TimeoutCommand(new PageLoadingCommand(command, m_manager, this), m_manager, this); + connect(m_pendingCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *))); + m_pendingCommand->start(); } else { writePageLoadFailure(); } @@ -52,6 +56,7 @@ void Connection::finishCommand(Response *response) { m_pageSuccess = true; writeResponse(response); sender()->deleteLater(); + m_pendingCommand = NULL; } void Connection::writeResponse(Response *response) { diff --git a/src/Connection.h b/src/Connection.h index f33dd6e..7927588 100644 --- a/src/Connection.h +++ b/src/Connection.h @@ -32,5 +32,6 @@ class Connection : public QObject { CommandFactory *m_commandFactory; bool m_pageSuccess; WebPage *currentPage(); + Command *m_pendingCommand; };