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. Pick-to: 6.1 6.2 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>
This commit is contained in:
parent
a7da8e0dab
commit
d9c0af92bd
@ -326,6 +326,7 @@ void QLocalSocket::abort()
|
||||
{
|
||||
Q_D(QLocalSocket);
|
||||
d->tcpSocket->abort();
|
||||
close();
|
||||
}
|
||||
|
||||
qint64 QLocalSocket::bytesAvailable() const
|
||||
|
@ -508,6 +508,7 @@ void QLocalSocket::abort()
|
||||
{
|
||||
Q_D(QLocalSocket);
|
||||
d->unixSocket.abort();
|
||||
close();
|
||||
}
|
||||
|
||||
qint64 QLocalSocket::bytesAvailable() const
|
||||
|
@ -969,6 +969,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();
|
||||
@ -1010,6 +1011,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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user