diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2021-04-01 18:28:22 +0300 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2021-04-06 11:27:41 +0300 |
commit | 72d1a54763023fa9c85556da905c34216cf5ed4b (patch) | |
tree | 608fb890d6996f2b47a2f742c125a202c5df9163 /tests/auto/network/socket/qlocalsocket | |
parent | 0e6c4224f00999d4089d7c2ac462bb5a60a14adc (diff) |
QWindowsPipeReader: determine pipe state before signaling
The 'pipeBroken' flag must be updated before emitting the readyRead()
signal to avoid deadlock of waitForReadyRead() inside slot connected
to readyRead().
Change-Id: Ie393fdd594c6691da6609ea18307589b7157c624
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'tests/auto/network/socket/qlocalsocket')
-rw-r--r-- | tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index f20f82ff88..eebbf4ef24 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -111,6 +111,7 @@ private slots: void longPath(); void waitForDisconnect(); void waitForDisconnectByServer(); + void waitForReadyReadOnDisconnected(); void removeServer(); @@ -1151,6 +1152,40 @@ void tst_QLocalSocket::waitForDisconnectByServer() QCOMPARE(spy.count(), 1); } +void tst_QLocalSocket::waitForReadyReadOnDisconnected() +{ + QString name = "tst_localsocket"; + LocalServer server; + QVERIFY(server.listen(name)); + LocalSocket socket; + connect(&socket, &QLocalSocket::readyRead, [&socket]() { + QVERIFY(socket.getChar(nullptr)); + // The next call should not block because the socket was closed + // by the peer. + QVERIFY(!socket.waitForReadyRead(3000)); + }); + + socket.connectToServer(name); + QVERIFY(socket.waitForConnected(3000)); + QVERIFY(server.waitForNewConnection(3000)); + QLocalSocket *serverSocket = server.nextPendingConnection(); + QVERIFY(serverSocket); + QVERIFY(serverSocket->putChar(0)); + QVERIFY(serverSocket->waitForBytesWritten(3000)); + serverSocket->close(); + +#ifdef Q_OS_WIN + // Ensure that the asynchronously delivered close notification is + // already queued up before we consume the data. + QTest::qSleep(250); +#endif + + QElapsedTimer timer; + timer.start(); + QVERIFY(socket.waitForReadyRead(5000)); + QVERIFY(timer.elapsed() < 2000); +} + void tst_QLocalSocket::removeServer() { // this is a hostile takeover, but recovering from a crash results in the same |