summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qwindowspipereader.cpp
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2021-10-02 18:10:20 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2021-10-06 10:16:14 +0300
commit82b86960c051de99fca7c4dfa7af2c914937f5c8 (patch)
treef5a47aa78d39a229e083269c07b52173e194ec0a /src/corelib/io/qwindowspipereader.cpp
parentb689d8dccd3c260e88116285b7b75e827ca9954b (diff)
QLocalSocket/Win: stop reading in close()
After calling close(), the socket can enter 'Closing' state, in which we try to write buffered data before disconnecting. As the device is already closed, we must disable any pipe reader activity and clear the read buffer. Change-Id: I8994df32bf324325d54dd36cbe1a1ee3f08022d1 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/io/qwindowspipereader.cpp')
-rw-r--r--src/corelib/io/qwindowspipereader.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp
index 5415ad7830..4435a47cab 100644
--- a/src/corelib/io/qwindowspipereader.cpp
+++ b/src/corelib/io/qwindowspipereader.cpp
@@ -104,6 +104,7 @@ void QWindowsPipeReader::setHandle(HANDLE hPipeReadEnd)
void QWindowsPipeReader::stop()
{
cancelAsyncRead(Stopped);
+ pipeBroken = true;
}
/*!
@@ -113,6 +114,22 @@ void QWindowsPipeReader::stop()
void QWindowsPipeReader::drainAndStop()
{
cancelAsyncRead(Draining);
+ pipeBroken = true;
+}
+
+/*!
+ Stops the asynchronous read sequence.
+ Clears the internal buffer and discards any pending data.
+ */
+void QWindowsPipeReader::stopAndClear()
+{
+ cancelAsyncRead(Stopped);
+ readBuffer.clear();
+ actualReadBufferSize = 0;
+ // QLocalSocket is supposed to write data in the 'Closing'
+ // state, so we don't set 'pipeBroken' flag here. Also, avoid
+ // setting this flag in checkForReadyRead().
+ lastError = ERROR_SUCCESS;
}
/*!
@@ -120,7 +137,6 @@ void QWindowsPipeReader::drainAndStop()
*/
void QWindowsPipeReader::cancelAsyncRead(State newState)
{
- pipeBroken = true;
if (state != Running)
return;
@@ -147,9 +163,9 @@ void QWindowsPipeReader::cancelAsyncRead(State newState)
}
mutex.unlock();
- // Because pipeBroken was set earlier, finish reading to keep the class
- // state consistent. Note that signals are not emitted in the call
- // below, as the caller is expected to do that synchronously.
+ // Finish reading to keep the class state consistent. Note that
+ // signals are not emitted in the call below, as the caller is
+ // expected to do that synchronously.
consumePending();
}