improves client connect error handling. Fixes #52

This commit is contained in:
Peter Thorson
2012-01-20 06:30:22 -06:00
parent 100ba9825f
commit a89cb776a1
2 changed files with 11 additions and 4 deletions

View File

@@ -153,7 +153,9 @@ namespace websocketpp {
GENERIC = 0,
// send attempted when endpoint write queue was full
SEND_QUEUE_FULL = 1,
PAYLOAD_VIOLATION = 2
PAYLOAD_VIOLATION = 2,
ENDPOINT_UNSECURE = 3,
ENDPOINT_UNAVAILABLE = 4
};
}

View File

@@ -253,18 +253,23 @@ private:
template <class endpoint>
typename endpoint_traits<endpoint>::connection_ptr
client<endpoint>::connect(const std::string& u) {
// TODO: will throw, should we catch and wrap?
// TODO: uri constructor will throw, should we catch and wrap?
uri_ptr location(new uri(u));
if (location->get_secure() && !m_endpoint.is_secure()) {
// TODO: what kind of exception does client throw?
throw "";
throw websocketpp::exception("Endpoint doesn't support secure connections.",websocketpp::error::ENDPOINT_UNSECURE);
}
tcp::resolver::query query(location->get_host(),location->get_port_str());
tcp::resolver::iterator iterator = m_resolver.resolve(query);
connection_ptr con = m_endpoint.create_connection();
if (!con) {
throw websocketpp::exception("Endpoint is unavailable.",
websocketpp::error::ENDPOINT_UNAVAILABLE);
}
con->set_uri(location);
boost::asio::async_connect(