From ac7c72698dec81847f105b32767c8565622f5c69 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Thu, 28 Jan 2021 17:26:02 +0100 Subject: [PATCH] Initial integration of new topicTree --- src/TopicTree.h | 4 ++-- src/WebSocketContextData.h | 8 +++++++- tests/TopicTree.cpp | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/TopicTree.h b/src/TopicTree.h index 334f4b2..6d11c4d 100644 --- a/src/TopicTree.h +++ b/src/TopicTree.h @@ -76,13 +76,13 @@ struct Intersection { std::pair dataChannels; std::vector holes; - void forSubscriber(Subscriber *s, std::vector &senderForMessages, std::function)> cb) { + void forSubscriber(std::vector &senderForMessages, std::function)> cb) { /* How far we already emitted of the two dataChannels */ std::pair emitted = {}; /* Holes are global to the entire topic tree, so we are not guaranteed to find * holes in this intersection - they are sorted, though */ - int examinedHoles = 0; + unsigned int examinedHoles = 0; /* This is a slow path of sorts, most subscribers will be observers, not active senders */ for (unsigned int id : senderForMessages) { diff --git a/src/WebSocketContextData.h b/src/WebSocketContextData.h index db2a04f..e8d7dba 100644 --- a/src/WebSocketContextData.h +++ b/src/WebSocketContextData.h @@ -76,7 +76,13 @@ public: Loop::get()->removePreHandler(this); } - WebSocketContextData() : topicTree([this](Subscriber *s, std::pair data) -> int { + WebSocketContextData() : topicTree([this](Subscriber *s, Intersection &intersection) -> int { + + + std::pair data = intersection.dataChannels; + + + /* We rely on writing to regular asyncSockets */ auto *asyncSocket = (AsyncSocket *) s->user; diff --git a/tests/TopicTree.cpp b/tests/TopicTree.cpp index 1148a19..8d1ef9f 100644 --- a/tests/TopicTree.cpp +++ b/tests/TopicTree.cpp @@ -19,7 +19,7 @@ void testCorrectness() { topicTree = new uWS::TopicTree([&topicTree, &actualResult](uWS::Subscriber *s, uWS::Intersection &intersection) { - intersection.forSubscriber(s, topicTree->getSenderFor(s), [s, &actualResult](std::pair dataChannels) { + intersection.forSubscriber(topicTree->getSenderFor(s), [s, &actualResult](std::pair dataChannels) { actualResult[s].first += dataChannels.first; actualResult[s].second += dataChannels.second; });