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 <maurice.kalinowski@qt.io>
bb10
Oliver Wolff 2016-10-13 13:59:44 +02:00 committed by Oliver Wolff
parent 2c0033983b
commit 0e61323c87
1 changed files with 4 additions and 2 deletions

View File

@ -492,10 +492,12 @@ void QNativeSocketEngine::close()
ComPtr<IAsyncAction> 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;
});