28 #ifndef WEBSOCKETPP_ENDPOINT_HPP
29 #define WEBSOCKETPP_ENDPOINT_HPP
31 #include <websocketpp/connection.hpp>
33 #include <websocketpp/logger/levels.hpp>
34 #include <websocketpp/version.hpp>
41 template <
typename connection,
typename config>
42 class endpoint :
public config::transport_type,
public config::endpoint_base {
46 typedef endpoint<connection,config> type;
86 typedef typename connection_type::termination_handler termination_handler;
91 explicit endpoint(
bool p_is_server)
92 : m_alog(
new alog_type(config::alog_level, log::channel_type_hint::access))
93 , m_elog(
new elog_type(config::elog_level, log::channel_type_hint::error))
94 , m_user_agent(::websocketpp::user_agent)
95 , m_open_handshake_timeout_dur(config::timeout_open_handshake)
96 , m_close_handshake_timeout_dur(config::timeout_close_handshake)
97 , m_pong_timeout_dur(config::timeout_pong)
98 , m_max_message_size(config::max_message_size)
99 , m_max_http_body_size(config::max_http_body_size)
100 , m_is_server(p_is_server)
102 m_alog->set_channels(config::alog_level);
103 m_elog->set_channels(config::elog_level);
105 m_alog->write(log::alevel::devel,
"endpoint constructor");
107 transport_type::init_logging(m_alog, m_elog);
112 ~endpoint<connection,config>() {}
114 #ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
116 endpoint(endpoint &) =
delete;
119 endpoint & operator=(endpoint
const &) =
delete;
122 #ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
124 endpoint(endpoint && o)
125 : config::transport_type(std::move(o))
126 , config::endpoint_base(std::move(o))
127 , m_alog(std::move(o.m_alog))
128 , m_elog(std::move(o.m_elog))
129 , m_user_agent(std::move(o.m_user_agent))
130 , m_open_handler(std::move(o.m_open_handler))
132 , m_close_handler(std::move(o.m_close_handler))
133 , m_fail_handler(std::move(o.m_fail_handler))
134 , m_ping_handler(std::move(o.m_ping_handler))
135 , m_pong_handler(std::move(o.m_pong_handler))
136 , m_pong_timeout_handler(std::move(o.m_pong_timeout_handler))
137 , m_interrupt_handler(std::move(o.m_interrupt_handler))
138 , m_http_handler(std::move(o.m_http_handler))
139 , m_validate_handler(std::move(o.m_validate_handler))
140 , m_message_handler(std::move(o.m_message_handler))
142 , m_open_handshake_timeout_dur(o.m_open_handshake_timeout_dur)
143 , m_close_handshake_timeout_dur(o.m_close_handshake_timeout_dur)
144 , m_pong_timeout_dur(o.m_pong_timeout_dur)
145 , m_max_message_size(o.m_max_message_size)
146 , m_max_http_body_size(o.m_max_http_body_size)
148 , m_rng(std::move(o.m_rng))
149 , m_is_server(o.m_is_server)
152 #ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
154 endpoint & operator=(endpoint &&) =
delete;
221 m_alog->set_channels(channels);
232 m_alog->clear_channels(channels);
243 m_elog->set_channels(channels);
254 m_elog->clear_channels(channels);
277 void set_open_handler(open_handler h) {
278 m_alog->write(log::alevel::devel,
"set_open_handler");
282 void set_close_handler(close_handler h) {
283 m_alog->write(log::alevel::devel,
"set_close_handler");
287 void set_fail_handler(fail_handler h) {
288 m_alog->write(log::alevel::devel,
"set_fail_handler");
292 void set_ping_handler(ping_handler h) {
293 m_alog->write(log::alevel::devel,
"set_ping_handler");
297 void set_pong_handler(pong_handler h) {
298 m_alog->write(log::alevel::devel,
"set_pong_handler");
302 void set_pong_timeout_handler(pong_timeout_handler h) {
303 m_alog->write(log::alevel::devel,
"set_pong_timeout_handler");
305 m_pong_timeout_handler = h;
307 void set_interrupt_handler(interrupt_handler h) {
308 m_alog->write(log::alevel::devel,
"set_interrupt_handler");
310 m_interrupt_handler = h;
312 void set_http_handler(http_handler h) {
313 m_alog->write(log::alevel::devel,
"set_http_handler");
317 void set_validate_handler(validate_handler h) {
318 m_alog->write(log::alevel::devel,
"set_validate_handler");
320 m_validate_handler = h;
323 m_alog->write(log::alevel::devel,
"set_message_handler");
325 m_message_handler = h;
354 m_open_handshake_timeout_dur = dur;
379 m_close_handshake_timeout_dur = dur;
401 m_pong_timeout_dur = dur;
416 return m_max_message_size;
433 m_max_message_size = new_value;
450 return m_max_http_body_size;
467 m_max_http_body_size = new_value;
482 void interrupt(connection_hdl hdl, lib::error_code & ec);
483 void interrupt(connection_hdl hdl);
505 void pause_reading(connection_hdl hdl, lib::error_code & ec);
560 void send(connection_hdl hdl, std::string
const & payload,
561 frame::opcode::value op, lib::error_code & ec);
571 void send(connection_hdl hdl, std::string
const & payload,
572 frame::opcode::value op);
574 void send(connection_hdl hdl,
void const * payload, size_t len,
575 frame::opcode::value op, lib::error_code & ec);
576 void send(connection_hdl hdl,
void const * payload, size_t len,
577 frame::opcode::value op);
579 void send(connection_hdl hdl,
message_ptr msg, lib::error_code & ec);
582 void close(connection_hdl hdl, close::status::value
const code,
583 std::string
const & reason, lib::error_code & ec);
584 void close(connection_hdl hdl, close::status::value
const code,
585 std::string
const & reason);
595 void ping(connection_hdl hdl, std::string
const & payload,
596 lib::error_code & ec);
606 void ping(connection_hdl hdl, std::string
const & payload);
616 void pong(connection_hdl hdl, std::string
const & payload,
617 lib::error_code & ec);
627 void pong(connection_hdl hdl, std::string
const & payload);
647 ec = error::make_error_code(error::bad_connection);
664 lib::shared_ptr<alog_type> m_alog;
665 lib::shared_ptr<elog_type> m_elog;
668 std::string m_user_agent;
670 open_handler m_open_handler;
671 close_handler m_close_handler;
672 fail_handler m_fail_handler;
673 ping_handler m_ping_handler;
674 pong_handler m_pong_handler;
675 pong_timeout_handler m_pong_timeout_handler;
676 interrupt_handler m_interrupt_handler;
677 http_handler m_http_handler;
678 validate_handler m_validate_handler;
681 long m_open_handshake_timeout_dur;
682 long m_close_handshake_timeout_dur;
683 long m_pong_timeout_dur;
684 size_t m_max_message_size;
685 size_t m_max_http_body_size;
690 bool const m_is_server;
698 #include <websocketpp/impl/endpoint_impl.hpp>