From 4f00240a3bf48a31a977682b621ec2d0477c27ba Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 28 Mar 2013 22:43:55 -0500 Subject: [PATCH] adds preliminary foundations for client support --- websocketpp/client.hpp | 55 +--------------- websocketpp/roles/client_endpoint.hpp | 92 +++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 60 deletions(-) diff --git a/websocketpp/client.hpp b/websocketpp/client.hpp index 981f9e57da..8728e0f9dc 100644 --- a/websocketpp/client.hpp +++ b/websocketpp/client.hpp @@ -28,59 +28,6 @@ #ifndef WEBSOCKETPP_CLIENT_HPP #define WEBSOCKETPP_CLIENT_HPP -#include - -#include -#include - -namespace websocketpp { - -template -class client : public endpoint { -protected: - typedef client type; - - typedef endpoint base; -public: - typedef typename base::connection_ptr connection_ptr; - - explicit client(typename base::handler_ptr default_handler) - : base(default_handler,true) - { - std::cout << "client constructor" << std::endl; - } - - connection_ptr get_connection(const std::string& u); - - connection_ptr connect(const std::string& u); - connection_ptr connect(connection_ptr con); -private: -}; - - -template -typename client::connection_ptr -client::get_connection(const std::string& u) { - connection_ptr con = base::create_connection(); -} - -template -typename client::connection_ptr -client::connect(const std::string& u) { - connection_ptr con = get_connection(u); - return connect(con); -} - -template -typename client::connection_ptr -client::connect(typename client::connection_ptr con) { - transport::connect(con); - return con; -} - -} // namespace websocketpp - - - +#include #endif //WEBSOCKETPP_CLIENT_HPP \ No newline at end of file diff --git a/websocketpp/roles/client_endpoint.hpp b/websocketpp/roles/client_endpoint.hpp index 5e1f35bb0c..224bead1d1 100644 --- a/websocketpp/roles/client_endpoint.hpp +++ b/websocketpp/roles/client_endpoint.hpp @@ -29,19 +29,99 @@ #define WEBSOCKETPP_CLIENT_ENDPOINT_HPP #include +#include #include -#include namespace websocketpp { -namespace role { +/// Client endpoint role based on the given config +/** + * + */ +template +class client : public endpoint,config> { +public: + /// Type of this endpoint + typedef client type; + + /// Type of the endpoint concurrency component + typedef typename config::concurrency_type concurrency_type; + /// Type of the endpoint transport component + typedef typename config::transport_type transport_type; + + /// Type of the connections this server will create + typedef connection connection_type; + /// Type of a shared pointer to the connections this server will create + typedef typename connection_type::ptr connection_ptr; + + /// Type of the connection transport component + typedef typename transport_type::transport_con_type transport_con_type; + /// Type of a shared pointer to the connection transport component + typedef typename transport_con_type::ptr transport_con_ptr; + + /// Type of the endpoint component of this server + typedef endpoint endpoint_type; + + explicit client() : endpoint_type(false) + { + endpoint_type::m_alog.write(log::alevel::devel, + "client constructor"); + } + + /// Get a new connection + /** + * Creates and returns a pointer to a new connection to the given URI + * suitable for passing to connect(connection_ptr). This method allows + * applying connection specific settings before performing the opening + * handshake. + * + * @return A connection_ptr to the new connection + */ + connection_ptr get_connection(const std::string& u, lib::error_code &ec) { + // parse uri + try { + + } catch (uri_exception) { + + } + + // 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 + /** + * Initiates the opening connection handshake for connection con. Exact + * behavior depends on the underlying transport policy. + * + * @return The pointer to the connection originally passed in. + */ + connection_ptr connect(connection_ptr con) { + // transport async_connect + + return con; + } + + + + // connect(...) +private: + // handle_connect +}; -} // namespace role } // namespace websocketpp - - - #endif //WEBSOCKETPP_CLIENT_ENDPOINT_HPP \ No newline at end of file