summaryrefslogtreecommitdiff
path: root/editor/debugger/editor_debugger_server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/debugger/editor_debugger_server.cpp')
-rw-r--r--editor/debugger/editor_debugger_server.cpp138
1 files changed, 6 insertions, 132 deletions
diff --git a/editor/debugger/editor_debugger_server.cpp b/editor/debugger/editor_debugger_server.cpp
index bde0921ced..c80988a662 100644
--- a/editor/debugger/editor_debugger_server.cpp
+++ b/editor/debugger/editor_debugger_server.cpp
@@ -30,7 +30,7 @@
#include "editor_debugger_server.h"
-#include "core/io/packet_peer.h"
+#include "core/io/marshalls.h"
#include "core/io/tcp_server.h"
#include "core/os/mutex.h"
#include "core/os/thread.h"
@@ -38,114 +38,18 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
-class EditorDebuggerPeerTCP : public EditorDebuggerPeer {
-
-private:
- enum {
- QUEUE_MAX = 2048,
- POLL_USEC_MAX = 100,
- };
- Ref<StreamPeerTCP> tcp;
- Ref<PacketPeerStream> packet_peer;
- List<Array> out_queue;
- List<Array> in_queue;
- Mutex mutex;
- bool connected = false;
-
-public:
- Error poll() {
- MutexLock lock(mutex);
- connected = tcp->get_status() == StreamPeerTCP::STATUS_CONNECTED;
- Error err = OK;
- uint64_t ticks = OS::get_singleton()->get_ticks_usec();
- while (connected && packet_peer->get_available_packet_count() > 0 && in_queue.size() < QUEUE_MAX && OS::get_singleton()->get_ticks_usec() - ticks < POLL_USEC_MAX) {
- Variant var;
- err = packet_peer->get_var(var);
- connected = tcp->get_status() == StreamPeerTCP::STATUS_CONNECTED;
- if (err != OK) {
- ERR_PRINT("Error reading variant from peer");
- break;
- }
- ERR_CONTINUE_MSG(var.get_type() != Variant::ARRAY, "Malformed packet received, not an Array.");
- in_queue.push_back(var);
- }
- ticks = OS::get_singleton()->get_ticks_usec();
- while (connected && out_queue.size() > 0 && OS::get_singleton()->get_ticks_usec() - ticks < POLL_USEC_MAX) {
- Array arr = out_queue[0];
- out_queue.pop_front();
- packet_peer->put_var(arr);
- connected = tcp->get_status() == StreamPeerTCP::STATUS_CONNECTED;
- }
- return err;
- }
-
- bool has_message() {
- return in_queue.size() > 0;
- }
-
- Array get_message() {
- MutexLock lock(mutex);
- ERR_FAIL_COND_V(!has_message(), Array());
- Array out = in_queue[0];
- in_queue.pop_front();
- return out;
- }
-
- Error put_message(const Array p_arr) {
- MutexLock lock(mutex);
- if (out_queue.size() > QUEUE_MAX) {
- return ERR_OUT_OF_MEMORY;
- }
- out_queue.push_back(p_arr);
- return OK;
- }
-
- int get_max_message_size() const {
- return 8 << 20; // 8 MiB
- }
-
- bool is_peer_connected() {
- return connected;
- }
-
- void close() {
- MutexLock lock(mutex);
- connected = false;
- tcp->disconnect_from_host();
- }
-
- EditorDebuggerPeerTCP(Ref<StreamPeerTCP> p_stream) {
- packet_peer.instance();
- tcp = p_stream;
- if (tcp.is_null()) {
- tcp.instance(); // Bug?
- }
- packet_peer->set_stream_peer(tcp);
- }
-
- ~EditorDebuggerPeerTCP() {
- close();
- packet_peer->set_stream_peer(Ref<StreamPeer>());
- }
-};
-
class EditorDebuggerServerTCP : public EditorDebuggerServer {
private:
Ref<TCP_Server> server;
- List<Ref<EditorDebuggerPeer> > peers;
- Thread *thread = NULL;
- Mutex mutex;
- bool running = false;
-
- static void _poll_func(void *p_ud);
public:
+ virtual void poll() {}
virtual Error start();
virtual void stop();
virtual bool is_active() const;
virtual bool is_connection_available() const;
- virtual Ref<EditorDebuggerPeer> take_connection();
+ virtual Ref<RemoteDebuggerPeer> take_connection();
EditorDebuggerServerTCP();
};
@@ -161,19 +65,11 @@ Error EditorDebuggerServerTCP::start() {
EditorNode::get_log()->add_message(String("Error listening on port ") + itos(remote_port), EditorLog::MSG_TYPE_ERROR);
return err;
}
- running = true;
- thread = Thread::create(_poll_func, this);
return err;
}
void EditorDebuggerServerTCP::stop() {
server->stop();
- if (thread != NULL) {
- running = false;
- Thread::wait_to_finish(thread);
- memdelete(thread);
- thread = NULL;
- }
}
bool EditorDebuggerServerTCP::is_active() const {
@@ -184,31 +80,9 @@ bool EditorDebuggerServerTCP::is_connection_available() const {
return server->is_listening() && server->is_connection_available();
}
-Ref<EditorDebuggerPeer> EditorDebuggerServerTCP::take_connection() {
- ERR_FAIL_COND_V(!is_connection_available(), Ref<EditorDebuggerPeer>());
- MutexLock lock(mutex);
- Ref<EditorDebuggerPeerTCP> peer = memnew(EditorDebuggerPeerTCP(server->take_connection()));
- peers.push_back(peer);
- return peer;
-}
-
-void EditorDebuggerServerTCP::_poll_func(void *p_ud) {
- EditorDebuggerServerTCP *me = (EditorDebuggerServerTCP *)p_ud;
- while (me->running) {
- me->mutex.lock();
- List<Ref<EditorDebuggerPeer> > remove;
- for (int i = 0; i < me->peers.size(); i++) {
- Ref<EditorDebuggerPeer> peer = me->peers[i];
- Error err = ((EditorDebuggerPeerTCP *)peer.ptr())->poll();
- if (err != OK || !peer->is_peer_connected())
- remove.push_back(peer);
- }
- for (List<Ref<EditorDebuggerPeer> >::Element *E = remove.front(); E; E = E->next()) {
- me->peers.erase(E->get());
- }
- me->mutex.unlock();
- OS::get_singleton()->delay_usec(50);
- }
+Ref<RemoteDebuggerPeer> EditorDebuggerServerTCP::take_connection() {
+ ERR_FAIL_COND_V(!is_connection_available(), Ref<RemoteDebuggerPeer>());
+ return memnew(RemoteDebuggerPeerTCP(server->take_connection()));
}
EditorDebuggerServer *EditorDebuggerServer::create_default() {