mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 04:06:14 +00:00
Merge pull request #85519 from mxaddict/blender-rpc-server
Added proper timeout for blender rpc connection
This commit is contained in:
commit
13bf4fd19a
@ -192,6 +192,40 @@ Error EditorImportBlendRunner::do_import(const Dictionary &p_options) {
|
||||
}
|
||||
}
|
||||
|
||||
HTTPClient::Status EditorImportBlendRunner::connect_blender_rpc(const Ref<HTTPClient> &p_client, int p_timeout_usecs) {
|
||||
p_client->connect_to_host("127.0.0.1", rpc_port);
|
||||
HTTPClient::Status status = p_client->get_status();
|
||||
|
||||
int attempts = 1;
|
||||
int wait_usecs = 1000;
|
||||
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
OS::get_singleton()->delay_usec(wait_usecs);
|
||||
status = p_client->get_status();
|
||||
switch (status) {
|
||||
case HTTPClient::STATUS_RESOLVING:
|
||||
case HTTPClient::STATUS_CONNECTING: {
|
||||
p_client->poll();
|
||||
break;
|
||||
}
|
||||
case HTTPClient::STATUS_CONNECTED: {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (attempts * wait_usecs < p_timeout_usecs) {
|
||||
p_client->connect_to_host("127.0.0.1", rpc_port);
|
||||
} else {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Error EditorImportBlendRunner::do_import_rpc(const Dictionary &p_options) {
|
||||
kill_timer->stop();
|
||||
|
||||
@ -211,25 +245,9 @@ Error EditorImportBlendRunner::do_import_rpc(const Dictionary &p_options) {
|
||||
|
||||
// Connect to RPC server.
|
||||
Ref<HTTPClient> client = HTTPClient::create();
|
||||
client->connect_to_host("127.0.0.1", rpc_port);
|
||||
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
HTTPClient::Status status = client->get_status();
|
||||
switch (status) {
|
||||
case HTTPClient::STATUS_RESOLVING:
|
||||
case HTTPClient::STATUS_CONNECTING: {
|
||||
client->poll();
|
||||
break;
|
||||
}
|
||||
case HTTPClient::STATUS_CONNECTED: {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ERR_FAIL_V_MSG(ERR_CONNECTION_ERROR, vformat("Unexpected status during RPC connection: %d", status));
|
||||
}
|
||||
}
|
||||
HTTPClient::Status status = connect_blender_rpc(client, 1000000);
|
||||
if (status != HTTPClient::STATUS_CONNECTED) {
|
||||
ERR_FAIL_V_MSG(ERR_CONNECTION_ERROR, vformat("Unexpected status during RPC connection: %d", status));
|
||||
}
|
||||
|
||||
// Send XML request.
|
||||
@ -240,9 +258,9 @@ Error EditorImportBlendRunner::do_import_rpc(const Dictionary &p_options) {
|
||||
}
|
||||
|
||||
// Wait for response.
|
||||
done = false;
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
HTTPClient::Status status = client->get_status();
|
||||
status = client->get_status();
|
||||
switch (status) {
|
||||
case HTTPClient::STATUS_REQUESTING: {
|
||||
client->poll();
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "core/io/http_client.h"
|
||||
#include "core/os/os.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/main/timer.h"
|
||||
@ -60,6 +61,7 @@ public:
|
||||
bool is_running() { return blender_pid != 0 && OS::get_singleton()->is_process_running(blender_pid); }
|
||||
bool is_using_rpc() { return rpc_port != 0; }
|
||||
Error do_import(const Dictionary &p_options);
|
||||
HTTPClient::Status connect_blender_rpc(const Ref<HTTPClient> &p_client, int p_timeout_usecs);
|
||||
|
||||
EditorImportBlendRunner();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user