QLocalSocket/Win: do not close the device on disconnectFromServer()

It's the user's privilege to do so when they want to finish reading the
QIODevice. Moreover, this is the only difference between close() and
disconnectFromServer().

[ChangeLog][QtNetwork][Important Behavior Changes] The Windows
implementation of QLocalSocket::disconnectFromServer() no longer calls
close(), which is consistent with the behavior on Unix.

Change-Id: Ie9ce20c60259a2b08f5254b719355bd7be9b17cd
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
This commit is contained in:
Alex Trotsenko 2021-07-23 20:01:29 +03:00
parent 6481733d45
commit f18d8fd1fb
3 changed files with 8 additions and 9 deletions

View File

@ -337,6 +337,8 @@ void QLocalSocketPrivate::_q_pipeClosed()
return;
}
serverName.clear();
fullServerName.clear();
pipeReader->stop();
delete pipeWriter;
pipeWriter = nullptr;
@ -403,11 +405,11 @@ void QLocalSocket::disconnectFromServer()
{
Q_D(QLocalSocket);
if (bytesToWrite() != 0) {
if (bytesToWrite() == 0) {
d->_q_pipeClosed();
} else if (d->state != QLocalSocket::ClosingState) {
d->state = QLocalSocket::ClosingState;
emit stateChanged(d->state);
} else {
close();
}
}
@ -444,8 +446,8 @@ void QLocalSocketPrivate::_q_bytesWritten(qint64 bytes)
QScopedValueRollback<bool> guard(emittedBytesWritten, true);
emit q->bytesWritten(bytes);
}
if (state == QLocalSocket::ClosingState && pipeWriterBytesToWrite() == 0)
q->close();
if (state == QLocalSocket::ClosingState)
q->disconnectFromServer();
}
qintptr QLocalSocket::socketDescriptor() const

View File

@ -4604,10 +4604,6 @@ void tst_QNetworkReply::ioPutToFileFromLocalSocket()
QNetworkReplyPtr reply(manager.put(QNetworkRequest(url), passive));
passive->setParent(reply.data());
#ifdef Q_OS_WIN
if (!data.isEmpty())
QEXPECT_FAIL("", "QTBUG-18385", Abort);
#endif
QVERIFY2(waitForFinish(reply) == Success, msgWaitForFinished(reply));
QCOMPARE(reply->error(), QNetworkReply::NoError);

View File

@ -1369,6 +1369,7 @@ void tst_QLocalSocket::delayedDisconnect()
QCOMPARE(socket.state(), QLocalSocket::ClosingState);
QVERIFY(socket.waitForDisconnected(3000));
QCOMPARE(socket.state(), QLocalSocket::UnconnectedState);
QVERIFY(socket.isOpen());
}
void tst_QLocalSocket::removeServer()