diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2021-07-22 16:55:47 +0300 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2021-07-24 16:55:43 +0300 |
commit | 6481733d45805ecbe22a0806923ee2e0894ecc28 (patch) | |
tree | ca88956618c45ab3ba43c3005cdbd22e9b888671 /tests/auto/network/socket | |
parent | 594948a07b8086c96ba720e92473c6175d4ac918 (diff) |
QLocalSocket/Win: do not flush the pipe in disconnectFromServer()
In the case where we have pending data to write, calling flush() here
may cause the device to close immediately, if the pipe writer already
got a result of the last operation from the thread pool. In this
scenario, the device does not enter the 'Closing' state, which leads
the following code to unexpectedly fail on Windows
socket.write(...);
socket.disconnectFromServer();
QVERIFY(socket.waitForDisconnected());
Removing the call to flush() makes the behavior consistent with the
implementation on Unix.
Change-Id: Ic31fbc999be979c1e5befa8f132d9fb367f472ca
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'tests/auto/network/socket')
-rw-r--r-- | tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index 165221bd42..74132416b7 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -120,6 +120,7 @@ private slots: void waitForDisconnect(); void waitForDisconnectByServer(); void waitForReadyReadOnDisconnected(); + void delayedDisconnect(); void removeServer(); @@ -1352,6 +1353,24 @@ void tst_QLocalSocket::waitForReadyReadOnDisconnected() QVERIFY(timer.elapsed() < 2000); } +void tst_QLocalSocket::delayedDisconnect() +{ + QString name = "tst_localsocket"; + LocalServer server; + QVERIFY(server.listen(name)); + LocalSocket socket; + socket.connectToServer(name); + QVERIFY(socket.waitForConnected(3000)); + QVERIFY(server.waitForNewConnection(3000)); + QLocalSocket *serverSocket = server.nextPendingConnection(); + QVERIFY(serverSocket); + QVERIFY(socket.putChar(0)); + socket.disconnectFromServer(); + QCOMPARE(socket.state(), QLocalSocket::ClosingState); + QVERIFY(socket.waitForDisconnected(3000)); + QCOMPARE(socket.state(), QLocalSocket::UnconnectedState); +} + void tst_QLocalSocket::removeServer() { // this is a hostile takeover, but recovering from a crash results in the same |