Skip to content

Commit

Permalink
fix subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Jan 25, 2024
1 parent 87a1d79 commit df30a57
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ 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) {
if (it->client == client) {
if (it->sub == sub && it->client == client) {
subscribers.erase(it);
break;
}
Expand Down Expand Up @@ -388,7 +388,6 @@ static void close_callback(ws28::Client *client) {
for (auto it = subscribers.begin(); it != subscribers.end(); ++it) {
if (it->client == client) {
subscribers.erase(it);
break;
}
}
}
Expand Down Expand Up @@ -494,10 +493,14 @@ static void storage_init() {
static void signal_handler(uv_signal_t *req, int /*signum*/) {
uv_signal_stop(req);
spdlog::warn("!! SIGINT");
for (const auto &s : subscribers) {
for (auto &s : subscribers) {
if (s.client == nullptr) {
continue;
}
relay_notice(s.client, s.sub, "shutdown...");
s.client->Close(0);
s.client->Destroy();
s.client = nullptr;
}
uv_stop(loop);
sqlite3_close_v2(conn);
Expand Down

0 comments on commit df30a57

Please sign in to comment.