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>(
176 return lib::error_code();
190 void set_uri(uri_ptr) {}
201 void pre_init(init_handler callback) {
202 if (m_state != READY) {
203 callback(socket::make_error_code(socket::error::invalid_state));
207 if (m_socket_init_handler) {
208 m_socket_init_handler(m_hdl,*m_socket);
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();
282 template <
typename ErrorCodeType>
283 lib::error_code translate_ec(ErrorCodeType) {
285 return make_error_code(transport::error::pass_through);
290 lib::error_code translate_ec(lib::error_code ec) {
306 connection_hdl m_hdl;
307 socket_init_handler m_socket_init_handler;
318 typedef endpoint type;
321 typedef connection socket_con_type;
324 typedef socket_con_type::ptr socket_con_ptr;
326 explicit endpoint() {}
332 bool is_secure()
const {
344 void set_socket_init_handler(socket_init_handler h) {
345 m_socket_init_handler = h;
357 lib::error_code init(socket_con_ptr scon) {
358 scon->set_socket_init_handler(m_socket_init_handler);
359 return lib::error_code();
362 socket_init_handler m_socket_init_handler;