Smaller TopicTree changes
This commit is contained in:
+14
-11
@@ -35,27 +35,28 @@ namespace uWS {
|
|||||||
class TopicTree {
|
class TopicTree {
|
||||||
private:
|
private:
|
||||||
struct Node : std::map<std::string, Node *> {
|
struct Node : std::map<std::string, Node *> {
|
||||||
Node *get(std::string path) {
|
/* Add and/or lookup node from topic */
|
||||||
std::pair<std::map<std::string, Node *>::iterator, bool> p = insert({path, nullptr});
|
Node *get(std::string topic) {
|
||||||
|
std::pair<std::map<std::string, Node *>::iterator, bool> p = insert({topic, nullptr});
|
||||||
if (p.second) {
|
if (p.second) {
|
||||||
return p.first->second = new Node;
|
return p.first->second = new Node;
|
||||||
} else {
|
} else {
|
||||||
return p.first->second;
|
return p.first->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Every subscriber should hold some backpressure cursor */
|
|
||||||
//std::vector<std::pair<void *, bool *>> subscribers;
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Subscribers have int backpressureOffset */
|
||||||
std::set<void *> subscribers;
|
std::set<void *> subscribers;
|
||||||
|
|
||||||
|
/* Current shared message */
|
||||||
std::string sharedMessage;
|
std::string sharedMessage;
|
||||||
|
|
||||||
/* We need backpressure stored */
|
/* Backpressure is stored linearly up to a limit */
|
||||||
/* vector */
|
|
||||||
std::string backpressure;
|
std::string backpressure;
|
||||||
} root; //topicToNode
|
unsigned int backpressureOffset = 0;
|
||||||
|
|
||||||
|
|
||||||
|
} topicToNode;
|
||||||
|
|
||||||
std::map<void *, std::vector<Node *>> socketToNodeList;
|
std::map<void *, std::vector<Node *>> socketToNodeList;
|
||||||
|
|
||||||
@@ -80,6 +81,8 @@ public:
|
|||||||
|
|
||||||
/* We say that all senders get their own message as well, for now being */
|
/* 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 (Node *topicNode : pubNodes) {
|
||||||
for (auto /*[*/ws/*, valid]*/ : topicNode->subscribers) {
|
for (auto /*[*/ws/*, valid]*/ : topicNode->subscribers) {
|
||||||
AsyncSocket<false> *asyncSocket = (AsyncSocket<false> *) ws; // assumes non-SSL for now
|
AsyncSocket<false> *asyncSocket = (AsyncSocket<false> *) ws; // assumes non-SSL for now
|
||||||
@@ -111,7 +114,7 @@ public:
|
|||||||
|
|
||||||
/* WebSocket.subscribe will lookup the Loop and subscribe in its tree */
|
/* WebSocket.subscribe will lookup the Loop and subscribe in its tree */
|
||||||
void subscribe(std::string topic, void *connection, bool *valid) {
|
void subscribe(std::string topic, void *connection, bool *valid) {
|
||||||
Node *curr = &root;
|
Node *curr = &topicToNode;
|
||||||
for (int i = 0; i < topic.length(); i++) {
|
for (int i = 0; i < topic.length(); i++) {
|
||||||
int start = i;
|
int start = i;
|
||||||
while (topic[i] != '/' && i < topic.length()) {
|
while (topic[i] != '/' && i < topic.length()) {
|
||||||
@@ -139,7 +142,7 @@ public:
|
|||||||
|
|
||||||
/* WebSocket.publish looks up its tree and publishes to it */
|
/* WebSocket.publish looks up its tree and publishes to it */
|
||||||
void publish(std::string topic, char *data, size_t length) {
|
void publish(std::string topic, char *data, size_t length) {
|
||||||
Node *curr = &root;
|
Node *curr = &topicToNode;
|
||||||
for (int i = 0; i < topic.length(); i++) {
|
for (int i = 0; i < topic.length(); i++) {
|
||||||
int start = i;
|
int start = i;
|
||||||
while (topic[i] != '/' && i < topic.length()) {
|
while (topic[i] != '/' && i < topic.length()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user