diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2018-05-08 15:04:32 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2018-05-26 19:42:34 +0000 |
commit | 5968a445e15640b6f63f150cd0c2e448051877c4 (patch) | |
tree | 9d3e5caea3a41d0639b75e2a333af62306a68c93 /src/corelib/io/qprocess_win.cpp | |
parent | 03ab94b0e7a549bcf839639438f782a47522ffa7 (diff) |
QProcess/Win: Use ConnectNamedPipe asynchronously and check return value
According to the documentation of ConnectNamedPipe we must pass an
OVERLAPPED object, because the passed handle was opened with
FILE_FLAG_OVERLAPPED.
Pass an OVERLAPPED object, and create a manual reset event that is
waited on if ConnectNamedPipe "fails" with ERROR_IO_PENDING.
Check the return type, and report any failure via qErrnoWarning.
Change-Id: Iedd702cecc2f0008eee6ed4f19d9370912190595
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qprocess_win.cpp')
-rw-r--r-- | src/corelib/io/qprocess_win.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index b1ec2c560c..2e4b5d9cef 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -149,7 +149,26 @@ static void qt_create_pipe(Q_PIPE *pipe, bool isInputPipe) } // Wait until connection is in place. - ConnectNamedPipe(hServer, NULL); + OVERLAPPED overlapped; + ZeroMemory(&overlapped, sizeof(overlapped)); + overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (ConnectNamedPipe(hServer, &overlapped) == 0) { + DWORD dwError = GetLastError(); + switch (dwError) { + case ERROR_PIPE_CONNECTED: + break; + case ERROR_IO_PENDING: + WaitForSingleObject(overlapped.hEvent, INFINITE); + break; + default: + qErrnoWarning(dwError, "QProcess: ConnectNamedPipe failed."); + CloseHandle(overlapped.hEvent); + CloseHandle(hClient); + CloseHandle(hServer); + return; + } + } + CloseHandle(overlapped.hEvent); if (isInputPipe) { pipe[0] = hClient; |