From 5968a445e15640b6f63f150cd0c2e448051877c4 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 8 May 2018 15:04:32 +0200 Subject: 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 Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- src/corelib/io/qprocess_win.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/corelib/io/qprocess_win.cpp') 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; -- cgit v1.2.3