Track active transfers in wxWebSessionCURL class

At various points in a transfer being managed by the wxWebSessionCURL
class we need to perform operations on a wxWebRequestCURL object.
However it’s possible for the request object to be deleted while the
transfer is in progress.

To ensure that the request objects are valid, keep track of the request
objects with a hash map. Objects are added to the map when a transfer is
started and removed when the transfer is complete or in the request’s
destructor.
This commit is contained in:
New Pagodi
2021-02-07 00:48:02 -06:00
parent b0b53e8db3
commit 774a752bed
2 changed files with 48 additions and 9 deletions

View File

@@ -17,6 +17,7 @@
#include "wx/thread.h"
#include "wx/vector.h"
#include "wx/timer.h"
#include "wx/hashmap.h"
#include "curl/curl.h"
@@ -151,6 +152,8 @@ public:
void CancelRequest(wxWebRequestCURL* request);
void RequestHasTerminated(wxWebRequestCURL* request);
static bool CurlRuntimeAtLeastVersion(unsigned int, unsigned int,
unsigned int);
@@ -165,6 +168,11 @@ private:
void ProcessSocketPollerResult(wxThreadEvent&);
void CheckForCompletedTransfers();
WX_DECLARE_HASH_MAP(CURL*, wxWebRequestCURL*, wxPointerHash, \
wxPointerEqual, TransferSet);
TransferSet m_activeTransfers;
SocketPoller* m_socketPoller;
wxTimer m_timeoutTimer;
CURLM* m_handle;