mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
adds more client functionality and associated tests
This commit is contained in:
@@ -10,7 +10,7 @@ Import('polyfill_libs')
|
||||
env = env.Clone ()
|
||||
env_cpp11 = env_cpp11.Clone ()
|
||||
|
||||
BOOST_LIBS = boostlibs(['unit_test_framework','system'],env) + [platform_libs]
|
||||
BOOST_LIBS = boostlibs(['unit_test_framework','system','regex'],env) + [platform_libs]
|
||||
|
||||
objs = env.Object('client_boost.o', ["client.cpp"], LIBS = BOOST_LIBS)
|
||||
objs += env.Object('server_boost.o', ["server.cpp"], LIBS = BOOST_LIBS)
|
||||
|
||||
@@ -56,7 +56,7 @@ struct stub_config : public websocketpp::config::core {
|
||||
typedef websocketpp::client<stub_config> client;
|
||||
typedef client::connection_ptr connection_ptr;
|
||||
|
||||
BOOST_AUTO_TEST_CASE( get_connection ) {
|
||||
BOOST_AUTO_TEST_CASE( invalid_uri ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
@@ -64,3 +64,21 @@ BOOST_AUTO_TEST_CASE( get_connection ) {
|
||||
|
||||
BOOST_CHECK( ec == websocketpp::error::make_error_code(websocketpp::error::invalid_uri) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( unsecure_endpoint ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
connection_ptr con = c.get_connection("wss://localhost/", ec);
|
||||
|
||||
BOOST_CHECK( ec == websocketpp::error::make_error_code(websocketpp::error::endpoint_not_secure) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( get_connection ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
|
||||
BOOST_CHECK( con );
|
||||
}
|
||||
@@ -82,24 +82,29 @@ public:
|
||||
connection_ptr get_connection(const std::string& u, lib::error_code &ec) {
|
||||
// parse uri
|
||||
try {
|
||||
// uri validation
|
||||
uri_ptr location(new uri(u));
|
||||
|
||||
if (location->get_secure() && !transport_type::is_secure()) {
|
||||
ec = error::make_error_code(error::endpoint_not_secure);
|
||||
return connection_ptr();
|
||||
}
|
||||
|
||||
// create connection
|
||||
connection_ptr con = endpoint_type::create_connection();
|
||||
|
||||
if (!con) {
|
||||
ec = error::make_error_code(error::con_creation_failed);
|
||||
return con;
|
||||
}
|
||||
|
||||
// Success
|
||||
ec = lib::error_code();
|
||||
return con;
|
||||
} catch (uri_exception) {
|
||||
|
||||
ec = error::make_error_code(error::invalid_uri);
|
||||
return connection_ptr();
|
||||
}
|
||||
|
||||
// uri validation
|
||||
|
||||
// create connection
|
||||
connection_ptr con = endpoint_type::create_connection();
|
||||
|
||||
if (!con) {
|
||||
ec = error::make_error_code(error::con_creation_failed);
|
||||
return con;
|
||||
}
|
||||
|
||||
// Success
|
||||
ec = lib::error_code();
|
||||
return con;
|
||||
}
|
||||
|
||||
/// Begin the connection process for the given connection
|
||||
@@ -120,6 +125,10 @@ public:
|
||||
// connect(...)
|
||||
private:
|
||||
// handle_connect
|
||||
void handle_connect(connection_ptr con, const lib::error_code & ec) {
|
||||
// start connection if successful
|
||||
// set failure information if not and call con->terminate
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace websocketpp
|
||||
|
||||
Reference in New Issue
Block a user