Fix IPCSocket issues
authorunc0rr
Sun, 04 Feb 2007 20:48:11 +0000
changeset 389 9628e69b609f
parent 388 dcf5335940bd
child 390 dca6bd77d71d
Fix IPCSocket issues
QTfrontend/tcpBase.cpp
QTfrontend/tcpBase.h
--- a/QTfrontend/tcpBase.cpp	Sun Feb 04 17:00:46 2007 +0000
+++ b/QTfrontend/tcpBase.cpp	Sun Feb 04 20:48:11 2007 +0000
@@ -26,7 +26,7 @@
 #include "hwconsts.h"
 
 QList<TCPBase*> srvsList;
-QTcpServer* TCPBase::IPCServer(0);
+QPointer<QTcpServer> TCPBase::IPCServer(0);
 
 TCPBase::TCPBase(bool demoMode) :
   m_isDemoMode(demoMode),
@@ -51,9 +51,11 @@
     // connection should be already finished
     return;
   }
+  disconnect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
   IPCSocket = IPCServer->nextPendingConnection();
   if(!IPCSocket) return;
   connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
+  connect(IPCSocket, SIGNAL(disconnected()), IPCSocket, SLOT(deleteLater()));
   connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
   SendToClientFirst();
 }
@@ -62,7 +64,7 @@
 {
   connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
   IPCSocket = 0;
-  
+
   QProcess * process;
   process = new QProcess;
   connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError)));
@@ -72,10 +74,6 @@
 
 void TCPBase::ClientDisconnect()
 {
-  IPCSocket->close();
-  IPCSocket->deleteLater();
-  // IPCSocket = 0; // FIXME: breaks image receiving
-
   onClientDisconnect();
 
   readbuffer.clear();
@@ -99,7 +97,7 @@
 
 void TCPBase::tcpServerReady()
 {
-  disconnect(srvsList.front(), SIGNAL(isReadyNow()), *(++srvsList.begin()), SLOT(tcpServerReady()));
+  disconnect(srvsList.front(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady()));
   srvsList.pop_front();
 
   RealStart();
@@ -114,7 +112,7 @@
     srvsList.push_back(this);
     return;
   }
-  
+
   RealStart();
 }
 
--- a/QTfrontend/tcpBase.h	Sun Feb 04 17:00:46 2007 +0000
+++ b/QTfrontend/tcpBase.h	Sun Feb 04 20:48:11 2007 +0000
@@ -26,6 +26,7 @@
 #include <QString>
 #include <QDir>
 #include <QProcess>
+#include <QPointer>
 
 #include <QImage>
 
@@ -34,7 +35,7 @@
 class TCPBase : public QObject
 {
   Q_OBJECT
-    
+
  public:
   TCPBase(bool demoMode);
 
@@ -60,11 +61,11 @@
   virtual void SendToClientFirst();
 
  private:
-  static QTcpServer* IPCServer;
+  static QPointer<QTcpServer> IPCServer;
 
   bool m_isDemoMode;
   void RealStart();
-  QTcpSocket * IPCSocket;
+  QPointer<QTcpSocket> IPCSocket;
 
  private slots:
   void NewConnection();