From 24411e9743735d6323f1d3686f8b989a5122f83b Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 23 Mar 2016 15:45:12 +0100 Subject: Add a write buffer to QLocalSocket/Win Commit 0307c008 removed the buffering of data-to-be-written from QWindowsPipeWriter, because it was assumed that users of this class (QProcess and QLocalSocket) already buffer data internally. This assumption was wrong for QLocalSocket. The following sequence localSocket->write(someData); localSocket->write(someMoreData); would not write anything on the second write. Add a write buffer to the Windows implementation of QLocalSocket. Task-number: QTBUG-52073 Change-Id: I6d0f03a722ec48138cbde3e2f69aae7dafe790d3 Reviewed-by: Oswald Buddenhagen --- .../network/socket/qlocalsocket/tst_qlocalsocket.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index d12a6b53c3..bfe43673d2 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -102,7 +102,10 @@ private slots: void multiConnect(); void writeOnlySocket(); + + void writeToClientAndDisconnect_data(); void writeToClientAndDisconnect(); + void debug(); void bytesWrittenSignal(); void syncDisconnectNotify(); @@ -1034,8 +1037,16 @@ void tst_QLocalSocket::writeOnlySocket() QCOMPARE(client.state(), QLocalSocket::ConnectedState); } +void tst_QLocalSocket::writeToClientAndDisconnect_data() +{ + QTest::addColumn("chunks"); + QTest::newRow("one chunk") << 1; + QTest::newRow("several chunks") << 20; +} + void tst_QLocalSocket::writeToClientAndDisconnect() { + QFETCH(int, chunks); QLocalServer server; QLocalSocket client; QSignalSpy readChannelFinishedSpy(&client, SIGNAL(readChannelFinished())); @@ -1049,14 +1060,17 @@ void tst_QLocalSocket::writeToClientAndDisconnect() char buffer[100]; memset(buffer, 0, sizeof(buffer)); - QCOMPARE(clientSocket->write(buffer, sizeof(buffer)), (qint64)sizeof(buffer)); - clientSocket->waitForBytesWritten(); + for (int i = 0; i < chunks; ++i) + QCOMPARE(clientSocket->write(buffer, sizeof(buffer)), qint64(sizeof(buffer))); + while (clientSocket->bytesToWrite()) + QVERIFY(clientSocket->waitForBytesWritten()); clientSocket->close(); server.close(); client.waitForDisconnected(); QCOMPARE(readChannelFinishedSpy.count(), 1); - QCOMPARE(client.read(buffer, sizeof(buffer)), (qint64)sizeof(buffer)); + const QByteArray received = client.readAll(); + QCOMPARE(received.size(), qint64(sizeof(buffer) * chunks)); QCOMPARE(client.state(), QLocalSocket::UnconnectedState); } -- cgit v1.2.3