Browse Source

fix error after disconnected

master
Robin Thoni 10 years ago
parent
commit
3773af4c13
7 changed files with 42 additions and 11 deletions
  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 View File

1
 #############################################################################
1
 #############################################################################
2
 # Makefile for building: libptsocket
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
 # Project:  libptsocket.pro
4
 # Project:  libptsocket.pro
5
 # Template: subdirs
5
 # Template: subdirs
6
 # Command: /usr/bin/qmake -o Makefile libptsocket.pro
6
 # Command: /usr/bin/qmake -o Makefile libptsocket.pro

+ 1
- 1
commons.pri View File

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

+ 2
- 2
ptsocket/Makefile View File

1
 #############################################################################
1
 #############################################################################
2
 # Makefile for building: libptsocket.so.1.0.0
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
 # Project:  ptsocket.pro
4
 # Project:  ptsocket.pro
5
 # Template: lib
5
 # Template: lib
6
 # Command: /usr/bin/qmake -o Makefile ptsocket.pro
6
 # Command: /usr/bin/qmake -o Makefile ptsocket.pro
10
 
10
 
11
 CC            = gcc
11
 CC            = gcc
12
 CXX           = g++
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
 CFLAGS        = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
14
 CFLAGS        = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
15
 CXXFLAGS      = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
15
 CXXFLAGS      = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
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.
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 View File

259
     m_timeoutTimer.start();
259
     m_timeoutTimer.start();
260
     if(s == QAbstractSocket::UnconnectedState)
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
 void PTSocket::m_socketError(QAbstractSocket::SocketError s)
270
 void PTSocket::m_socketError(QAbstractSocket::SocketError s)
268
 {
271
 {
269
     if(s != QAbstractSocket::RemoteHostClosedError)
272
     if(s != QAbstractSocket::RemoteHostClosedError)
270
-    {
271
-        qDebug()<<"Socket error:"<<s;
272
         setState(Error);
273
         setState(Error);
273
-    }
274
 }
274
 }
275
 
275
 
276
 void PTSocket::setState(PTSocket::State s)
276
 void PTSocket::setState(PTSocket::State s)

+ 2
- 2
tests/Makefile View File

1
 #############################################################################
1
 #############################################################################
2
 # Makefile for building: tests
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
 # Project:  tests.pro
4
 # Project:  tests.pro
5
 # Template: app
5
 # Template: app
6
 # Command: /usr/bin/qmake -o Makefile tests.pro
6
 # Command: /usr/bin/qmake -o Makefile tests.pro
10
 
10
 
11
 CC            = gcc
11
 CC            = gcc
12
 CXX           = g++
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
 CFLAGS        = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
14
 CFLAGS        = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
15
 CXXFLAGS      = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
15
 CXXFLAGS      = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
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.
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 View File

50
                     <<TestState(1, PTSocket::Handshaked)
50
                     <<TestState(1, PTSocket::Handshaked)
51
                     <<TestState(1, PTSocket::Disconnecting)
51
                     <<TestState(1, PTSocket::Disconnecting)
52
                     <<TestState(1, PTSocket::Disconnected));
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
     m_currentState = 0;
60
     m_currentState = 0;
54
     m_currentTest = -1;
61
     m_currentTest = -1;
55
 }
62
 }
134
     sock->connectToHost("127.0.0.1", m_serv->serverPort());
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
 void Test::timeout(int i)
160
 void Test::timeout(int i)
138
 {
161
 {
139
     m_timeoutTimer.start(i);
162
     m_timeoutTimer.start(i);
167
         case 4:
190
         case 4:
168
             test5HandshakeFake2();
191
             test5HandshakeFake2();
169
             break;
192
             break;
193
+	case 5:
194
+		test6Error1();
195
+		break;
196
+	case 6:
197
+		test7Error2();
198
+		break;
170
         default:
199
         default:
171
             qApp->quit();
200
             qApp->quit();
172
         }
201
         }

+ 2
- 0
tests/test.h View File

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

Loading…
Cancel
Save