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 = lib::make_shared<lib::asio::ip::tcp::socket>(
174 if (m_socket_init_handler) {
175 m_socket_init_handler(m_hdl, *m_socket);
180 return lib::error_code();
194 void set_uri(uri_ptr) {}
205 void pre_init(init_handler callback) {
206 if (m_state != READY) {
207 callback(socket::make_error_code(socket::error::invalid_state));
213 callback(lib::error_code());
224 void post_init(init_handler callback) {
225 callback(lib::error_code());
235 void set_handle(connection_hdl hdl) {
248 lib::asio::error_code cancel_socket() {
249 lib::asio::error_code ec;
250 m_socket->cancel(ec);
254 void async_shutdown(socket::shutdown_handler h) {
255 lib::asio::error_code ec;
256 m_socket->shutdown(lib::asio::ip::tcp::socket::shutdown_both, ec);
260 lib::error_code get_ec()
const {
261 return lib::error_code();
283 template <
typename ErrorCodeType>
285 lib::error_code translate_ec(ErrorCodeType) {
287 return make_error_code(transport::error::pass_through);
293 lib::error_code translate_ec(lib::error_code ec) {
309 connection_hdl m_hdl;
310 socket_init_handler m_socket_init_handler;
321 typedef endpoint type;
324 typedef connection socket_con_type;
327 typedef socket_con_type::ptr socket_con_ptr;
329 explicit endpoint() {}
335 bool is_secure()
const {
347 void set_socket_init_handler(socket_init_handler h) {
348 m_socket_init_handler = h;
360 lib::error_code init(socket_con_ptr scon) {
361 scon->set_socket_init_handler(m_socket_init_handler);
362 return lib::error_code();
365 socket_init_handler m_socket_init_handler;