Implement wxWebRequestCURL::Cancel()

This commit is contained in:
Tobias Taschner
2018-11-05 22:12:41 +01:00
parent fe4a5343f7
commit d2420a064c
2 changed files with 28 additions and 2 deletions

View File

@@ -243,7 +243,7 @@ bool wxWebRequestCURL::StartRequest()
void wxWebRequestCURL::Cancel()
{
wxFAIL_MSG("not implemented");
static_cast<wxWebSessionCURL&>(GetSession()).CancelRequest(this);
}
void wxWebRequestCURL::HandleCompletion()
@@ -393,6 +393,18 @@ wxThread::ExitCode wxWebSessionCURL::Entry()
while ( activeRequests )
{
// Handle cancelled requests
{
wxMutexLocker lock(m_cancelledMutex);
while ( !m_cancelledRequests.empty() )
{
wxObjectDataPtr<wxWebRequestCURL> request(m_cancelledRequests.back());
m_cancelledRequests.pop_back();
curl_multi_remove_handle(m_handle, request->GetHandle());
request->SetState(wxWebRequest::State_Cancelled);
}
}
// Instruct CURL to work on requests
curl_multi_perform(m_handle, &activeRequests);
@@ -413,7 +425,7 @@ wxThread::ExitCode wxWebSessionCURL::Entry()
{
// Wait for CURL work to finish
int numfds;
curl_multi_wait(m_handle, NULL, 0, 1000, &numfds);
curl_multi_wait(m_handle, NULL, 0, 500, &numfds);
if ( !numfds )
{
@@ -458,6 +470,15 @@ bool wxWebSessionCURL::StartRequest(wxWebRequestCURL & request)
return true;
}
void wxWebSessionCURL::CancelRequest(wxWebRequestCURL* request)
{
// Add the request to a list of threads that will be removed from the curl
// multi handle in the worker thread
wxMutexLocker lock(m_cancelledMutex);
request->IncRef();
m_cancelledRequests.push_back(wxObjectDataPtr<wxWebRequestCURL>(request));
}
// static
void wxWebSessionCURL::InitializeCURL()
{