Hello all,
I have implemented a socket client for my app. There is a async read interface like this:
IAsyncOperationWithProgress<IBuffer^, unsigned int>^ CSmiHttpClient::ReadAsync(IBuffer^ buffer,
unsigned int count, InputStreamOptions options)
{
m_psBuffer = buffer;
m_readCompleteEvent = task_completion_event<void>();
m_cancellationTokenSource = cancellation_token_source();
mCurReadOp = create_async([this](progress_reporter<unsigned int> progress) {
task<void> task1 = create_task(m_readCompleteEvent, m_cancellationTokenSource.get_token()).then([this, progress]{
if (is_task_cancellation_requested())
{
cancel_current_task();
return;
}
progress.report(100);
});
return m_psBuffer;
});
}
And i process async call via IAsyncOperationWithProgressCompletedHandler.
IFACEMETHODIMP CReceiveOperation::Invoke(
_In_opt_ IAsyncOperationWithProgress<IBuffer*, UINT32> *asyncInfo, AsyncStatus status )
{
if (asyncInfo == nullptr)
{
return E_POINTER;
}
ComPtr<IBuffer> spWinRtBuffer;
HRESULT hrResult = asyncInfo->GetResults(&spWinRtBuffer);
ComPtr<IMFAsyncResult> spResult;
ComPtr<IAsyncInfo> spAsyncInfo;
ComPtr<IInputStream> spInputStream;
ComPtr<IDataReader> spDataReader;
DWORD cbBufferLen = 0;
if (SUCCEEDED(hrResult))
{
hrResult = spWinRtBuffer->get_Length(&_cbRead);
}
if (SUCCEEDED(hrResult) && _cbRead == 0)
{
hrResult = MF_E_NET_READ;
}
ComPtr<IUnknown> spThisUnk;
HRESULT hr = this->QueryInterface(IID_PPV_ARGS(&spThisUnk));
if (SUCCEEDED(hr))
{
hr = MFCreateAsyncResult(spThisUnk.Get(), _spCallback.Get(), _spState.Get(), &spResult);
}
if (SUCCEEDED(hr))
{
spResult->SetStatus(hrResult);
hr = MFInvokeCallback(spResult.Get());
}
if (SUCCEEDED(asyncInfo->QueryInterface(IID_IAsyncInfo, &spAsyncInfo)))
{
spAsyncInfo->Close();
}
return hr;
}
Now i want to return some error code when network is bad, how can i set the error code for IAsyncOperationWithProgressCompletedHandler?
thanks
haha