From 0e61323c87490ea3991f7b6211034285ce5a932f Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 13 Oct 2016 13:59:44 +0200 Subject: [PATCH] winrt: Added timeout for cancellation of socket read operation As the function runs on the XAML thread it can make the app unresponsive/wait forever on a socket close. Thus we should not wait forever but have a timeout. If the timeout is hit the socket is not closed properly but hard reset. Change-Id: I82e9425c0f8195e3465027fdc2417a93f1c1ad91 Reviewed-by: Maurice Kalinowski --- src/network/socket/qnativesocketengine_winrt.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/network/socket/qnativesocketengine_winrt.cpp b/src/network/socket/qnativesocketengine_winrt.cpp index 58f0668854..b6a739d1b8 100644 --- a/src/network/socket/qnativesocketengine_winrt.cpp +++ b/src/network/socket/qnativesocketengine_winrt.cpp @@ -492,10 +492,12 @@ void QNativeSocketEngine::close() ComPtr action; hr = socket3->CancelIOAsync(&action); Q_ASSERT_SUCCEEDED(hr); - hr = QWinRTFunctions::await(action); + hr = QWinRTFunctions::await(action, QWinRTFunctions::YieldThread, 5000); // If there is no pending IO (no read established before) the function will fail with // "function was called at an unexpected time" which is fine. - if (hr != E_ILLEGAL_METHOD_CALL) + // Timeout is fine as well. The result will be the socket being hard reset instead of + // being closed gracefully + if (hr != E_ILLEGAL_METHOD_CALL && hr != ERROR_TIMEOUT) Q_ASSERT_SUCCEEDED(hr); return S_OK; });