Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Disconnect signals from TimeoutCommand after fired
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoran committed Oct 26, 2012
1 parent f20d32d commit 7289a8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
14 changes: 6 additions & 8 deletions src/Connection.cpp
Expand Up @@ -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();
}
Expand All @@ -50,7 +48,7 @@ void Connection::writePageLoadFailure() {

void Connection::finishCommand(Response *response) {
m_pageSuccess = true;
m_runningCommand->deleteLater();
sender()->deleteLater();
writeResponse(response);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Connection.h
Expand Up @@ -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();
};
Expand Down
9 changes: 9 additions & 0 deletions src/TimeoutCommand.cpp
Expand Up @@ -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()));
}
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 7289a8e

Please sign in to comment.