diff --git a/src/TopicTree.h b/src/TopicTree.h index 6d11c4d..44cb4fb 100644 --- a/src/TopicTree.h +++ b/src/TopicTree.h @@ -76,7 +76,7 @@ struct Intersection { std::pair dataChannels; std::vector holes; - void forSubscriber(std::vector &senderForMessages, std::function)> cb) { + void forSubscriber(std::vector &senderForMessages, std::function, bool)> cb) { /* How far we already emitted of the two dataChannels */ std::pair emitted = {}; @@ -111,7 +111,8 @@ struct Intersection { std::string_view(dataChannels.second.data() + emitted.second, toEmit.second), }; - cb(cutDataChannels); + /* We only need to test the first data channel for "FIN" */ + cb(cutDataChannels, emitted.first + toEmit.first + toIgnore.first == dataChannels.first.length()); } emitted.first += toEmit.first + toIgnore.first; @@ -127,7 +128,7 @@ struct Intersection { std::string_view(dataChannels.second.data() + emitted.second, dataChannels.second.length() - emitted.second), }; - cb(cutDataChannels); + cb(cutDataChannels, true); } }; diff --git a/tests/TopicTree.cpp b/tests/TopicTree.cpp index 8d1ef9f..389d1aa 100644 --- a/tests/TopicTree.cpp +++ b/tests/TopicTree.cpp @@ -19,11 +19,25 @@ void testCorrectness() { topicTree = new uWS::TopicTree([&topicTree, &actualResult](uWS::Subscriber *s, uWS::Intersection &intersection) { - intersection.forSubscriber(topicTree->getSenderFor(s), [s, &actualResult](std::pair dataChannels) { + /* How many bytes we have in first data channel at time we get fin = true */ + unsigned int finAt = 0; + + intersection.forSubscriber(topicTree->getSenderFor(s), [s, &finAt, &actualResult](std::pair dataChannels, bool fin) { actualResult[s].first += dataChannels.first; actualResult[s].second += dataChannels.second; + + /* Check that getting fin = true really is the last segment */ + if (!finAt && fin) { + finAt = actualResult[s].first.length(); + } }); + /* Assume finAt == actualResult[s].first.length() */ + if (actualResult[s].first.length() != finAt) { + std::cout << "ERROR! FinAt mismatching!" << std::endl; + exit(1); + } + /* We actually don't use this one */ return 0; });