@@ -13,12 +13,13 @@
#include "../../debug.h"
#include "../../rev.h"
#include "../network_internal.h"
#include "http.h"
#include <mutex>
#include <winhttp.h>
#include "../../safeguards.h"
static HINTERNET _winhttp_session = nullptr;
@@ -43,12 +44,13 @@ public:
bool Receive();
void WinHttpCallback(DWORD code, void *info, DWORD length);
};
static std::vector<NetworkHTTPRequest *> _http_requests;
static std::vector<NetworkHTTPRequest *> _new_http_requests;
static std::mutex _new_http_requests_mutex;
/**
* Create a new HTTP request.
*
* @param uri the URI to connect to (https://.../..).
* @param callback the callback to send data back on.
@@ -280,21 +282,26 @@ NetworkHTTPRequest::~NetworkHTTPRequest(
}
/* static */ void NetworkHTTPSocketHandler::Connect(const std::string &uri, HTTPCallback *callback, const std::string data)
{
auto request = new NetworkHTTPRequest(std::wstring(uri.begin(), uri.end()), callback, data);
request->Connect();
std::lock_guard<std::mutex> lock(_new_http_requests_mutex);
_new_http_requests.push_back(request);
/* static */ void NetworkHTTPSocketHandler::HTTPReceive()
if (!_new_http_requests.empty()) {
/* We delay adding new requests, as Receive() below can cause a callback which adds a new requests. */
_http_requests.insert(_http_requests.end(), _new_http_requests.begin(), _new_http_requests.end());
_new_http_requests.clear();
if (_http_requests.empty()) return;
for (auto it = _http_requests.begin(); it != _http_requests.end(); /* nothing */) {
NetworkHTTPRequest *cur = *it;
Status change: