Skip to content

Commit

Permalink
fix subscribers loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Jan 25, 2024
1 parent df30a57 commit f5eeaf6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ static void do_relay_count(ws28::Client *client, nlohmann::json &data) {

static void do_relay_close(ws28::Client *client, nlohmann::json &data) {
std::string sub = data[1];
for (auto it = subscribers.begin(); it != subscribers.end(); ++it) {
auto it = subscribers.begin();
while (it != subscribers.end()) {
if (it->sub == sub && it->client == client) {
subscribers.erase(it);
break;
it = subscribers.erase(it);
} else {
it++;
}
}
}
Expand Down Expand Up @@ -385,9 +387,12 @@ static bool check_callback(ws28::Client * /*client*/, ws28::HTTPRequest &req) {
}

static void close_callback(ws28::Client *client) {
for (auto it = subscribers.begin(); it != subscribers.end(); ++it) {
auto it = subscribers.begin();
while (it != subscribers.end()) {
if (it->client == client) {
subscribers.erase(it);
it = subscribers.erase(it);
} else {
it++;
}
}
}
Expand Down

0 comments on commit f5eeaf6

Please sign in to comment.