QLocalSocket/Unix: fix aborting the socket

According to the documentation, calling abort() should immediately
reset the socket to its initial state. This includes:

  - closing the file descriptor;
  - closing the QLocalSocket as an I/O device;
  - canceling a pending outgoing connection, if it exist;
  - reseting 'serverName' string.

So, adding a call to close() resets the state entirely.

Change-Id: I9c604b5187c6300b437d7aa4c2d06db03edacf21
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit d9c0af92bd893e1f6a0b4c627300ea96a73aba55)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Alex Trotsenko 2021-07-14 19:58:48 +03:00 committed by Qt Cherry-pick Bot
parent 9d07711bfd
commit bb6c9b368c
3 changed files with 8 additions and 0 deletions

View File

@ -316,6 +316,7 @@ void QLocalSocket::abort()
{
Q_D(QLocalSocket);
d->tcpSocket->abort();
close();
}
qint64 QLocalSocket::bytesAvailable() const

View File

@ -408,6 +408,7 @@ void QLocalSocket::abort()
{
Q_D(QLocalSocket);
d->unixSocket.abort();
close();
}
qint64 QLocalSocket::bytesAvailable() const

View File

@ -721,6 +721,7 @@ void tst_QLocalSocket::simpleCommandProtocol2()
server.listen(QStringLiteral("simpleProtocol"));
QLocalSocket localSocketWrite;
QSignalSpy spyDisconnected(&localSocketWrite, SIGNAL(disconnected()));
localSocketWrite.connectToServer(server.serverName());
QVERIFY(server.waitForNewConnection());
QLocalSocket* localSocketRead = server.nextPendingConnection();
@ -762,6 +763,11 @@ void tst_QLocalSocket::simpleCommandProtocol2()
}
localSocketWrite.abort();
QCOMPARE(localSocketWrite.state(), QLocalSocket::UnconnectedState);
QCOMPARE(spyDisconnected.count(), 1);
QCOMPARE(localSocketWrite.bytesToWrite(), 0);
QVERIFY(!localSocketWrite.isOpen());
QVERIFY(localSocketRead->waitForDisconnected(1000));
}