| 77 | } |
| 78 | |
| 79 | Error EditorDebuggerServerTCP::start(const String &p_uri) { |
| 80 | // Default host and port |
| 81 | String bind_host = (String)EDITOR_GET("network/debug/remote_host"); |
| 82 | int bind_port = (int)EDITOR_GET("network/debug/remote_port"); |
| 83 | |
| 84 | // Optionally override |
| 85 | if (!p_uri.is_empty() && p_uri != "tcp://") { |
| 86 | String scheme, path, fragment; |
| 87 | Error err = p_uri.parse_url(scheme, bind_host, bind_port, path, fragment); |
| 88 | ERR_FAIL_COND_V(err != OK, ERR_INVALID_PARAMETER); |
| 89 | ERR_FAIL_COND_V(!bind_host.is_valid_ip_address() && bind_host != "*", ERR_INVALID_PARAMETER); |
| 90 | } |
| 91 | |
| 92 | // Try listening on ports |
| 93 | const int max_attempts = 5; |
| 94 | for (int attempt = 1;; ++attempt) { |
| 95 | const Error err = server->listen(bind_port, bind_host); |
| 96 | if (err == OK) { |
| 97 | break; |
| 98 | } |
| 99 | if (attempt >= max_attempts) { |
| 100 | EditorNode::get_log()->add_message(vformat("Cannot listen on port %d, remote debugging unavailable.", bind_port), EditorLog::MSG_TYPE_ERROR); |
| 101 | return err; |
| 102 | } |
| 103 | int last_port = bind_port++; |
| 104 | EditorNode::get_log()->add_message(vformat("Cannot listen on port %d, trying %d instead.", last_port, bind_port), EditorLog::MSG_TYPE_WARNING); |
| 105 | } |
| 106 | |
| 107 | // Endpoint that the client should connect to |
| 108 | endpoint = vformat("tcp://%s:%d", bind_host, bind_port); |
| 109 | |
| 110 | return OK; |
| 111 | } |
| 112 | |
| 113 | void EditorDebuggerServerTCP::stop() { |
| 114 | server->stop(); |
nothing calls this directly
no test coverage detected