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>
bb10
Joerg Bornemann 2018-05-08 15:04:32 +02:00
parent 03ab94b0e7
commit 5968a445e1
1 changed files with 20 additions and 1 deletions

View File

@ -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;