diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2021-07-12 17:36:39 +0300 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2021-07-14 20:48:54 +0300 |
commit | 6c1bc7798bec6bc48439b297e55d14a9da0a3673 (patch) | |
tree | 5306df8fe590c75c44a3344c5ce624f89d7eedcf /tests/auto/network/socket | |
parent | de58fa3038da8457490bcb2f160701f3bbb2d9be (diff) |
QLocalSocket/Win: destroy the pipe before emitting final signals
Both readChannelFinished() and disconnected() signals should be emitted
after closing the pipe. Otherwise, these signals do not correspond to
the state of the socket and may even be resent, if a slot connected to
one of these signals processes events.
[ChangeLog][QtNetwork][Important Behavior Changes] QLocalSocket on
Windows now emits both readChannelFinished() and disconnected() signals
after closing the pipe and emitting stateChanged(UnconnectedState),
which is consistent with the behavior on Unix.
Pick-to: 6.2
Change-Id: I1cc551b7897fdba3cec1fd6705f5396790818c7d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/network/socket')
-rw-r--r-- | tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index cec783985d..8c5fff8aad 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -144,6 +144,9 @@ private slots: void verifyListenWithDescriptor_data(); void serverBindingsAndProperties(); + +protected slots: + void socketClosedSlot(); }; tst_QLocalSocket::tst_QLocalSocket() @@ -1543,11 +1546,23 @@ void tst_QLocalSocket::bytesWrittenSignal() QVERIFY(writeThread.wait(2000)); } +void tst_QLocalSocket::socketClosedSlot() +{ + QLocalSocket *socket = qobject_cast<QLocalSocket *>(sender()); + + QCOMPARE(socket->state(), QLocalSocket::UnconnectedState); +} + void tst_QLocalSocket::syncDisconnectNotify() { QLocalServer server; QVERIFY(server.listen("syncDisconnectNotify")); QLocalSocket client; + connect(&client, &QLocalSocket::disconnected, + this, &tst_QLocalSocket::socketClosedSlot); + connect(&client, &QIODevice::readChannelFinished, + this, &tst_QLocalSocket::socketClosedSlot); + client.connectToServer("syncDisconnectNotify"); QVERIFY(server.waitForNewConnection()); QLocalSocket* serverSocket = server.nextPendingConnection(); @@ -1563,12 +1578,19 @@ void tst_QLocalSocket::asyncDisconnectNotify() QVERIFY(server.listen("asyncDisconnectNotify")); QLocalSocket client; QSignalSpy disconnectedSpy(&client, SIGNAL(disconnected())); + QSignalSpy readChannelFinishedSpy(&client, SIGNAL(readChannelFinished())); + connect(&client, &QLocalSocket::disconnected, + this, &tst_QLocalSocket::socketClosedSlot); + connect(&client, &QIODevice::readChannelFinished, + this, &tst_QLocalSocket::socketClosedSlot); + client.connectToServer("asyncDisconnectNotify"); QVERIFY(server.waitForNewConnection()); QLocalSocket* serverSocket = server.nextPendingConnection(); QVERIFY(serverSocket); delete serverSocket; QTRY_VERIFY(!disconnectedSpy.isEmpty()); + QCOMPARE(readChannelFinishedSpy.count(), 1); } void tst_QLocalSocket::verifySocketOptions_data() |