From 49a9c50ea8b7cbe92684a707f985792b06d17f1e Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Sat, 29 Sep 2012 18:37:56 +0200 Subject: [PATCH] QWindowsPipeReader: use CancelIoEx on Windows >= Vista This cancels only the I/O operation of the reader and not all operations on the handle. Change-Id: Ie442199534cf45e58bb2e053da9fecee961a460e Reviewed-by: Friedemann Kleint --- src/corelib/io/qwindowspipereader.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp index 8a06a7ba21..cca6e80810 100644 --- a/src/corelib/io/qwindowspipereader.cpp +++ b/src/corelib/io/qwindowspipereader.cpp @@ -64,10 +64,25 @@ QWindowsPipeReader::QWindowsPipeReader(QObject *parent) connect(dataReadNotifier, &QWinOverlappedIoNotifier::notified, this, &QWindowsPipeReader::notified); } +static void qt_cancelIo(HANDLE handle, OVERLAPPED *overlapped) +{ + typedef BOOL (WINAPI *PtrCancelIoEx)(HANDLE, LPOVERLAPPED); + static PtrCancelIoEx ptrCancelIoEx = 0; + if (!ptrCancelIoEx) { + HMODULE kernel32 = GetModuleHandleA("kernel32"); + if (kernel32) + ptrCancelIoEx = PtrCancelIoEx(GetProcAddress(kernel32, "CancelIoEx")); + } + if (ptrCancelIoEx) + ptrCancelIoEx(handle, overlapped); + else + CancelIo(handle); +} + QWindowsPipeReader::~QWindowsPipeReader() { if (readSequenceStarted) { - CancelIo(handle); + qt_cancelIo(handle, &overlapped); dataReadNotifier->waitForNotified(-1, &overlapped); } }