Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Disconnect signals from TimeoutCommand after fired

  • Loading branch information...
commit 7289a8e77acc61737738dd339b517a1bc9fa1ad1 1 parent f20d32d
@mhoran mhoran authored
Showing with 16 additions and 11 deletions.
  1. +6 −8 src/Connection.cpp
  2. +1 −3 src/Connection.h
  3. +9 −0 src/TimeoutCommand.cpp
View
14 src/Connection.cpp
@@ -22,17 +22,15 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par
}
void Connection::commandReady(Command *command) {
- m_queuedCommand = command;
m_manager->logger() << "Received" << command->toString();
- startCommand();
+ startCommand(command);
}
-void Connection::startCommand() {
+void Connection::startCommand(Command *command) {
if (m_pageSuccess) {
- m_runningCommand = new PageLoadingCommand(m_queuedCommand, m_manager, this);
- m_runningCommand = new TimeoutCommand(m_runningCommand, m_manager, this);
- connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
- m_runningCommand->start();
+ command = new TimeoutCommand(new PageLoadingCommand(command, m_manager, this), m_manager, this);
+ connect(command, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
+ command->start();
} else {
writePageLoadFailure();
}
@@ -50,7 +48,7 @@ void Connection::writePageLoadFailure() {
void Connection::finishCommand(Response *response) {
m_pageSuccess = true;
- m_runningCommand->deleteLater();
+ sender()->deleteLater();
writeResponse(response);
}
View
4 src/Connection.h
@@ -22,16 +22,14 @@ class Connection : public QObject {
void pendingLoadFinished(bool success);
private:
- void startCommand();
+ void startCommand(Command *);
void writeResponse(Response *response);
void writePageLoadFailure();
QTcpSocket *m_socket;
- Command *m_queuedCommand;
WebPageManager *m_manager;
CommandParser *m_commandParser;
CommandFactory *m_commandFactory;
- Command *m_runningCommand;
bool m_pageSuccess;
WebPage *currentPage();
};
View
9 src/TimeoutCommand.cpp
@@ -39,6 +39,9 @@ void TimeoutCommand::pendingLoadFinished(bool success) {
if (success) {
startCommand();
} else {
+ disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
+ disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
+ disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
emit finished(new Response(false, m_manager->currentPage()->failureString()));
}
}
@@ -48,12 +51,18 @@ void TimeoutCommand::pageLoadingFromCommand() {
}
void TimeoutCommand::commandTimeout() {
+ disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
+ disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
+ disconnect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
m_manager->currentPage()->triggerAction(QWebPage::Stop);
m_command->deleteLater();
emit finished(new Response(false, QString("timeout")));
}
void TimeoutCommand::commandFinished(Response *response) {
+ disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
+ disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
+ disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
m_command->deleteLater();
emit finished(response);
}
Please sign in to comment.
Something went wrong with that request. Please try again.