summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qwindowspipereader.cpp
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2021-04-23 19:45:35 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2021-05-06 21:06:44 +0300
commitca14ed494c1b5b52960e37f3188d4b818dc67be1 (patch)
tree9c3aefdb3e558fd5c4073de86244106f2380c479 /src/corelib/io/qwindowspipereader.cpp
parent3d71c4b740d23d5c3f380f495990f35ea17dc2a0 (diff)
QLocalSocket/Win: implement duplex communication in blocking mode
[ChangeLog][QtNetwork][QLocalSocket] The waitFor*() functions on Windows now support duplex operation, as they already did on Unix. As a side effect, this restores the behavior that a single call to waitForReadyRead() won't emit both readyRead() and disconnected(), which also matches Unix behavior. The groundwork for that misbehavior was laid by incorrect refactoring in d1a671b69 already, but at this point it was harmless, as the pipe couldn't be newly closed after a successful read. That changed with f265c87e0, which made the queuing of signals async. Change-Id: I1eb80e8f147bb58825143e0fe1e4300c59ae0fbb Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/io/qwindowspipereader.cpp')
-rw-r--r--src/corelib/io/qwindowspipereader.cpp59
1 files changed, 5 insertions, 54 deletions
diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp
index 9030c3aaa1..d8e9834ea0 100644
--- a/src/corelib/io/qwindowspipereader.cpp
+++ b/src/corelib/io/qwindowspipereader.cpp
@@ -143,7 +143,7 @@ void QWindowsPipeReader::cancelAsyncRead(State newState)
// Wait for callback to complete.
do {
locker.unlock();
- waitForNotification(QDeadlineTimer(-1));
+ waitForNotification();
locker.relock();
} while (readSequenceStarted);
}
@@ -462,67 +462,18 @@ DWORD QWindowsPipeReader::checkPipeState()
return 0;
}
-bool QWindowsPipeReader::waitForNotification(const QDeadlineTimer &deadline)
+bool QWindowsPipeReader::waitForNotification()
{
+ DWORD waitRet;
do {
- DWORD waitRet = WaitForSingleObjectEx(syncHandle, deadline.remainingTime(), TRUE);
+ waitRet = WaitForSingleObjectEx(syncHandle, INFINITE, TRUE);
if (waitRet == WAIT_OBJECT_0)
return true;
- if (waitRet != WAIT_IO_COMPLETION)
- return false;
-
// Some I/O completion routine was called. Wait some more.
- } while (!deadline.hasExpired());
+ } while (waitRet == WAIT_IO_COMPLETION);
return false;
}
-/*!
- Waits for the completion of the asynchronous read operation.
- Returns \c true, if we've emitted the readyRead signal.
- */
-bool QWindowsPipeReader::waitForReadyRead(int msecs)
-{
- QDeadlineTimer timer(msecs);
-
- // Make sure that 'syncHandle' was triggered by the thread pool callback.
- while (isReadOperationActive() && waitForNotification(timer)) {
- if (consumePendingAndEmit(false))
- return true;
- }
-
- return false;
-}
-
-/*!
- Waits until the pipe is closed.
- */
-bool QWindowsPipeReader::waitForPipeClosed(int msecs)
-{
- const int sleepTime = 10;
- QDeadlineTimer timer(msecs);
-
- while (waitForReadyRead(timer.remainingTime())) {}
- if (pipeBroken)
- return true;
-
- if (timer.hasExpired())
- return false;
-
- // When the read buffer is full, the read sequence is not running,
- // so we need to peek the pipe to detect disconnection.
- forever {
- checkPipeState();
- consumePendingAndEmit(false);
- if (pipeBroken)
- return true;
-
- if (timer.hasExpired())
- return false;
-
- Sleep(sleepTime);
- }
-}
-
QT_END_NAMESPACE