static */
| 301 | } |
| 302 | |
| 303 | /* static */ void NetworkHTTPSocketHandler::HTTPReceive() |
| 304 | { |
| 305 | /* Process all callbacks. */ |
| 306 | { |
| 307 | std::lock_guard<std::mutex> lock(_http_callback_mutex); |
| 308 | |
| 309 | { |
| 310 | std::lock_guard<std::mutex> lock(_new_http_callback_mutex); |
| 311 | if (!_new_http_callbacks.empty()) { |
| 312 | /* We delay adding new callbacks, as HandleQueue() below might add a new callback. */ |
| 313 | _http_callbacks.insert(_http_callbacks.end(), _new_http_callbacks.begin(), _new_http_callbacks.end()); |
| 314 | _new_http_callbacks.clear(); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | for (auto &callback : _http_callbacks) { |
| 319 | callback->HandleQueue(); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /* Process all requests. */ |
| 324 | { |
| 325 | std::lock_guard<std::mutex> lock(_new_http_requests_mutex); |
| 326 | if (!_new_http_requests.empty()) { |
| 327 | /* We delay adding new requests, as Receive() below can cause a callback which adds a new requests. */ |
| 328 | _http_requests.insert(_http_requests.end(), _new_http_requests.begin(), _new_http_requests.end()); |
| 329 | _new_http_requests.clear(); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | if (_http_requests.empty()) return; |
| 334 | |
| 335 | for (auto it = _http_requests.begin(); it != _http_requests.end(); /* nothing */) { |
| 336 | NetworkHTTPRequest *cur = *it; |
| 337 | |
| 338 | if (cur->Receive()) { |
| 339 | it = _http_requests.erase(it); |
| 340 | delete cur; |
| 341 | continue; |
| 342 | } |
| 343 | |
| 344 | ++it; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | void NetworkHTTPInitialize() |
| 349 | { |