diff options
Diffstat (limited to 'editor/fileserver')
-rw-r--r-- | editor/fileserver/editor_file_server.cpp | 15 | ||||
-rw-r--r-- | editor/fileserver/editor_file_server.h | 14 |
2 files changed, 12 insertions, 17 deletions
diff --git a/editor/fileserver/editor_file_server.cpp b/editor/fileserver/editor_file_server.cpp index df0af69359..eed3917845 100644 --- a/editor/fileserver/editor_file_server.cpp +++ b/editor/fileserver/editor_file_server.cpp @@ -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]; @@ -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); @@ -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 7807e72800..21abbc3f8c 100644 --- a/editor/fileserver/editor_file_server.h +++ b/editor/fileserver/editor_file_server.h @@ -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; + RBSet<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(); |