summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-06-14 18:25:15 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-06-14 18:25:15 (GMT)
commit47249ef4ccf8014f5252a37252fc76a326e7818c (patch)
tree1b60bd41248fed507eee02384c0e5b9343679131
parent7aa5b113f9fe39a24a80b5462d64b02e77ed20e7 (diff)
parentd61a1fecde3d4a5b34a849ae852a498e6bb1c2de (diff)
downloadQt-47249ef4ccf8014f5252a37252fc76a326e7818c.zip
Qt-47249ef4ccf8014f5252a37252fc76a326e7818c.tar.gz
Qt-47249ef4ccf8014f5252a37252fc76a326e7818c.tar.bz2
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.6-integration
* '4.6' of scm.dev.nokia.troll.no:qt/oslo-staging-1: beautify tst_QLocalSocket::writeToClientAndDisconnect QLocalSocket/Win: check for broken pipe in waitForReadyRead QLocalSocket/Win: call close on async connection loss
-rw-r--r--src/network/socket/qlocalsocket_win.cpp13
-rw-r--r--tests/auto/qlocalsocket/tst_qlocalsocket.cpp49
2 files changed, 52 insertions, 10 deletions
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp
index 2223ebe..5486f47 100644
--- a/src/network/socket/qlocalsocket_win.cpp
+++ b/src/network/socket/qlocalsocket_win.cpp
@@ -485,6 +485,8 @@ void QLocalSocketPrivate::_q_notified()
if (!completeAsyncRead()) {
pipeClosed = true;
emit q->readChannelFinished();
+ if (actualReadBufferSize == 0)
+ QTimer::singleShot(0, q, SLOT(_q_pipeClosed()));
return;
}
startAsyncRead();
@@ -568,11 +570,22 @@ bool QLocalSocket::waitForReadyRead(int msecs)
if (d->state != QLocalSocket::ConnectedState)
return false;
+ // We already know that the pipe is gone, but did not enter the event loop yet.
+ if (d->pipeClosed) {
+ close();
+ return false;
+ }
+
Q_ASSERT(d->readSequenceStarted);
DWORD result = WaitForSingleObject(d->overlapped.hEvent, msecs == -1 ? INFINITE : msecs);
switch (result) {
case WAIT_OBJECT_0:
d->_q_notified();
+ // We just noticed that the pipe is gone.
+ if (d->pipeClosed) {
+ close();
+ return false;
+ }
return true;
case WAIT_TIMEOUT:
return false;
diff --git a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
index d2cba6e..9c09917 100644
--- a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
+++ b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
@@ -115,7 +115,8 @@ private slots:
void writeToClientAndDisconnect();
void debug();
void bytesWrittenSignal();
-
+ void syncDisconnectNotify();
+ void asyncDisconnectNotify();
#ifdef Q_OS_SYMBIAN
private:
@@ -996,16 +997,9 @@ void tst_QLocalSocket::writeToClientAndDisconnect()
clientSocket->close();
server.close();
- // Wait for the client to notice the broken connection.
- int timeout = 5000;
- do {
- const int timestep = 100;
- QTest::qWait(timestep);
- timeout -= timestep;
- } while (!readChannelFinishedSpy.count() && timeout > 0);
-
- QCOMPARE(readChannelFinishedSpy.count(), 1);
+ QTRY_COMPARE(readChannelFinishedSpy.count(), 1);
QCOMPARE(client.read(buffer, sizeof(buffer)), (qint64)sizeof(buffer));
+ client.waitForDisconnected();
QCOMPARE(client.state(), QLocalSocket::UnconnectedState);
}
@@ -1061,6 +1055,41 @@ void tst_QLocalSocket::bytesWrittenSignal()
QVERIFY(writeThread.wait(2000));
}
+void tst_QLocalSocket::syncDisconnectNotify()
+{
+#ifdef Q_OS_SYMBIAN
+ unlink("syncDisconnectNotify");
+#endif
+
+ QLocalServer server;
+ QVERIFY(server.listen("syncDisconnectNotify"));
+ QLocalSocket client;
+ client.connectToServer("syncDisconnectNotify");
+ QVERIFY(server.waitForNewConnection());
+ QLocalSocket* serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ delete serverSocket;
+ QCOMPARE(client.waitForReadyRead(), false);
+}
+
+void tst_QLocalSocket::asyncDisconnectNotify()
+{
+#ifdef Q_OS_SYMBIAN
+ unlink("asyncDisconnectNotify");
+#endif
+
+ QLocalServer server;
+ QVERIFY(server.listen("asyncDisconnectNotify"));
+ QLocalSocket client;
+ QSignalSpy disconnectedSpy(&client, SIGNAL(disconnected()));
+ client.connectToServer("asyncDisconnectNotify");
+ QVERIFY(server.waitForNewConnection());
+ QLocalSocket* serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ delete serverSocket;
+ QTRY_VERIFY(!disconnectedSpy.isEmpty());
+}
+
#ifdef Q_OS_SYMBIAN
void tst_QLocalSocket::unlink(QString name)
{