Skip to content
This repository
Browse code

Disconnect signals from TimeoutCommand after fired

  • Loading branch information...
commit 7289a8e77acc61737738dd339b517a1bc9fa1ad1 1 parent f20d32d
Matthew Horan authored October 25, 2012
14  src/Connection.cpp
@@ -22,17 +22,15 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par
22 22
 }
23 23
 
24 24
 void Connection::commandReady(Command *command) {
25  
-  m_queuedCommand = command;
26 25
   m_manager->logger() << "Received" << command->toString();
27  
-  startCommand();
  26
+  startCommand(command);
28 27
 }
29 28
 
30  
-void Connection::startCommand() {
  29
+void Connection::startCommand(Command *command) {
31 30
   if (m_pageSuccess) {
32  
-    m_runningCommand = new PageLoadingCommand(m_queuedCommand, m_manager, this);
33  
-    m_runningCommand = new TimeoutCommand(m_runningCommand, m_manager, this);
34  
-    connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
35  
-    m_runningCommand->start();
  31
+    command = new TimeoutCommand(new PageLoadingCommand(command, m_manager, this), m_manager, this);
  32
+    connect(command, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
  33
+    command->start();
36 34
   } else {
37 35
     writePageLoadFailure();
38 36
   }
@@ -50,7 +48,7 @@ void Connection::writePageLoadFailure() {
50 48
 
51 49
 void Connection::finishCommand(Response *response) {
52 50
   m_pageSuccess = true;
53  
-  m_runningCommand->deleteLater();
  51
+  sender()->deleteLater();
54 52
   writeResponse(response);
55 53
 }
56 54
 
4  src/Connection.h
@@ -22,16 +22,14 @@ class Connection : public QObject {
22 22
     void pendingLoadFinished(bool success);
23 23
 
24 24
   private:
25  
-    void startCommand();
  25
+    void startCommand(Command *);
26 26
     void writeResponse(Response *response);
27 27
     void writePageLoadFailure();
28 28
 
29 29
     QTcpSocket *m_socket;
30  
-    Command *m_queuedCommand;
31 30
     WebPageManager *m_manager;
32 31
     CommandParser *m_commandParser;
33 32
     CommandFactory *m_commandFactory;
34  
-    Command *m_runningCommand;
35 33
     bool m_pageSuccess;
36 34
     WebPage *currentPage();
37 35
 };
9  src/TimeoutCommand.cpp
@@ -39,6 +39,9 @@ void TimeoutCommand::pendingLoadFinished(bool success) {
39 39
   if (success) {
40 40
     startCommand();
41 41
   } else {
  42
+    disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
  43
+    disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
  44
+    disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
42 45
     emit finished(new Response(false, m_manager->currentPage()->failureString()));
43 46
   }
44 47
 }
@@ -48,12 +51,18 @@ void TimeoutCommand::pageLoadingFromCommand() {
48 51
 }
49 52
 
50 53
 void TimeoutCommand::commandTimeout() {
  54
+  disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
  55
+  disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
  56
+  disconnect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
51 57
   m_manager->currentPage()->triggerAction(QWebPage::Stop);
52 58
   m_command->deleteLater();
53 59
   emit finished(new Response(false, QString("timeout")));
54 60
 }
55 61
 
56 62
 void TimeoutCommand::commandFinished(Response *response) {
  63
+  disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
  64
+  disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
  65
+  disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
57 66
   m_command->deleteLater();
58 67
   emit finished(response);
59 68
 }

0 notes on commit 7289a8e

Please sign in to comment.
Something went wrong with that request. Please try again.