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 {
80 typedef typename concurrency_type::mutex_type
mutex_type;
86 typedef typename connection_type::termination_handler termination_handler;
89 : m_alog(config::alog_level, log::channel_type_hint::access)
90 , m_elog(config::elog_level, log::channel_type_hint::error)
92 , m_open_handshake_timeout_dur(config::timeout_open_handshake)
93 , m_close_handshake_timeout_dur(config::timeout_close_handshake)
94 , m_pong_timeout_dur(config::timeout_pong)
95 , m_max_message_size(config::max_message_size)
96 , m_max_http_body_size(config::max_http_body_size)
97 , m_is_server(p_is_server)
99 m_alog.set_channels(config::alog_level);
100 m_elog.set_channels(config::elog_level);
104 transport_type::init_logging(&m_alog, &m_elog);
117 scoped_lock_type guard(m_mutex);
144 scoped_lock_type guard(m_mutex);
168 m_alog.set_channels(channels);
179 m_alog.clear_channels(channels);
190 m_elog.set_channels(channels);
201 m_elog.clear_channels(channels);
226 scoped_lock_type guard(m_mutex);
231 scoped_lock_type guard(m_mutex);
236 scoped_lock_type guard(m_mutex);
241 scoped_lock_type guard(m_mutex);
246 scoped_lock_type guard(m_mutex);
251 scoped_lock_type guard(m_mutex);
252 m_pong_timeout_handler = h;
256 scoped_lock_type guard(m_mutex);
257 m_interrupt_handler = h;
261 scoped_lock_type guard(m_mutex);
266 scoped_lock_type guard(m_mutex);
267 m_validate_handler = h;
269 void set_message_handler(message_handler h) {
271 scoped_lock_type guard(m_mutex);
272 m_message_handler = h;
300 scoped_lock_type guard(m_mutex);
301 m_open_handshake_timeout_dur = dur;
325 scoped_lock_type guard(m_mutex);
326 m_close_handshake_timeout_dur = dur;
347 scoped_lock_type guard(m_mutex);
348 m_pong_timeout_dur = dur;
363 return m_max_message_size;
380 m_max_message_size = new_value;
397 return m_max_http_body_size;
414 m_max_http_body_size = new_value;
479 frame::opcode::value op, lib::error_code & ec);
490 frame::opcode::value op);
493 frame::opcode::value op, lib::error_code & ec);
495 frame::opcode::value op);
501 std::string
const & reason, lib::error_code & ec);
503 std::string
const & reason);
514 lib::error_code & ec);
535 lib::error_code & ec);
562 scoped_lock_type lock(m_mutex);
563 connection_ptr con = lib::static_pointer_cast<connection_type>(
581 connection_ptr create_connection();
587 std::string m_user_agent;
598 message_handler m_message_handler;
600 long m_open_handshake_timeout_dur;
601 long m_close_handshake_timeout_dur;
602 long m_pong_timeout_dur;
603 size_t m_max_message_size;
604 size_t m_max_http_body_size;
609 bool const m_is_server;
612 mutable mutex_type m_mutex;
617 #include <websocketpp/impl/endpoint_impl.hpp>
619 #endif // WEBSOCKETPP_ENDPOINT_HPP
config::concurrency_type concurrency_type
Type of the concurrency component of this endpoint.
uint16_t value
The type of a close code value.
size_t get_max_message_size() const
Get default maximum message size.
bool is_server() const
Returns whether or not this endpoint is a server.
lib::function< void(connection_hdl)> close_handler
The type and function signature of a close handler.
lib::function< void(connection_hdl)> open_handler
The type and function signature of an open handler.
void ping(connection_hdl hdl, std::string const &payload, lib::error_code &ec)
Send a ping to a specific connection.
lib::function< void(connection_hdl, std::string)> pong_timeout_handler
The type and function signature of a pong timeout handler.
lib::function< void(connection_hdl)> interrupt_handler
The type and function signature of an interrupt handler.
config::rng_type rng_type
Type of RNG.
lib::function< bool(connection_hdl, std::string)> ping_handler
The type and function signature of a ping handler.
void set_close_handshake_timeout(long dur)
Set close handshake timeout.
lib::weak_ptr< type > weak_ptr
Type of a weak pointer to this connection.
Represents an individual WebSocket connection.
connection_type::message_ptr message_ptr
Type of message pointers that this endpoint uses.
void interrupt(connection_hdl hdl, lib::error_code &ec)
connection_type::message_handler message_handler
Type of message_handler.
void set_open_handshake_timeout(long dur)
Set open handshake timeout.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
transport_con_type::ptr transport_con_ptr
alog_type & get_alog()
Get reference to access logger.
static char const user_agent[]
Default user agent string.
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
concurrency_type::scoped_lock_type scoped_lock_type
Type of our concurrency policy's scoped lock object.
void pause_reading(connection_hdl hdl, lib::error_code &ec)
Pause reading of new data (exception free)
std::string get_user_agent() const
Returns the user agent string that this endpoint will use.
static level const devel
Development messages (warning: very chatty)
concurrency_type::mutex_type mutex_type
Type of our concurrency policy's mutex object.
void resume_reading(connection_hdl hdl, lib::error_code &ec)
Resume reading of new data (exception free)
lib::function< bool(connection_hdl)> validate_handler
The type and function signature of a validate handler.
void set_max_http_body_size(size_t new_value)
Set maximum HTTP message body size.
void set_max_message_size(size_t new_value)
Set default maximum message size.
transport_type::transport_con_type transport_con_type
config::alog_type alog_type
Type of access logger.
size_t get_max_http_body_size() const
Get maximum HTTP message body size.
config::transport_type transport_type
Type of the transport component of this endpoint.
connection_type::ptr connection_ptr
Shared pointer to connection_type.
lib::function< void(connection_hdl)> http_handler
The type and function signature of a http handler.
void pong(connection_hdl hdl, std::string const &payload, lib::error_code &ec)
Send a pong to a specific connection.
void clear_error_channels(log::level channels)
Clear Error logging channels.
void set_access_channels(log::level channels)
Set Access logging channel.
Namespace for the WebSocket++ project.
elog_type & get_elog()
Get reference to error logger.
config::elog_type elog_type
Type of error logger.
Creates and manages connections associated with a WebSocket endpoint.
connection_type::weak_ptr connection_weak_ptr
Weak pointer to connection type.
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection.
connection connection_type
Type of the connections that this endpoint creates.
void clear_access_channels(log::level channels)
Clear Access logging channels.
void set_error_channels(log::level channels)
Set Error logging channel.
void set_pong_timeout(long dur)
Set pong timeout.
lib::function< void(connection_hdl, std::string)> pong_handler
The type and function signature of a pong handler.
connection_ptr get_con_from_hdl(connection_hdl hdl)
Retrieves a connection_ptr from a connection_hdl (exception version)
void set_user_agent(std::string const &ua)
Sets the user agent string that this endpoint will use.
void send(connection_hdl hdl, std::string const &payload, frame::opcode::value op, lib::error_code &ec)
Create a message and add it to the outgoing send queue (exception free)
lib::function< void(connection_hdl)> fail_handler
The type and function signature of a fail handler.