Reconnect to Slack RTM when disconnected with an error
This commit is contained in:
parent
61f2419ba4
commit
f592dc0ef3
2 changed files with 11 additions and 0 deletions
|
@ -66,6 +66,7 @@ class WebSocketClient {
|
||||||
void handleDNSResult(const std::vector<Swift::HostAddress>&, boost::optional<Swift::DomainNameResolveError>);
|
void handleDNSResult(const std::vector<Swift::HostAddress>&, boost::optional<Swift::DomainNameResolveError>);
|
||||||
void handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data);
|
void handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data);
|
||||||
void handleConnected(bool error);
|
void handleConnected(bool error);
|
||||||
|
void handleDisconnected(const boost::optional<Swift::Connection::Error> &error);
|
||||||
|
|
||||||
void connectServer();
|
void connectServer();
|
||||||
|
|
||||||
|
|
|
@ -208,10 +208,20 @@ void WebSocketClient::handleConnected(bool error) {
|
||||||
m_conn->write(Swift::createSafeByteArray(req));
|
m_conn->write(Swift::createSafeByteArray(req));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebSocketClient::handleDisconnected(const boost::optional<Swift::Connection::Error> &error) {
|
||||||
|
if (!error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG4CXX_ERROR(logger, "Disconected from " << m_host << ". Will reconnect in 1 second.");
|
||||||
|
m_reconnectTimer->start();
|
||||||
|
}
|
||||||
|
|
||||||
void WebSocketClient::handleDNSResult(const std::vector<Swift::HostAddress> &addrs, boost::optional<Swift::DomainNameResolveError>) {
|
void WebSocketClient::handleDNSResult(const std::vector<Swift::HostAddress> &addrs, boost::optional<Swift::DomainNameResolveError>) {
|
||||||
m_conn = m_tlsConnectionFactory->createConnection();
|
m_conn = m_tlsConnectionFactory->createConnection();
|
||||||
m_conn->onDataRead.connect(boost::bind(&WebSocketClient::handleDataRead, this, _1));
|
m_conn->onDataRead.connect(boost::bind(&WebSocketClient::handleDataRead, this, _1));
|
||||||
m_conn->onConnectFinished.connect(boost::bind(&WebSocketClient::handleConnected, this, _1));
|
m_conn->onConnectFinished.connect(boost::bind(&WebSocketClient::handleConnected, this, _1));
|
||||||
|
m_conn->onDisconnected.connect(boost::bind(&WebSocketClient::handleDisconnected, this, _1));
|
||||||
m_conn->connect(Swift::HostAddressPort(addrs[0], 443));
|
m_conn->connect(Swift::HostAddressPort(addrs[0], 443));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue