QLocalSocket: call abort() instead of close() on destruction

The QLocalSocket destructor should immediately close the connection
and destroy the socket, clearing any pending data in the write buffer.

The abort() call ensures that the pipe is destroyed on Windows, making
the additional call to destroyPipeHandles() from the private destructor
unnecessary.

Change-Id: Ic7a0d8cf2779cd933cded864c8bab0d096469499
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
This commit is contained in:
Alex Trotsenko 2021-07-22 12:00:19 +03:00
parent 3221c8dbbe
commit 594948a07b
3 changed files with 9 additions and 13 deletions

View File

@ -397,7 +397,7 @@ QLocalSocket::QLocalSocket(QObject * parent)
*/
QLocalSocket::~QLocalSocket()
{
QLocalSocket::close();
abort();
#if !defined(Q_OS_WIN) && !defined(QT_LOCALSOCKET_TCP)
Q_D(QLocalSocket);
d->unixSocket.setParent(nullptr);

View File

@ -132,7 +132,6 @@ public:
void _q_errorOccurred(QAbstractSocket::SocketError newError);
#elif defined(Q_OS_WIN)
~QLocalSocketPrivate();
void destroyPipeHandles();
qint64 pipeWriterBytesToWrite() const;
void _q_canRead();
void _q_bytesWritten(qint64 bytes);

View File

@ -161,15 +161,9 @@ QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(),
QLocalSocketPrivate::~QLocalSocketPrivate()
{
destroyPipeHandles();
}
void QLocalSocketPrivate::destroyPipeHandles()
{
if (handle != INVALID_HANDLE_VALUE) {
DisconnectNamedPipe(handle);
CloseHandle(handle);
}
Q_ASSERT(state == QLocalSocket::UnconnectedState);
Q_ASSERT(handle == INVALID_HANDLE_VALUE);
Q_ASSERT(pipeWriter == nullptr);
}
void QLocalSocket::connectToServer(OpenMode openMode)
@ -346,8 +340,11 @@ void QLocalSocketPrivate::_q_pipeClosed()
pipeReader->stop();
delete pipeWriter;
pipeWriter = nullptr;
destroyPipeHandles();
if (handle != INVALID_HANDLE_VALUE) {
DisconnectNamedPipe(handle);
CloseHandle(handle);
handle = INVALID_HANDLE_VALUE;
}
state = QLocalSocket::UnconnectedState;
emit q->stateChanged(state);