Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions fuzzing/AsyncEpollHelloWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ void test() {
listen_socket = listenSocket;
});

/* Publishing without WebSocket contexts must be a no-op */
uWS::PreparedMessage preparedMessage = {};
if (app.publish("unused", "hi", uWS::TEXT) ||
app.publishPrepared("unused", preparedMessage) ||
app.numSubscribers("unused")) {
exit(-1);
}

app.run();
}
uWS::Loop::get()->free();
Expand Down
12 changes: 12 additions & 0 deletions src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ struct TemplatedApp {

/* Same as publish, but takes a prepared message */
bool publishPrepared(std::string_view topic, PreparedMessage &preparedMessage) {
if (!topicTree) {
return false;
}

/* It is assumed by heuristics that a prepared message ought to be big,
* and so there is no fast path for small messages (yet?) as preparing a small message is unlikely */

Expand All @@ -164,6 +168,10 @@ struct TemplatedApp {
* TopicTree of this app (technically there are many TopicTrees, however the concept is that one
* app has one conceptual Topic tree) */
bool publish(std::string_view topic, std::string_view message, OpCode opCode, bool compress = false) {
if (!topicTree) {
return false;
}

/* Anything big bypasses corking efforts */
if (message.length() >= LoopData::CORK_BUFFER_SIZE) {
return topicTree->publishBig(nullptr, topic, {message, opCode, compress}, [](Subscriber *s, TopicTreeBigMessage &message) {
Expand All @@ -181,6 +189,10 @@ struct TemplatedApp {
* This function should probably be optimized a lot in future releases,
* it could be O(1) with a hash map of fullnames and their counts. */
unsigned int numSubscribers(std::string_view topic) {
if (!topicTree) {
return 0;
}

Topic *t = topicTree->lookupTopic(topic);
if (t) {
return (unsigned int) t->size();
Expand Down
Loading