| 465 | } |
| 466 | |
| 467 | void TwitchChatConnection::Disconnect() |
| 468 | { |
| 469 | std::lock_guard<std::mutex> lock(_connectMtx); |
| 470 | if (_state == State::DISCONNECTED) { |
| 471 | vblog(LOG_INFO, "TwitchChatConnection already disconnected"); |
| 472 | return; |
| 473 | } |
| 474 | |
| 475 | _stop = true; |
| 476 | |
| 477 | websocketpp::lib::error_code ec; |
| 478 | _client.close(_connection, websocketpp::close::status::normal, |
| 479 | "Twitch chat connection stopping", ec); |
| 480 | if (ec) { |
| 481 | blog(LOG_INFO, "TwitchChatConnection close failed: %s", |
| 482 | ec.message().c_str()); |
| 483 | |
| 484 | // TODO: avoid using stop() |
| 485 | _stop = true; |
| 486 | std::this_thread::sleep_for(3s); |
| 487 | _client.stop(); |
| 488 | } |
| 489 | |
| 490 | { |
| 491 | std::unique_lock<std::mutex> waitLock(_waitMtx); |
| 492 | _cv.notify_all(); |
| 493 | } |
| 494 | |
| 495 | if (_thread.joinable()) { |
| 496 | _thread.join(); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | static std::string toLowerCase(const std::string &str) |
| 501 | { |
no test coverage detected