28 #ifndef WEBSOCKETPP_TRANSPORT_SECURITY_NONE_HPP
29 #define WEBSOCKETPP_TRANSPORT_SECURITY_NONE_HPP
31 #include <websocketpp/uri.hpp>
33 #include <websocketpp/transport/base/connection.hpp>
34 #include <websocketpp/transport/asio/security/base.hpp>
36 #include <websocketpp/common/asio.hpp>
37 #include <websocketpp/common/memory.hpp>
42 namespace websocketpp {
47 namespace basic_socket {
50 typedef lib::function<
void(connection_hdl,lib::asio::ip::tcp::socket&)>
58 class connection :
public lib::enable_shared_from_this<connection> {
61 typedef connection type;
63 typedef lib::shared_ptr<type> ptr;
66 typedef lib::asio::io_service* io_service_ptr;
68 typedef lib::shared_ptr<lib::asio::io_service::strand> strand_ptr;
70 typedef lib::asio::ip::tcp::socket socket_type;
72 typedef lib::shared_ptr<socket_type> socket_ptr;
74 explicit connection() : m_state(UNINITIALIZED) {
81 return shared_from_this();
88 bool is_secure()
const {
100 void set_socket_init_handler(socket_init_handler h) {
101 m_socket_init_handler = h;
108 lib::asio::ip::tcp::socket & get_socket() {
116 lib::asio::ip::tcp::socket & get_next_layer() {
124 lib::asio::ip::tcp::socket & get_raw_socket() {
138 std::string get_remote_endpoint(lib::error_code & ec)
const {
141 lib::asio::error_code aec;
142 lib::asio::ip::tcp::endpoint ep = m_socket->remote_endpoint(aec);
145 ec = error::make_error_code(error::pass_through);
146 s <<
"Error getting remote endpoint: " << aec
147 <<
" (" << aec.message() <<
")";
150 ec = lib::error_code();
165 lib::error_code init_asio (io_service_ptr service, strand_ptr,
bool)
167 if (m_state != UNINITIALIZED) {
168 return socket::make_error_code(socket::error::invalid_state);
171 m_socket.reset(
new lib::asio::ip::tcp::socket(*service));
173 if (m_socket_init_handler) {
174 m_socket_init_handler(m_hdl, *m_socket);
179 return lib::error_code();
193 void set_uri(uri_ptr) {}
204 void pre_init(init_handler callback) {
205 if (m_state != READY) {
206 callback(socket::make_error_code(socket::error::invalid_state));
212 callback(lib::error_code());
223 void post_init(init_handler callback) {
224 callback(lib::error_code());
234 void set_handle(connection_hdl hdl) {
247 lib::asio::error_code cancel_socket() {
248 lib::asio::error_code ec;
249 m_socket->cancel(ec);
253 void async_shutdown(socket::shutdown_handler h) {
254 lib::asio::error_code ec;
255 m_socket->shutdown(lib::asio::ip::tcp::socket::shutdown_both, ec);
259 lib::error_code get_ec()
const {
260 return lib::error_code();
282 template <
typename ErrorCodeType>
284 lib::error_code translate_ec(ErrorCodeType) {
286 return make_error_code(transport::error::pass_through);
292 lib::error_code translate_ec(lib::error_code ec) {
308 connection_hdl m_hdl;
309 socket_init_handler m_socket_init_handler;
320 typedef endpoint type;
323 typedef connection socket_con_type;
326 typedef socket_con_type::ptr socket_con_ptr;
328 explicit endpoint() {}
334 bool is_secure()
const {
346 void set_socket_init_handler(socket_init_handler h) {
347 m_socket_init_handler = h;
359 lib::error_code init(socket_con_ptr scon) {
360 scon->set_socket_init_handler(m_socket_init_handler);
361 return lib::error_code();
364 socket_init_handler m_socket_init_handler;