Просмотр исходного кода

fix error after disconnected

master
Robin Thoni 11 лет назад
Родитель
Сommit
3773af4c13
7 измененных файлов: 42 добавлений и 11 удалений
  1. 1
    1
      Makefile
  2. 1
    1
      commons.pri
  3. 2
    2
      ptsocket/Makefile
  4. 5
    5
      ptsocket/ptsocket.cpp
  5. 2
    2
      tests/Makefile
  6. 29
    0
      tests/test.cpp
  7. 2
    0
      tests/test.h

+ 1
- 1
Makefile Просмотреть файл

@@ -1,6 +1,6 @@
1 1
 #############################################################################
2 2
 # Makefile for building: libptsocket
3
-# Generated by qmake (2.01a) (Qt 4.8.2) on: mar. déc. 31 15:44:02 2013
3
+# Generated by qmake (2.01a) (Qt 4.8.2) on: mer. janv. 1 15:03:04 2014
4 4
 # Project:  libptsocket.pro
5 5
 # Template: subdirs
6 6
 # Command: /usr/bin/qmake -o Makefile libptsocket.pro

+ 1
- 1
commons.pri Просмотреть файл

@@ -1 +1 @@
1
-#DEFINES += PT_DEBUG
1
+DEFINES += PT_DEBUG

+ 2
- 2
ptsocket/Makefile Просмотреть файл

@@ -1,6 +1,6 @@
1 1
 #############################################################################
2 2
 # Makefile for building: libptsocket.so.1.0.0
3
-# Generated by qmake (2.01a) (Qt 4.8.2) on: mar. déc. 31 16:37:00 2013
3
+# Generated by qmake (2.01a) (Qt 4.8.2) on: mer. janv. 1 15:03:47 2014
4 4
 # Project:  ptsocket.pro
5 5
 # Template: lib
6 6
 # Command: /usr/bin/qmake -o Makefile ptsocket.pro
@@ -10,7 +10,7 @@
10 10
 
11 11
 CC            = gcc
12 12
 CXX           = g++
13
-DEFINES       = -DQT_WEBKIT -DLIBPTSOCKET_LIBRARY -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
13
+DEFINES       = -DQT_WEBKIT -DPT_DEBUG -DLIBPTSOCKET_LIBRARY -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
14 14
 CFLAGS        = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
15 15
 CXXFLAGS      = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
16 16
 INCPATH       = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4 -I.

+ 5
- 5
ptsocket/ptsocket.cpp Просмотреть файл

@@ -259,18 +259,18 @@ void PTSocket::m_stateChanged(QAbstractSocket::SocketState s)
259 259
     m_timeoutTimer.start();
260 260
     if(s == QAbstractSocket::UnconnectedState)
261 261
     {
262
-        m_timeoutTimer.stop();
263
-        setState(Disconnected);
262
+	if(error() == QAbstractSocket::UnknownSocketError || error() == QAbstractSocket::RemoteHostClosedError)
263
+	{
264
+	        m_timeoutTimer.stop();
265
+        	setState(Disconnected);
266
+	}
264 267
     }
265 268
 }
266 269
 
267 270
 void PTSocket::m_socketError(QAbstractSocket::SocketError s)
268 271
 {
269 272
     if(s != QAbstractSocket::RemoteHostClosedError)
270
-    {
271
-        qDebug()<<"Socket error:"<<s;
272 273
         setState(Error);
273
-    }
274 274
 }
275 275
 
276 276
 void PTSocket::setState(PTSocket::State s)

+ 2
- 2
tests/Makefile Просмотреть файл

@@ -1,6 +1,6 @@
1 1
 #############################################################################
2 2
 # Makefile for building: tests
3
-# Generated by qmake (2.01a) (Qt 4.8.2) on: mar. déc. 31 16:15:32 2013
3
+# Generated by qmake (2.01a) (Qt 4.8.2) on: mer. janv. 1 15:03:53 2014
4 4
 # Project:  tests.pro
5 5
 # Template: app
6 6
 # Command: /usr/bin/qmake -o Makefile tests.pro
@@ -10,7 +10,7 @@
10 10
 
11 11
 CC            = gcc
12 12
 CXX           = g++
13
-DEFINES       = -DQT_WEBKIT -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
13
+DEFINES       = -DQT_WEBKIT -DPT_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
14 14
 CFLAGS        = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
15 15
 CXXFLAGS      = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
16 16
 INCPATH       = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4 -I../ptsocket -I.

+ 29
- 0
tests/test.cpp Просмотреть файл

@@ -50,6 +50,13 @@ Test::Test(QObject *parent) : QObject(parent)
50 50
                     <<TestState(1, PTSocket::Handshaked)
51 51
                     <<TestState(1, PTSocket::Disconnecting)
52 52
                     <<TestState(1, PTSocket::Disconnected));
53
+    m_testsStates<<(QList<TestState>()//Error Invalid Host
54
+			<<TestState(1, PTSocket::HostLookUp)
55
+			<<TestState(1, PTSocket::Error));
56
+    m_testsStates<<(QList<TestState>()//Error Invalid Port
57
+			<<TestState(1, PTSocket::HostLookUp)
58
+			<<TestState(1, PTSocket::Connecting)
59
+			<<TestState(1, PTSocket::Error));
53 60
     m_currentState = 0;
54 61
     m_currentTest = -1;
55 62
 }
@@ -134,6 +141,22 @@ void Test::test5HandshakeFake2()
134 141
     sock->connectToHost("127.0.0.1", m_serv->serverPort());
135 142
 }
136 143
 
144
+void Test::test6Error1()
145
+{
146
+	preTest();
147
+	PTSocket* sock = newSocket();
148
+	m_socketsIds.insert(sock, 1);
149
+	sock->connectToHost("", m_serv->serverPort());
150
+}
151
+
152
+void Test::test7Error2()
153
+{
154
+	preTest();
155
+	PTSocket* sock = newSocket();
156
+	m_socketsIds.insert(sock, 1);
157
+	sock->connectToHost("127.0.0.1", 15963);
158
+}
159
+
137 160
 void Test::timeout(int i)
138 161
 {
139 162
     m_timeoutTimer.start(i);
@@ -167,6 +190,12 @@ void Test::timedout()
167 190
         case 4:
168 191
             test5HandshakeFake2();
169 192
             break;
193
+	case 5:
194
+		test6Error1();
195
+		break;
196
+	case 6:
197
+		test7Error2();
198
+		break;
170 199
         default:
171 200
             qApp->quit();
172 201
         }

+ 2
- 0
tests/test.h Просмотреть файл

@@ -26,6 +26,8 @@ public slots:
26 26
     void test3Handshake();
27 27
     void test4HandshakeFake1();
28 28
     void test5HandshakeFake2();
29
+    void test6Error1();
30
+    void test7Error2();
29 31
 
30 32
 private slots:
31 33
     void timeout(int i = 15000);

Загрузка…
Отмена
Сохранить