diff options
Diffstat (limited to 'editor/debugger/editor_debugger_server.cpp')
-rw-r--r-- | editor/debugger/editor_debugger_server.cpp | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/editor/debugger/editor_debugger_server.cpp b/editor/debugger/editor_debugger_server.cpp index 8c3833af50..34904d55aa 100644 --- a/editor/debugger/editor_debugger_server.cpp +++ b/editor/debugger/editor_debugger_server.cpp @@ -41,15 +41,18 @@ class EditorDebuggerServerTCP : public EditorDebuggerServer { private: Ref<TCPServer> server; + String endpoint; public: static EditorDebuggerServer *create(const String &p_protocol); - virtual void poll() {} - virtual Error start(const String &p_uri); - virtual void stop(); - virtual bool is_active() const; - virtual bool is_connection_available() const; - virtual Ref<RemoteDebuggerPeer> take_connection(); + + virtual void poll() override {} + virtual String get_uri() const override; + virtual Error start(const String &p_uri) override; + virtual void stop() override; + virtual bool is_active() const override; + virtual bool is_connection_available() const override; + virtual Ref<RemoteDebuggerPeer> take_connection() override; EditorDebuggerServerTCP(); }; @@ -63,21 +66,42 @@ EditorDebuggerServerTCP::EditorDebuggerServerTCP() { server.instantiate(); } +String EditorDebuggerServerTCP::get_uri() const { + return endpoint; +} + Error EditorDebuggerServerTCP::start(const String &p_uri) { - int bind_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); + // Default host and port String bind_host = (String)EditorSettings::get_singleton()->get("network/debug/remote_host"); + int bind_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); + + // Optionally override if (!p_uri.is_empty() && p_uri != "tcp://") { String scheme, path; Error err = p_uri.parse_url(scheme, bind_host, bind_port, path); ERR_FAIL_COND_V(err != OK, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(!bind_host.is_valid_ip_address() && bind_host != "*", ERR_INVALID_PARAMETER); } - const Error err = server->listen(bind_port, bind_host); - if (err != OK) { - EditorNode::get_log()->add_message(String("Error listening on port ") + itos(bind_port), EditorLog::MSG_TYPE_ERROR); - return err; + + // Try listening on ports + const int max_attempts = 5; + for (int attempt = 1;; ++attempt) { + const Error err = server->listen(bind_port, bind_host); + if (err == OK) { + break; + } + if (attempt >= max_attempts) { + EditorNode::get_log()->add_message(vformat("Cannot listen on port %d, remote debugging unavailable.", bind_port), EditorLog::MSG_TYPE_ERROR); + return err; + } + int last_port = bind_port++; + EditorNode::get_log()->add_message(vformat("Cannot listen on port %d, trying %d instead.", last_port, bind_port), EditorLog::MSG_TYPE_WARNING); } - return err; + + // Endpoint that the client should connect to + endpoint = vformat("tcp://%s:%d", bind_host, bind_port); + + return OK; } void EditorDebuggerServerTCP::stop() { |