diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2021-08-24 18:30:12 +0300 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2021-09-18 10:46:35 +0300 |
commit | 4e695eece7e1de874f3f8bb0a530a2ae05a0014a (patch) | |
tree | d7a92d2ace64ce126cdbd61149511bc81531b8b7 /tests/auto/network/socket | |
parent | 51e28dc54fab3caa9e2b3bea4fd7a2fb5724d7c7 (diff) |
QWindowsPipeWriter: do not clear the buffer in thread pool callback
In a blocking application, receiving the results of write operations
must be synchronized with the waitFor...() functions. But, clearing
the buffer in another thread can cause the code
localsocket.write(...);
QVERIFY(localsocket.bytesToWrite() > 0);
to fail unexpectedly, if the socket has been disconnected between
the calls.
So, defer resetting the buffer until checkForWrite() is called.
Change-Id: I8c21036aab6a4c56d02c0d9a18d4bbce52d724f4
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 | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index f537bd9157..519a7bfacb 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -132,6 +132,7 @@ private slots: void writeToClientAndDisconnect_data(); void writeToClientAndDisconnect(); + void writeToDisconnected(); void debug(); void bytesWrittenSignal(); @@ -1524,6 +1525,32 @@ void tst_QLocalSocket::writeToClientAndDisconnect() QCOMPARE(client.state(), QLocalSocket::UnconnectedState); } +void tst_QLocalSocket::writeToDisconnected() +{ + QLocalServer server; + QVERIFY(server.listen("writeToDisconnected")); + + QLocalSocket client; + client.connectToServer("writeToDisconnected"); + QVERIFY(client.waitForConnected(3000)); + QVERIFY(server.waitForNewConnection(3000)); + QLocalSocket *serverSocket = server.nextPendingConnection(); + QVERIFY(serverSocket); + serverSocket->abort(); + + QCOMPARE(client.state(), QLocalSocket::ConnectedState); + QVERIFY(client.putChar(0)); + +#ifdef Q_OS_WIN + // Ensure the asynchronous write operation is finished. + QTest::qSleep(250); +#endif + + QCOMPARE(client.bytesToWrite(), qint64(1)); + QVERIFY(!client.waitForBytesWritten()); + QCOMPARE(client.state(), QLocalSocket::UnconnectedState); +} + void tst_QLocalSocket::debug() { // Make sure this compiles |