Make sure wxEVT_WEBREQUEST_DATA is processed in the main thread

This event was processed in a worker thread, which was different from
all the other events and also almost surely not thread-safe, so change
this and queue it for processing in the main thread instead.

Use wxMemoryBuffer instead of non-owning pointer in wxWebRequestEvent
and reset the buffer used internally every time to ensure the data is
still available by the time the event is processed.

Also increase the amount of data downloaded in the "advanced" page of
the sample as it has to be greater than wxWEBREQUEST_BUFFER_SIZE, which
is currently 64KiB, to have a chance of seeing the value actually
change, otherwise all the data arrives in a single event. As it is,
using the maximal size supported by the httpbin service, we only get 2
events.
This commit is contained in:
Vadim Zeitlin
2021-01-16 23:48:15 +01:00
parent 4c19572d9d
commit 970ab0a1ae
3 changed files with 24 additions and 19 deletions

View File

@@ -364,22 +364,19 @@ public:
void OnRequestData(wxWebRequestEvent& evt)
{
// Count zero bytes in data buffer
bool notify = false;
const char* p = (const char*) evt.GetDataBuffer();
for ( size_t i = 0; i < evt.GetDataSize(); i++ )
{
if ( *p == 0 )
{
m_advCount++;
notify = true;
}
p++;
}
if ( notify )
CallAfter(&WebRequestFrame::UpdateAdvCount);
UpdateAdvCount();
// Make sure the new text is immediately visible.
m_advCountStaticText->Update();
}
void UpdateAdvCount()
@@ -425,7 +422,7 @@ public:
defaultURL = "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.7z";
break;
case Page_Advanced:
defaultURL = "https://httpbin.org/bytes/64000";
defaultURL = "https://httpbin.org/bytes/100000";
break;
}
m_urlTextCtrl->SetValue(defaultURL);