Auto-Increment Debugger Port

Note: This PR also changes the port of the GDScript Language Server from 6008 to 6005. This opens enough ports above the debug port (6007) for this change to be useful.
This commit is contained in:
Nathan Franke 2021-09-29 21:06:28 -05:00
parent 2a9dd654bc
commit de7873c2d8
No known key found for this signature in database
GPG key ID: 92164DCCF3B1F723
10 changed files with 106 additions and 48 deletions

View file

@ -45,7 +45,7 @@ class GDScriptLanguageServer : public EditorPlugin {
bool started = false;
bool use_thread = false;
String host = "127.0.0.1";
int port = 6008;
int port = 6005;
static void thread_main(void *p_userdata);
private:

View file

@ -31,6 +31,8 @@
#include "editor_debugger_server_websocket.h"
#include "core/config/project_settings.h"
#include "editor/editor_log.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "modules/websocket/remote_debugger_peer_websocket.h"
@ -48,19 +50,47 @@ void EditorDebuggerServerWebSocket::poll() {
server->poll();
}
String EditorDebuggerServerWebSocket::get_uri() const {
return endpoint;
}
Error EditorDebuggerServerWebSocket::start(const String &p_uri) {
// 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");
String bind_host = EditorSettings::get_singleton()->get("network/debug/remote_host");
// Optionally override
if (!p_uri.is_empty() && p_uri != "ws://") {
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);
}
// Set up the server
server->set_bind_ip(bind_host);
Vector<String> compatible_protocols;
compatible_protocols.push_back("binary"); // compatibility with EMSCRIPTEN TCP-to-WebSocket layer.
return server->listen(bind_port, compatible_protocols);
// Try listening on ports
const int max_attempts = 5;
for (int attempt = 1;; ++attempt) {
const Error err = server->listen(bind_port, compatible_protocols);
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);
}
// Endpoint that the client should connect to
endpoint = vformat("ws://%s:%d", bind_host, bind_port);
return OK;
}
void EditorDebuggerServerWebSocket::stop() {

View file

@ -40,6 +40,7 @@ class EditorDebuggerServerWebSocket : public EditorDebuggerServer {
private:
Ref<WebSocketServer> server;
List<int> pending_peers;
String endpoint;
public:
static EditorDebuggerServer *create(const String &p_protocol);
@ -47,12 +48,13 @@ public:
void _peer_connected(int p_peer, String p_protocol);
void _peer_disconnected(int p_peer, bool p_was_clean);
void poll() override;
Error start(const String &p_uri) override;
void stop() override;
bool is_active() const override;
bool is_connection_available() const override;
Ref<RemoteDebuggerPeer> take_connection() override;
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;
EditorDebuggerServerWebSocket();
~EditorDebuggerServerWebSocket();