summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeon Krause <lk@leonkrause.com>2018-02-17 17:42:58 +0100
committerLeon Krause <lk@leonkrause.com>2018-02-17 18:12:50 +0100
commitca9fa9cca8a27f14a7b0178d6abf573815722996 (patch)
tree0ffcd4f9f291f8be91fc0a69e97264b3780c26ce
parent2cd7bc04ea9a99510c26113a81f8371be5b1f49f (diff)
Warn when polling HTTPClient synchronously in HTML5 platform
-rw-r--r--platform/javascript/http_client.h.inc5
-rw-r--r--platform/javascript/http_client_javascript.cpp19
2 files changed, 24 insertions, 0 deletions
diff --git a/platform/javascript/http_client.h.inc b/platform/javascript/http_client.h.inc
index 23a74e68f5..d75d33a33a 100644
--- a/platform/javascript/http_client.h.inc
+++ b/platform/javascript/http_client.h.inc
@@ -46,3 +46,8 @@ String password;
int polled_response_code;
String polled_response_header;
PoolByteArray polled_response;
+
+#ifdef DEBUG_ENABLED
+bool has_polled;
+uint64_t last_polling_frame;
+#endif
diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp
index 5ab3d1b770..939a8d11f2 100644
--- a/platform/javascript/http_client_javascript.cpp
+++ b/platform/javascript/http_client_javascript.cpp
@@ -240,6 +240,21 @@ Error HTTPClient::poll() {
return ERR_CONNECTION_ERROR;
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);
if (godot_xhr_get_ready_state(xhr_id) != XHR_READY_STATE_DONE) {
return OK;
@@ -280,6 +295,10 @@ HTTPClient::HTTPClient() {
port = -1;
use_tls = false;
polled_response_code = 0;
+#ifdef DEBUG_ENABLED
+ has_polled = false;
+ last_polling_frame = 0;
+#endif
}
HTTPClient::~HTTPClient() {