Changeset - f592dc0ef3a6
[Not reviewed]
0 2 0
Jan Kaluza - 10 years ago 2015-12-28 09:17:41
jkaluza@redhat.com
Reconnect to Slack RTM when disconnected with an error
2 files changed with 11 insertions and 0 deletions:
0 comments (0 inline, 0 general)
include/transport/WebSocketClient.h
Show inline comments
 
@@ -63,12 +63,13 @@ class WebSocketClient {
 
		boost::signal<void ()> onWebSocketConnected;
 

	
 
	private:
 
		void handleDNSResult(const std::vector<Swift::HostAddress>&, boost::optional<Swift::DomainNameResolveError>);
 
		void handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data);
 
		void handleConnected(bool error);
 
		void handleDisconnected(const boost::optional<Swift::Connection::Error> &error);
 

	
 
		void connectServer();
 

	
 
	private:
 
		Component *m_component;
 
		boost::shared_ptr<Swift::DomainNameAddressQuery> m_dnsQuery;
libtransport/WebSocketClient.cpp
Show inline comments
 
@@ -205,14 +205,24 @@ void WebSocketClient::handleConnected(bool error) {
 
	req += "Sec-WebSocket-Version: 13\r\n";
 
	req += "\r\n";
 

	
 
	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>) {
 
	m_conn = m_tlsConnectionFactory->createConnection();
 
	m_conn->onDataRead.connect(boost::bind(&WebSocketClient::handleDataRead, 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));
 
}
 

	
 
}
0 comments (0 inline, 0 general)