Warn when polling HTTPClient synchronously in HTML5 platform

(cherry picked from commit ca9fa9cca8)
This commit is contained in:
Leon Krause 2018-02-17 17:42:58 +01:00 committed by Hein-Pieter van Braam
parent 5bb269d01d
commit c5b5fd61d4
2 changed files with 24 additions and 0 deletions

View File

@ -46,3 +46,8 @@ String password;
int polled_response_code; int polled_response_code;
String polled_response_header; String polled_response_header;
PoolByteArray polled_response; PoolByteArray polled_response;
#ifdef DEBUG_ENABLED
bool has_polled;
uint64_t last_polling_frame;
#endif

View File

@ -240,6 +240,21 @@ Error HTTPClient::poll() {
return ERR_CONNECTION_ERROR; return ERR_CONNECTION_ERROR;
case STATUS_REQUESTING: case STATUS_REQUESTING:
#ifdef DEBUG_ENABLED
if (!has_polled) {
has_polled = true;
} else {
// forcing synchronous requests is not possible on the web
if (last_polling_frame == Engine::get_singleton()->get_idle_frames()) {
WARN_PRINT("HTTPClient polled multiple times in one frame, "
"but request cannot progress more than once per "
"frame on the HTML5 platform.");
}
}
last_polling_frame = Engine::get_singleton()->get_idle_frames();
#endif
polled_response_code = godot_xhr_get_status(xhr_id); polled_response_code = godot_xhr_get_status(xhr_id);
if (godot_xhr_get_ready_state(xhr_id) != XHR_READY_STATE_DONE) { if (godot_xhr_get_ready_state(xhr_id) != XHR_READY_STATE_DONE) {
return OK; return OK;
@ -280,6 +295,10 @@ HTTPClient::HTTPClient() {
port = -1; port = -1;
use_tls = false; use_tls = false;
polled_response_code = 0; polled_response_code = 0;
#ifdef DEBUG_ENABLED
has_polled = false;
last_polling_frame = 0;
#endif
} }
HTTPClient::~HTTPClient() { HTTPClient::~HTTPClient() {