| 81 | } |
| 82 | |
| 83 | void WSClientConnection::ConnectThread() |
| 84 | { |
| 85 | do { |
| 86 | std::unique_lock<std::mutex> lck(_waitMtx); |
| 87 | _client.reset(); |
| 88 | _status = Status::CONNECTING; |
| 89 | // Create a connection to the given URI and queue it for connection once |
| 90 | // the event loop starts |
| 91 | websocketpp::lib::error_code ec; |
| 92 | client::connection_ptr con = _client.get_connection(_uri, ec); |
| 93 | if (ec) { |
| 94 | _failMsg = ec.message(); |
| 95 | blog(LOG_INFO, "connect to '%s' failed: %s", |
| 96 | _uri.c_str(), _failMsg.c_str()); |
| 97 | } else { |
| 98 | _failMsg = ""; |
| 99 | _client.connect(con); |
| 100 | _connection = connection_hdl(con); |
| 101 | |
| 102 | // Start the ASIO io_service run loop |
| 103 | vblog(LOG_INFO, "connect io thread started for '%s'", |
| 104 | _uri.c_str()); |
| 105 | _client.run(); |
| 106 | vblog(LOG_INFO, "connect: io thread exited '%s'", |
| 107 | _uri.c_str()); |
| 108 | } |
| 109 | |
| 110 | if (_reconnect) { |
| 111 | blog(LOG_INFO, |
| 112 | "trying to reconnect to %s in %d seconds.", |
| 113 | _uri.c_str(), _reconnectDelay); |
| 114 | _cv.wait_for(lck, |
| 115 | std::chrono::seconds(_reconnectDelay)); |
| 116 | } |
| 117 | } while (_reconnect && !_disconnect); |
| 118 | _status = Status::DISCONNECTED; |
| 119 | } |
| 120 | |
| 121 | void WSClientConnection::Connect(const std::string &uri, |
| 122 | const std::string &pass, bool reconnect, |