summaryrefslogtreecommitdiff
path: root/editor/fileserver
diff options
context:
space:
mode:
Diffstat (limited to 'editor/fileserver')
-rw-r--r--editor/fileserver/editor_file_server.cpp27
-rw-r--r--editor/fileserver/editor_file_server.h18
2 files changed, 20 insertions, 25 deletions
diff --git a/editor/fileserver/editor_file_server.cpp b/editor/fileserver/editor_file_server.cpp
index 8f019a95fd..718bcb24cc 100644
--- a/editor/fileserver/editor_file_server.cpp
+++ b/editor/fileserver/editor_file_server.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -46,14 +46,13 @@ void EditorFileServer::_close_client(ClientData *cd) {
cd->efs->to_wait.insert(cd->thread);
}
while (cd->files.size()) {
- memdelete(cd->files.front()->get());
- cd->files.erase(cd->files.front());
+ cd->files.remove(cd->files.begin());
}
memdelete(cd);
}
void EditorFileServer::_subthread_start(void *s) {
- ClientData *cd = (ClientData *)s;
+ ClientData *cd = static_cast<ClientData *>(s);
cd->connection->set_no_delay(true);
uint8_t buf4[8];
@@ -88,7 +87,7 @@ void EditorFileServer::_subthread_start(void *s) {
ERR_FAIL();
}
} else {
- if (cd->efs->password != "") {
+ if (!cd->efs->password.is_empty()) {
encode_uint32(ERR_INVALID_DATA, buf4);
cd->connection->put_data(buf4, 4);
OS::get_singleton()->delay_usec(1000000);
@@ -181,8 +180,8 @@ void EditorFileServer::_subthread_start(void *s) {
break;
}
- FileAccess *fa = FileAccess::open(s2, FileAccess::READ);
- if (!fa) {
+ Ref<FileAccess> fa = FileAccess::open(s2, FileAccess::READ);
+ if (fa.is_null()) {
//not found, continue
encode_uint32(id, buf4);
cd->connection->put_data(buf4, 4);
@@ -249,7 +248,6 @@ void EditorFileServer::_subthread_start(void *s) {
case FileAccessNetwork::COMMAND_CLOSE: {
print_verbose("CLOSED");
ERR_CONTINUE(!cd->files.has(id));
- memdelete(cd->files[id]);
cd->files.erase(id);
} break;
}
@@ -259,7 +257,7 @@ void EditorFileServer::_subthread_start(void *s) {
}
void EditorFileServer::_thread_start(void *s) {
- EditorFileServer *self = (EditorFileServer *)s;
+ EditorFileServer *self = static_cast<EditorFileServer *>(s);
while (!self->quit) {
if (self->cmd == CMD_ACTIVATE) {
self->server->listen(self->port);
@@ -284,7 +282,7 @@ void EditorFileServer::_thread_start(void *s) {
self->wait_mutex.lock();
while (self->to_wait.size()) {
- Thread *w = self->to_wait.front()->get();
+ Thread *w = *self->to_wait.begin();
self->to_wait.erase(w);
self->wait_mutex.unlock();
w->wait_to_finish();
@@ -298,8 +296,8 @@ void EditorFileServer::_thread_start(void *s) {
void EditorFileServer::start() {
stop();
- port = EDITOR_DEF("filesystem/file_server/port", 6010);
- password = EDITOR_DEF("filesystem/file_server/password", "");
+ port = EDITOR_GET("filesystem/file_server/port");
+ password = EDITOR_GET("filesystem/file_server/password");
cmd = CMD_ACTIVATE;
}
@@ -313,9 +311,6 @@ void EditorFileServer::stop() {
EditorFileServer::EditorFileServer() {
server.instantiate();
- quit = false;
- active = false;
- cmd = CMD_NONE;
thread.start(_thread_start, this);
EDITOR_DEF("filesystem/file_server/port", 6010);
diff --git a/editor/fileserver/editor_file_server.h b/editor/fileserver/editor_file_server.h
index d0405e0bb7..03b6ededab 100644
--- a/editor/fileserver/editor_file_server.h
+++ b/editor/fileserver/editor_file_server.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -47,15 +47,15 @@ class EditorFileServer : public Object {
};
struct ClientData {
- Thread *thread;
+ Thread *thread = nullptr;
Ref<StreamPeerTCP> connection;
- Map<int, FileAccess *> files;
+ HashMap<int, Ref<FileAccess>> files;
EditorFileServer *efs = nullptr;
bool quit = false;
};
Ref<TCPServer> server;
- Set<Thread *> to_wait;
+ HashSet<Thread *> to_wait;
static void _close_client(ClientData *cd);
static void _subthread_start(void *s);
@@ -63,12 +63,12 @@ class EditorFileServer : public Object {
Mutex wait_mutex;
Thread thread;
static void _thread_start(void *);
- bool quit;
- Command cmd;
+ bool quit = false;
+ Command cmd = CMD_NONE;
String password;
- int port;
- bool active;
+ int port = 0;
+ bool active = false;
public:
void start();