From cfac783cd90fe81c46e50152cb160cc8a3cc758d Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sat, 9 Feb 2019 23:47:34 +0100 Subject: [PATCH] Smaller TopicTree changes --- src/TopicTree.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/TopicTree.h b/src/TopicTree.h index de207ee..44a1b3c 100644 --- a/src/TopicTree.h +++ b/src/TopicTree.h @@ -35,27 +35,28 @@ namespace uWS { class TopicTree { private: struct Node : std::map { - Node *get(std::string path) { - std::pair::iterator, bool> p = insert({path, nullptr}); + /* Add and/or lookup node from topic */ + Node *get(std::string topic) { + std::pair::iterator, bool> p = insert({topic, nullptr}); if (p.second) { return p.first->second = new Node; } else { return p.first->second; } } - /* Every subscriber should hold some backpressure cursor */ - //std::vector> subscribers; - + /* Subscribers have int backpressureOffset */ std::set subscribers; - + /* Current shared message */ std::string sharedMessage; - /* We need backpressure stored */ - /* vector */ + /* Backpressure is stored linearly up to a limit */ std::string backpressure; - } root; //topicToNode + unsigned int backpressureOffset = 0; + + + } topicToNode; std::map> socketToNodeList; @@ -80,6 +81,8 @@ public: /* We say that all senders get their own message as well, for now being */ + // if a node is very likely used together with another node? + for (Node *topicNode : pubNodes) { for (auto /*[*/ws/*, valid]*/ : topicNode->subscribers) { AsyncSocket *asyncSocket = (AsyncSocket *) ws; // assumes non-SSL for now @@ -111,7 +114,7 @@ public: /* WebSocket.subscribe will lookup the Loop and subscribe in its tree */ void subscribe(std::string topic, void *connection, bool *valid) { - Node *curr = &root; + Node *curr = &topicToNode; for (int i = 0; i < topic.length(); i++) { int start = i; while (topic[i] != '/' && i < topic.length()) { @@ -139,7 +142,7 @@ public: /* WebSocket.publish looks up its tree and publishes to it */ void publish(std::string topic, char *data, size_t length) { - Node *curr = &root; + Node *curr = &topicToNode; for (int i = 0; i < topic.length(); i++) { int start = i; while (topic[i] != '/' && i < topic.length()) {