Represents an individual WebSocket connection. More...
#include <connection.hpp>
Public Types | |
typedef connection< config > | type |
Type of this connection. More... | |
typedef lib::shared_ptr< type > | ptr |
Type of a shared pointer to this connection. More... | |
typedef lib::weak_ptr< type > | weak_ptr |
Type of a weak pointer to this connection. More... | |
typedef config::concurrency_type | concurrency_type |
Type of the concurrency component of this connection. More... | |
typedef config::alog_type | alog_type |
Type of the access logging policy. More... | |
typedef config::elog_type | elog_type |
Type of the error logging policy. More... | |
typedef config::transport_type::transport_con_type | transport_con_type |
Type of the transport component of this connection. More... | |
typedef transport_con_type::ptr | transport_con_ptr |
Type of a shared pointer to the transport component of this connection. More... | |
typedef lib::function< void(ptr)> | termination_handler |
typedef concurrency_type::scoped_lock_type | scoped_lock_type |
typedef concurrency_type::mutex_type | mutex_type |
typedef config::request_type | request_type |
typedef config::response_type | response_type |
typedef config::message_type | message_type |
typedef message_type::ptr | message_ptr |
typedef config::con_msg_manager_type | con_msg_manager_type |
typedef con_msg_manager_type::ptr | con_msg_manager_ptr |
typedef config::rng_type | rng_type |
Type of RNG. More... | |
typedef processor::processor< config > | processor_type |
typedef lib::shared_ptr< processor_type > | processor_ptr |
typedef lib::function< void(connection_hdl, message_ptr)> | message_handler |
typedef transport_con_type::timer_ptr | timer_ptr |
Type of a pointer to a transport timer handle. More... | |
typedef session::internal_state::value | istate_type |
Public Member Functions | |
connection (bool p_is_server, std::string const &ua, alog_type &alog, elog_type &elog, rng_type &rng) | |
ptr | get_shared () |
Get a shared pointer to this component. More... | |
void | set_open_handler (open_handler h) |
Set open handler. More... | |
void | set_close_handler (close_handler h) |
Set close handler. More... | |
void | set_fail_handler (fail_handler h) |
Set fail handler. More... | |
void | set_ping_handler (ping_handler h) |
Set ping handler. More... | |
void | set_pong_handler (pong_handler h) |
Set pong handler. More... | |
void | set_pong_timeout_handler (pong_timeout_handler h) |
Set pong timeout handler. More... | |
void | set_interrupt_handler (interrupt_handler h) |
Set interrupt handler. More... | |
void | set_http_handler (http_handler h) |
Set http handler. More... | |
void | set_validate_handler (validate_handler h) |
Set validate handler. More... | |
void | set_message_handler (message_handler h) |
Set message handler. More... | |
void | set_open_handshake_timeout (long dur) |
Set open handshake timeout. More... | |
void | set_close_handshake_timeout (long dur) |
Set close handshake timeout. More... | |
void | set_pong_timeout (long dur) |
Set pong timeout. More... | |
size_t | get_max_message_size () const |
Get maximum message size. More... | |
void | set_max_message_size (size_t new_value) |
Set maximum message size. More... | |
size_t | get_max_http_body_size () const |
Get maximum HTTP message body size. More... | |
void | set_max_http_body_size (size_t new_value) |
Set maximum HTTP message body size. More... | |
size_t | get_buffered_amount () const |
Get the size of the outgoing write buffer (in payload bytes) More... | |
size_t | buffered_amount () const |
Get the size of the outgoing write buffer (in payload bytes) More... | |
lib::error_code | send (std::string const &payload, frame::opcode::value op=frame::opcode::text) |
Create a message and then add it to the outgoing send queue. More... | |
lib::error_code | send (void const *payload, size_t len, frame::opcode::value op=frame::opcode::binary) |
Send a message (raw array overload) More... | |
lib::error_code | send (message_ptr msg) |
Add a message to the outgoing send queue. More... | |
lib::error_code | interrupt () |
Asyncronously invoke handler::on_inturrupt. More... | |
void | handle_interrupt () |
Transport inturrupt callback. More... | |
lib::error_code | pause_reading () |
Pause reading of new data. More... | |
void | handle_pause_reading () |
Pause reading callback. More... | |
lib::error_code | resume_reading () |
Resume reading of new data. More... | |
void | handle_resume_reading () |
Resume reading callback. More... | |
void | ping (std::string const &payload) |
Send a ping. More... | |
void | ping (std::string const &payload, lib::error_code &ec) |
exception free variant of ping More... | |
void | handle_pong_timeout (std::string payload, lib::error_code const &ec) |
Utility method that gets called back when the ping timer expires. More... | |
void | pong (std::string const &payload) |
Send a pong. More... | |
void | pong (std::string const &payload, lib::error_code &ec) |
exception free variant of pong More... | |
void | close (close::status::value const code, std::string const &reason) |
Close the connection. More... | |
void | close (close::status::value const code, std::string const &reason, lib::error_code &ec) |
exception free variant of close More... | |
bool | get_secure () const |
Returns the secure flag from the connection URI. More... | |
std::string const & | get_host () const |
Returns the host component of the connection URI. More... | |
std::string const & | get_resource () const |
Returns the resource component of the connection URI. More... | |
uint16_t | get_port () const |
Returns the port component of the connection URI. More... | |
uri_ptr | get_uri () const |
Gets the connection URI. More... | |
void | set_uri (uri_ptr uri) |
Sets the connection URI. More... | |
std::string const & | get_subprotocol () const |
Gets the negotated subprotocol. More... | |
std::vector< std::string > const & | get_requested_subprotocols () const |
Gets all of the subprotocols requested by the client. More... | |
void | add_subprotocol (std::string const &request, lib::error_code &ec) |
Adds the given subprotocol string to the request list (exception free) More... | |
void | add_subprotocol (std::string const &request) |
Adds the given subprotocol string to the request list. More... | |
void | select_subprotocol (std::string const &value, lib::error_code &ec) |
Select a subprotocol to use (exception free) More... | |
void | select_subprotocol (std::string const &value) |
Select a subprotocol to use. More... | |
std::string const & | get_request_header (std::string const &key) const |
Retrieve a request header. More... | |
std::string const & | get_request_body () const |
Retrieve a request body. More... | |
std::string const & | get_response_header (std::string const &key) const |
Retrieve a response header. More... | |
http::status_code::value | get_response_code () const |
Get response HTTP status code. More... | |
std::string const & | get_response_msg () const |
Get response HTTP status message. More... | |
void | set_status (http::status_code::value code) |
Set response status code and message. More... | |
void | set_status (http::status_code::value code, std::string const &msg) |
Set response status code and message. More... | |
void | set_body (std::string const &value) |
Set response body content. More... | |
void | append_header (std::string const &key, std::string const &val) |
Append a header. More... | |
void | replace_header (std::string const &key, std::string const &val) |
Replace a header. More... | |
void | remove_header (std::string const &key) |
Remove a header. More... | |
request_type const & | get_request () const |
Get request object. More... | |
response_type const & | get_response () const |
Get response object. More... | |
lib::error_code | defer_http_response () |
Defer HTTP Response until later (Exception free) More... | |
void | send_http_response (lib::error_code &ec) |
Send deferred HTTP Response (exception free) More... | |
void | send_http_response () |
Send deferred HTTP Response. More... | |
connection_hdl | get_handle () const |
Get Connection Handle. More... | |
bool | is_server () const |
Get whether or not this connection is part of a server or client. More... | |
std::string const & | get_origin () const |
Return the same origin policy origin value from the opening request. More... | |
session::state::value | get_state () const |
Return the connection state. More... | |
close::status::value | get_local_close_code () const |
Get the WebSocket close code sent by this endpoint. More... | |
std::string const & | get_local_close_reason () const |
Get the WebSocket close reason sent by this endpoint. More... | |
close::status::value | get_remote_close_code () const |
Get the WebSocket close code sent by the remote endpoint. More... | |
std::string const & | get_remote_close_reason () const |
Get the WebSocket close reason sent by the remote endpoint. More... | |
lib::error_code | get_ec () const |
Get the internal error code for a closed/failed connection. More... | |
message_ptr | get_message (websocketpp::frame::opcode::value op, size_t size) const |
Get a message buffer. More... | |
void | read_handshake (size_t num_bytes) |
void | handle_read_handshake (lib::error_code const &ec, size_t bytes_transferred) |
void | handle_read_http_response (lib::error_code const &ec, size_t bytes_transferred) |
void | handle_write_http_response (lib::error_code const &ec) |
void | handle_send_http_request (lib::error_code const &ec) |
void | handle_open_handshake_timeout (lib::error_code const &ec) |
void | handle_close_handshake_timeout (lib::error_code const &ec) |
void | handle_read_frame (lib::error_code const &ec, size_t bytes_transferred) |
void | read_frame () |
Issue a new transport read unless reading is paused. More... | |
std::vector< int > const & | get_supported_versions () const |
Get array of WebSocket protocol versions that this connection supports. More... | |
void | set_termination_handler (termination_handler new_handler) |
Sets the handler for a terminating connection. More... | |
void | terminate (lib::error_code const &ec) |
void | handle_terminate (terminate_status tstat, lib::error_code const &ec) |
void | write_frame () |
Checks if there are frames in the send queue and if there are sends one. More... | |
void | handle_write_frame (lib::error_code const &ec) |
Process the results of a frame write operation and start the next write. More... | |
void | start () |
Start the connection state machine. More... | |
void | set_handle (connection_hdl hdl) |
Set Connection Handle. More... | |
Protected Member Functions | |
void | handle_transport_init (lib::error_code const &ec) |
lib::error_code | initialize_processor () |
Set m_processor based on information in m_request. More... | |
lib::error_code | process_handshake_request () |
Perform WebSocket handshake validation of m_request using m_processor. More... | |
Represents an individual WebSocket connection.
Definition at line 235 of file connection.hpp.
typedef connection<config> websocketpp::connection< config >::type |
Type of this connection.
Definition at line 241 of file connection.hpp.
typedef lib::shared_ptr<type> websocketpp::connection< config >::ptr |
Type of a shared pointer to this connection.
Definition at line 243 of file connection.hpp.
typedef lib::weak_ptr<type> websocketpp::connection< config >::weak_ptr |
Type of a weak pointer to this connection.
Definition at line 245 of file connection.hpp.
typedef config::concurrency_type websocketpp::connection< config >::concurrency_type |
Type of the concurrency component of this connection.
Definition at line 248 of file connection.hpp.
typedef config::alog_type websocketpp::connection< config >::alog_type |
Type of the access logging policy.
Definition at line 250 of file connection.hpp.
typedef config::elog_type websocketpp::connection< config >::elog_type |
Type of the error logging policy.
Definition at line 252 of file connection.hpp.
typedef config::transport_type::transport_con_type websocketpp::connection< config >::transport_con_type |
Type of the transport component of this connection.
Definition at line 256 of file connection.hpp.
typedef transport_con_type::ptr websocketpp::connection< config >::transport_con_ptr |
Type of a shared pointer to the transport component of this connection.
Definition at line 258 of file connection.hpp.
typedef lib::function<void(ptr)> websocketpp::connection< config >::termination_handler |
Definition at line 260 of file connection.hpp.
typedef concurrency_type::scoped_lock_type websocketpp::connection< config >::scoped_lock_type |
Definition at line 262 of file connection.hpp.
typedef concurrency_type::mutex_type websocketpp::connection< config >::mutex_type |
Definition at line 263 of file connection.hpp.
typedef config::request_type websocketpp::connection< config >::request_type |
Definition at line 265 of file connection.hpp.
typedef config::response_type websocketpp::connection< config >::response_type |
Definition at line 266 of file connection.hpp.
typedef config::message_type websocketpp::connection< config >::message_type |
Definition at line 268 of file connection.hpp.
typedef message_type::ptr websocketpp::connection< config >::message_ptr |
Definition at line 269 of file connection.hpp.
typedef config::con_msg_manager_type websocketpp::connection< config >::con_msg_manager_type |
Definition at line 271 of file connection.hpp.
typedef con_msg_manager_type::ptr websocketpp::connection< config >::con_msg_manager_ptr |
Definition at line 272 of file connection.hpp.
typedef config::rng_type websocketpp::connection< config >::rng_type |
Type of RNG.
Definition at line 275 of file connection.hpp.
typedef processor::processor<config> websocketpp::connection< config >::processor_type |
Definition at line 277 of file connection.hpp.
typedef lib::shared_ptr<processor_type> websocketpp::connection< config >::processor_ptr |
Definition at line 278 of file connection.hpp.
typedef lib::function<void(connection_hdl,message_ptr)> websocketpp::connection< config >::message_handler |
Definition at line 281 of file connection.hpp.
typedef transport_con_type::timer_ptr websocketpp::connection< config >::timer_ptr |
Type of a pointer to a transport timer handle.
Definition at line 284 of file connection.hpp.
typedef session::internal_state::value websocketpp::connection< config >::istate_type |
Definition at line 287 of file connection.hpp.
|
inlineexplicit |
Definition at line 297 of file connection.hpp.
|
inline |
Get a shared pointer to this component.
Definition at line 336 of file connection.hpp.
|
inline |
Set open handler.
The open handler is called after the WebSocket handshake is complete and the connection is considered OPEN.
h | The new open_handler |
Definition at line 351 of file connection.hpp.
|
inline |
Set close handler.
The close handler is called immediately after the connection is closed.
h | The new close_handler |
Definition at line 361 of file connection.hpp.
|
inline |
Set fail handler.
The fail handler is called whenever the connection fails while the handshake is bring processed.
h | The new fail_handler |
Definition at line 372 of file connection.hpp.
|
inline |
Set ping handler.
The ping handler is called whenever the connection receives a ping control frame. The ping payload is included.
The ping handler's return time controls whether or not a pong is sent in response to this ping. Returning false will suppress the return pong. If no ping handler is set a pong will be sent.
h | The new ping_handler |
Definition at line 387 of file connection.hpp.
|
inline |
Set pong handler.
The pong handler is called whenever the connection receives a pong control frame. The pong payload is included.
h | The new pong_handler |
Definition at line 398 of file connection.hpp.
|
inline |
Set pong timeout handler.
If the transport component being used supports timers, the pong timeout handler is called whenever a pong control frame is not received with the configured timeout period after the application sends a ping.
The config setting timeout_pong
controls the length of the timeout period. It is specified in milliseconds.
This can be used to probe the health of the remote endpoint's WebSocket implementation. This does not guarantee that the remote application itself is still healthy but can be a useful diagnostic.
Note: receipt of this callback doesn't mean the pong will never come. This functionality will not suppress delivery of the pong in question should it arrive after the timeout.
h | The new pong_timeout_handler |
Definition at line 421 of file connection.hpp.
|
inline |
Set interrupt handler.
The interrupt handler is called whenever the connection is manually interrupted by the application.
h | The new interrupt_handler |
Definition at line 432 of file connection.hpp.
|
inline |
Set http handler.
The http handler is called after an HTTP request other than a WebSocket upgrade request is received. It allows a WebSocket++ server to respond to regular HTTP requests on the same port as it processes WebSocket connections. This can be useful for hosting error messages, flash policy files, status pages, and other simple HTTP responses. It is not intended to be used as a primary web server.
h | The new http_handler |
Definition at line 447 of file connection.hpp.
|
inline |
Set validate handler.
The validate handler is called after a WebSocket handshake has been parsed but before a response is returned. It provides the application a chance to examine the request and determine whether or not it wants to accept the connection.
Returning false from the validate handler will reject the connection. If no validate handler is present, all connections will be allowed.
h | The new validate_handler |
Definition at line 463 of file connection.hpp.
|
inline |
Set message handler.
The message handler is called after a new message has been received.
h | The new message_handler |
Definition at line 473 of file connection.hpp.
|
inline |
Set open handshake timeout.
Sets the length of time the library will wait after an opening handshake has been initiated before cancelling it. This can be used to prevent excessive wait times for outgoing clients or excessive resource usage from broken clients or DoS attacks on servers.
Connections that time out will have their fail handlers called with the open_handshake_timeout error code.
The default value is specified via the compile time config value 'timeout_open_handshake'. The default value in the core config is 5000ms. A value of 0 will disable the timer entirely.
To be effective, the transport you are using must support timers. See the documentation for your transport policy for details about its timer support.
dur | The length of the open handshake timeout in ms |
Definition at line 501 of file connection.hpp.
|
inline |
Set close handshake timeout.
Sets the length of time the library will wait after a closing handshake has been initiated before cancelling it. This can be used to prevent excessive wait times for outgoing clients or excessive resource usage from broken clients or DoS attacks on servers.
Connections that time out will have their close handlers called with the close_handshake_timeout error code.
The default value is specified via the compile time config value 'timeout_close_handshake'. The default value in the core config is 5000ms. A value of 0 will disable the timer entirely.
To be effective, the transport you are using must support timers. See the documentation for your transport policy for details about its timer support.
dur | The length of the close handshake timeout in ms |
Definition at line 525 of file connection.hpp.
|
inline |
Set pong timeout.
Sets the length of time the library will wait for a pong response to a ping. This can be used as a keepalive or to detect broken connections.
Pong responses that time out will have the pong timeout handler called.
The default value is specified via the compile time config value 'timeout_pong'. The default value in the core config is 5000ms. A value of 0 will disable the timer entirely.
To be effective, the transport you are using must support timers. See the documentation for your transport policy for details about its timer support.
dur | The length of the pong timeout in ms |
Definition at line 546 of file connection.hpp.
|
inline |
Get maximum message size.
Get maximum message size. Maximum message size determines the point at which the connection will fail with the message_too_big protocol error.
The default is set by the endpoint that creates the connection.
Definition at line 559 of file connection.hpp.
|
inline |
Set maximum message size.
Set maximum message size. Maximum message size determines the point at which the connection will fail with the message_too_big protocol error. This value may be changed during the connection.
The default is set by the endpoint that creates the connection.
new_value | The value to set as the maximum message size. |
Definition at line 575 of file connection.hpp.
Referenced by websocketpp::connection< config >::get_supported_versions().
|
inline |
Get maximum HTTP message body size.
Get maximum HTTP message body size. Maximum message body size determines the point at which the connection will stop reading an HTTP request whose body is too large.
The default is set by the endpoint that creates the connection.
Definition at line 594 of file connection.hpp.
|
inline |
Set maximum HTTP message body size.
Set maximum HTTP message body size. Maximum message body size determines the point at which the connection will stop reading an HTTP request whose body is too large.
The default is set by the endpoint that creates the connection.
new_value | The value to set as the maximum message size. |
Definition at line 610 of file connection.hpp.
size_t websocketpp::connection< config >::get_buffered_amount | ( | ) | const |
Get the size of the outgoing write buffer (in payload bytes)
Retrieves the number of bytes in the outgoing write buffer that have not already been dispatched to the transport layer. This represents the bytes that are presently cancelable without uncleanly ending the websocket connection
This method invokes the m_write_lock mutex
Definition at line 71 of file connection_impl.hpp.
|
inline |
Get the size of the outgoing write buffer (in payload bytes)
get_buffered_amount
instead Definition at line 635 of file connection.hpp.
lib::error_code websocketpp::connection< config >::send | ( | std::string const & | payload, |
frame::opcode::value | op = frame::opcode::text |
||
) |
Create a message and then add it to the outgoing send queue.
Convenience method to send a message given a payload string and optionally an opcode. Default opcode is utf8 text.
This method locks the m_write_lock mutex
payload | The payload string to generated the message with |
op | The opcode to generated the message with. Default is frame::opcode::text |
Definition at line 83 of file connection_impl.hpp.
lib::error_code websocketpp::connection< config >::send | ( | void const * | payload, |
size_t | len, | ||
frame::opcode::value | op = frame::opcode::binary |
||
) |
Send a message (raw array overload)
Convenience method to send a message given a raw array and optionally an opcode. Default opcode is binary.
This method locks the m_write_lock mutex
payload | A pointer to the array containing the bytes to send. |
len | Length of the array. |
op | The opcode to generated the message with. Default is frame::opcode::binary |
Definition at line 94 of file connection_impl.hpp.
lib::error_code websocketpp::connection< config >::send | ( | message_ptr | msg | ) |
Add a message to the outgoing send queue.
If presented with a prepared message it is added without validation or framing. If presented with an unprepared message it is validated, framed, and then added
Errors are returned via an exception
This method invokes the m_write_lock mutex
msg | A message_ptr to the message to send. |
Definition at line 104 of file connection_impl.hpp.
References websocketpp::log::alevel::devel, websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::error::no_outgoing_buffers, and websocketpp::session::state::open.
lib::error_code websocketpp::connection< config >::interrupt | ( | ) |
Asyncronously invoke handler::on_inturrupt.
Trigger the on_interrupt handler.
Signals to the connection to asyncronously invoke the on_inturrupt callback for this connection's handler once it is safe to do so.
When the on_inturrupt handler callback is called it will be from within the transport event loop with all the thread safety features guaranteed by the transport to regular handlers
Multiple inturrupt signals can be active at once on the same connection
This is thread safe if the transport is thread safe
Definition at line 341 of file connection_impl.hpp.
References websocketpp::log::alevel::devel.
void websocketpp::connection< config >::handle_interrupt | ( | ) |
Transport inturrupt callback.
Definition at line 353 of file connection_impl.hpp.
lib::error_code websocketpp::connection< config >::pause_reading | ( | ) |
Pause reading of new data.
Signals to the connection to halt reading of new data. While reading is paused, the connection will stop reading from its associated socket. In turn this will result in TCP based flow control kicking in and slowing data flow from the remote endpoint.
This is useful for applications that push new requests to a queue to be processed by another thread and need a way to signal when their request queue is full without blocking the network processing thread.
Use resume_reading()
to resume.
If supported by the transport this is done asynchronously. As such reading may not stop until the current read operation completes. Typically you can expect to receive no more bytes after initiating a read pause than the size of the read buffer.
If reading is paused for this connection already nothing is changed.
Definition at line 360 of file connection_impl.hpp.
References websocketpp::log::alevel::devel.
void websocketpp::connection< config >::handle_pause_reading | ( | ) |
Pause reading callback.
Pause reading handler. Not safe to call directly.
Definition at line 372 of file connection_impl.hpp.
References websocketpp::log::alevel::devel.
lib::error_code websocketpp::connection< config >::resume_reading | ( | ) |
Resume reading of new data.
Signals to the connection to resume reading of new data after it was paused by pause_reading()
.
If reading is not paused for this connection already nothing is changed.
Definition at line 378 of file connection_impl.hpp.
References websocketpp::log::alevel::devel.
void websocketpp::connection< config >::handle_resume_reading | ( | ) |
Resume reading callback.
Resume reading helper method. Not safe to call directly.
Definition at line 390 of file connection_impl.hpp.
void websocketpp::connection< config >::ping | ( | std::string const & | payload | ) |
Send a ping.
Initiates a ping with the given payload/
There is no feedback directly from ping except in cases of immediately detectable errors. Feedback will be provided via on_pong or on_pong_timeout callbacks.
Ping locks the m_write_lock mutex
payload | Payload to be used for the ping |
Definition at line 224 of file connection_impl.hpp.
References websocketpp::frame::opcode::ping.
void websocketpp::connection< config >::ping | ( | std::string const & | payload, |
lib::error_code & | ec | ||
) |
exception free variant of ping
Definition at line 155 of file connection_impl.hpp.
References websocketpp::log::alevel::devel, websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::error::no_outgoing_buffers, websocketpp::session::state::open, and websocketpp::log::elevel::warn.
void websocketpp::connection< config >::handle_pong_timeout | ( | std::string | payload, |
lib::error_code const & | ec | ||
) |
Utility method that gets called back when the ping timer expires.
Definition at line 233 of file connection_impl.hpp.
References websocketpp::log::elevel::devel, and websocketpp::transport::error::operation_aborted.
void websocketpp::connection< config >::pong | ( | std::string const & | payload | ) |
Send a pong.
Initiates a pong with the given payload.
There is no feedback from a pong once sent.
Pong locks the m_write_lock mutex
payload | Payload to be used for the pong |
Definition at line 295 of file connection_impl.hpp.
References websocketpp::frame::opcode::pong.
void websocketpp::connection< config >::pong | ( | std::string const & | payload, |
lib::error_code & | ec | ||
) |
exception free variant of pong
Definition at line 252 of file connection_impl.hpp.
References websocketpp::log::alevel::devel, websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::error::no_outgoing_buffers, and websocketpp::session::state::open.
void websocketpp::connection< config >::close | ( | close::status::value const | code, |
std::string const & | reason | ||
) |
Close the connection.
Initiates the close handshake process.
If close returns successfully the connection will be in the closing state and no additional messages may be sent. All messages sent prior to calling close will be written out before the connection is closed.
If no reason is specified none will be sent. If no code is specified then no code will be sent.
The handler's on_close callback will be called once the close handshake is complete.
Reasons will be automatically truncated to the maximum length (123 bytes) if necessary.
code | The close code to send |
reason | The close reason to send |
Definition at line 326 of file connection_impl.hpp.
References close().
void websocketpp::connection< config >::close | ( | close::status::value const | code, |
std::string const & | reason, | ||
lib::error_code & | ec | ||
) |
exception free variant of close
Definition at line 304 of file connection_impl.hpp.
References websocketpp::frame::limits::close_reason_size, websocketpp::log::alevel::devel, websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::session::state::open, and websocketpp::close::status::terminal().
bool websocketpp::connection< config >::get_secure | ( | ) | const |
Returns the secure flag from the connection URI.
This value is available after the HTTP request has been fully read and may be called from any thread.
Definition at line 406 of file connection_impl.hpp.
std::string const & websocketpp::connection< config >::get_host | ( | ) | const |
Returns the host component of the connection URI.
This value is available after the HTTP request has been fully read and may be called from any thread.
Definition at line 412 of file connection_impl.hpp.
std::string const & websocketpp::connection< config >::get_resource | ( | ) | const |
Returns the resource component of the connection URI.
This value is available after the HTTP request has been fully read and may be called from any thread.
Definition at line 418 of file connection_impl.hpp.
uint16_t websocketpp::connection< config >::get_port | ( | ) | const |
Returns the port component of the connection URI.
This value is available after the HTTP request has been fully read and may be called from any thread.
Definition at line 424 of file connection_impl.hpp.
uri_ptr websocketpp::connection< config >::get_uri | ( | ) | const |
Gets the connection URI.
This should really only be called by internal library methods unless you really know what you are doing.
Definition at line 430 of file connection_impl.hpp.
void websocketpp::connection< config >::set_uri | ( | uri_ptr | uri | ) |
Sets the connection URI.
This should really only be called by internal library methods unless you really know what you are doing.
uri | The new URI to set |
Definition at line 436 of file connection_impl.hpp.
std::string const & websocketpp::connection< config >::get_subprotocol | ( | ) | const |
Gets the negotated subprotocol.
Retrieves the subprotocol that was negotiated during the handshake. This method is valid in the open handler and later.
Definition at line 447 of file connection_impl.hpp.
std::vector< std::string > const & websocketpp::connection< config >::get_requested_subprotocols | ( | ) | const |
Gets all of the subprotocols requested by the client.
Retrieves the subprotocols that were requested during the handshake. This method is valid in the validate handler and later.
Definition at line 453 of file connection_impl.hpp.
void websocketpp::connection< config >::add_subprotocol | ( | std::string const & | request, |
lib::error_code & | ec | ||
) |
Adds the given subprotocol string to the request list (exception free)
Adds a subprotocol to the list to send with the opening handshake. This may be called multiple times to request more than one. If the server supports one of these, it may choose one. If so, it will return it in it's handshake reponse and the value will be available via get_subprotocol(). Subprotocol requests should be added in order of preference.
request | The subprotocol to request |
ec | A reference to an error code that will be filled in the case of errors |
Definition at line 458 of file connection_impl.hpp.
References websocketpp::error::client_only, websocketpp::error::invalid_subprotocol, websocketpp::http::is_not_token_char(), and websocketpp::error::make_error_code().
void websocketpp::connection< config >::add_subprotocol | ( | std::string const & | request | ) |
Adds the given subprotocol string to the request list.
Adds a subprotocol to the list to send with the opening handshake. This may be called multiple times to request more than one. If the server supports one of these, it may choose one. If so, it will return it in it's handshake reponse and the value will be available via get_subprotocol(). Subprotocol requests should be added in order of preference.
request | The subprotocol to request |
Definition at line 478 of file connection_impl.hpp.
void websocketpp::connection< config >::select_subprotocol | ( | std::string const & | value, |
lib::error_code & | ec | ||
) |
Select a subprotocol to use (exception free)
Indicates which subprotocol should be used for this connection. Valid only during the validate handler callback. Subprotocol selected must have been requested by the client. Consult get_requested_subprotocols() for a list of valid subprotocols.
This member function is valid on server endpoints/connections only
value | The subprotocol to select |
ec | A reference to an error code that will be filled in the case of errors |
Definition at line 488 of file connection_impl.hpp.
References websocketpp::error::make_error_code(), websocketpp::error::server_only, and websocketpp::error::unrequested_subprotocol.
void websocketpp::connection< config >::select_subprotocol | ( | std::string const & | value | ) |
Select a subprotocol to use.
Indicates which subprotocol should be used for this connection. Valid only during the validate handler callback. Subprotocol selected must have been requested by the client. Consult get_requested_subprotocols() for a list of valid subprotocols.
This member function is valid on server endpoints/connections only
value | The subprotocol to select |
Definition at line 516 of file connection_impl.hpp.
std::string const & websocketpp::connection< config >::get_request_header | ( | std::string const & | key | ) | const |
Retrieve a request header.
Retrieve the value of a header from the handshake HTTP request.
key | Name of the header to get |
Definition at line 527 of file connection_impl.hpp.
std::string const & websocketpp::connection< config >::get_request_body | ( | ) | const |
Retrieve a request body.
Retrieve the value of the request body. This value is typically used with PUT and POST requests to upload files or other data. Only HTTP connections will ever have bodies. WebSocket connection's will always have blank bodies.
Definition at line 533 of file connection_impl.hpp.
std::string const & websocketpp::connection< config >::get_response_header | ( | std::string const & | key | ) | const |
Retrieve a response header.
Retrieve the value of a header from the handshake HTTP request.
key | Name of the header to get |
Definition at line 539 of file connection_impl.hpp.
|
inline |
Get response HTTP status code.
Gets the response status code
Definition at line 983 of file connection.hpp.
|
inline |
Get response HTTP status message.
Gets the response status message
Definition at line 995 of file connection.hpp.
void websocketpp::connection< config >::set_status | ( | http::status_code::value | code | ) |
Set response status code and message.
Sets the response status code to code
and looks up the corresponding message for standard codes. Non-standard codes will be entered as Unknown use set_status(status_code::value,std::string) overload to set both values explicitly.
This member function is valid only from the http() and validate() handler callbacks.
code | Code to set |
msg | Message to set |
Definition at line 545 of file connection_impl.hpp.
References websocketpp::error::invalid_state, websocketpp::error::make_error_code(), and websocketpp::session::internal_state::PROCESS_HTTP_REQUEST.
Referenced by websocketpp::connection< config >::process_handshake_request().
void websocketpp::connection< config >::set_status | ( | http::status_code::value | code, |
std::string const & | msg | ||
) |
Set response status code and message.
Sets the response status code and message to independent custom values. use set_status(status_code::value) to set the code and have the standard message be automatically set.
This member function is valid only from the http() and validate() handler callbacks.
code | Code to set |
msg | Message to set |
Definition at line 556 of file connection_impl.hpp.
References websocketpp::error::invalid_state, websocketpp::error::make_error_code(), and websocketpp::session::internal_state::PROCESS_HTTP_REQUEST.
void websocketpp::connection< config >::set_body | ( | std::string const & | value | ) |
Set response body content.
Set the body content of the HTTP response to the parameter string. Note set_body will also set the Content-Length HTTP header to the appropriate value. If you want the Content-Length header to be something else set it to something else after calling set_body
This member function is valid only from the http() and validate() handler callbacks.
value | String data to include as the body content. |
Definition at line 569 of file connection_impl.hpp.
References websocketpp::error::invalid_state, websocketpp::error::make_error_code(), and websocketpp::session::internal_state::PROCESS_HTTP_REQUEST.
void websocketpp::connection< config >::append_header | ( | std::string const & | key, |
std::string const & | val | ||
) |
Append a header.
If a header with this name already exists the value will be appended to the existing header to form a comma separated list of values. Use connection::replace_header
to overwrite existing values.
This member function is valid only from the http() and validate() handler callbacks, or to a client connection before connect has been called.
key | Name of the header to set |
val | Value to add |
Definition at line 580 of file connection_impl.hpp.
References websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::session::internal_state::PROCESS_HTTP_REQUEST, and websocketpp::session::internal_state::USER_INIT.
void websocketpp::connection< config >::replace_header | ( | std::string const & | key, |
std::string const & | val | ||
) |
Replace a header.
If a header with this name already exists the old value will be replaced Use connection::append_header
to append to a list of existing values.
This member function is valid only from the http() and validate() handler callbacks, or to a client connection before connect has been called.
key | Name of the header to set |
val | Value to set |
Definition at line 604 of file connection_impl.hpp.
References websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::session::internal_state::PROCESS_HTTP_REQUEST, and websocketpp::session::internal_state::USER_INIT.
void websocketpp::connection< config >::remove_header | ( | std::string const & | key | ) |
Remove a header.
Removes a header from the response.
This member function is valid only from the http() and validate() handler callbacks, or to a client connection before connect has been called.
key | The name of the header to remove |
Definition at line 628 of file connection_impl.hpp.
References websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::session::internal_state::PROCESS_HTTP_REQUEST, and websocketpp::session::internal_state::USER_INIT.
|
inline |
Get request object.
Direct access to request object. This can be used to call methods of the request object that are not part of the standard request API that connection wraps.
Note use of this method involves using behavior specific to the configured HTTP policy. Such behavior may not work with alternate HTTP policies.
Definition at line 1102 of file connection.hpp.
|
inline |
Get response object.
Direct access to the HTTP response sent or received as a part of the opening handshake. This can be used to call methods of the response object that are not part of the standard request API that connection wraps.
Note use of this method involves using behavior specific to the configured HTTP policy. Such behavior may not work with alternate HTTP policies.
Definition at line 1121 of file connection.hpp.
lib::error_code websocketpp::connection< config >::defer_http_response | ( | ) |
Defer HTTP Response until later (Exception free)
Defer HTTP Response until later.
Used in the http handler to defer the HTTP response for this connection until later. Handshake timers will be canceled and the connection will be left open until send_http_response
or an equivalent is called.
Warning: deferred connections won't time out and as a result can tie up resources.
Used in the http handler to defer the HTTP response for this connection until later. Handshake timers will be canceled and the connection will be left open until send_http_response
or an equivalent is called.
Warning: deferred connections won't time out and as a result can tie up resources.
Definition at line 661 of file connection_impl.hpp.
References websocketpp::session::http_state::deferred.
void websocketpp::connection< config >::send_http_response | ( | lib::error_code & | ec | ) |
Send deferred HTTP Response (exception free)
Sends an http response to an HTTP connection that was deferred. This will send a complete response including all headers, status line, and body text. The connection will be closed afterwards.
ec | A status code, zero on success, non-zero otherwise |
Definition at line 686 of file connection_impl.hpp.
References websocketpp::session::http_state::body_written, websocketpp::session::http_state::deferred, websocketpp::error::invalid_state, and websocketpp::error::make_error_code().
void websocketpp::connection< config >::send_http_response | ( | ) |
Send deferred HTTP Response.
Definition at line 702 of file connection_impl.hpp.
|
inline |
Get Connection Handle.
The connection handle is a token that can be shared outside the WebSocket++ core for the purposes of identifying a connection and sending it messages.
Definition at line 1183 of file connection.hpp.
|
inline |
Get whether or not this connection is part of a server or client.
Definition at line 1191 of file connection.hpp.
Referenced by BOOST_AUTO_TEST_CASE().
std::string const & websocketpp::connection< config >::get_origin | ( | ) | const |
Return the same origin policy origin value from the opening request.
This value is available after the HTTP request has been fully read and may be called from any thread.
Definition at line 65 of file connection_impl.hpp.
session::state::value websocketpp::connection< config >::get_state | ( | ) | const |
Return the connection state.
Values can be connecting, open, closing, and closed
Definition at line 77 of file connection_impl.hpp.
|
inline |
Get the WebSocket close code sent by this endpoint.
Definition at line 1217 of file connection.hpp.
|
inline |
Get the WebSocket close reason sent by this endpoint.
Definition at line 1225 of file connection.hpp.
|
inline |
Get the WebSocket close code sent by the remote endpoint.
Definition at line 1233 of file connection.hpp.
|
inline |
Get the WebSocket close reason sent by the remote endpoint.
Definition at line 1241 of file connection.hpp.
|
inline |
Get the internal error code for a closed/failed connection.
Retrieves a machine readable detailed error code indicating the reason that the connection was closed or failed. Valid only after the close or fail handler is called.
Definition at line 1254 of file connection.hpp.
|
inline |
Get a message buffer.
Warning: The API related to directly sending message buffers may change before the 1.0 release. If you plan to use it, please keep an eye on any breaking changes notifications in future release notes. Also if you have any feedback about usage and capabilities now is a great time to provide it.
Message buffers are used to store message payloads and other message metadata.
The size parameter is a hint only. Your final payload does not need to match it. There may be some performance benefits if the initial size guess is equal to or slightly higher than the final payload size.
op | The opcode for the new message |
size | A hint to optimize the initial allocation of payload space. |
Definition at line 1277 of file connection.hpp.
void websocketpp::connection< config >::read_handshake | ( | size_t | num_bytes | ) |
Definition at line 774 of file connection_impl.hpp.
References websocketpp::config::core_client::connection_read_buffer_size, and websocketpp::log::alevel::devel.
void websocketpp::connection< config >::handle_read_handshake | ( | lib::error_code const & | ec, |
size_t | bytes_transferred | ||
) |
Definition at line 804 of file connection_impl.hpp.
References websocketpp::session::state::closed, websocketpp::session::state::connecting, websocketpp::config::core_client::connection_read_buffer_size, websocketpp::log::alevel::devel, websocketpp::transport::error::eof, websocketpp::log::elevel::fatal, websocketpp::error::general, websocketpp::error::http_parse_error, websocketpp::session::http_state::init, websocketpp::http::status_code::internal_server_error, websocketpp::error::invalid_state, websocketpp::http::exception::m_error_code, websocketpp::http::exception::m_error_msg, websocketpp::error::make_error_code(), websocketpp::processor::error::make_error_code(), websocketpp::session::internal_state::PROCESS_HTTP_REQUEST, websocketpp::session::internal_state::READ_HTTP_REQUEST, websocketpp::log::elevel::rerror, websocketpp::processor::error::short_key3, and websocketpp::utility::to_hex().
void websocketpp::connection< config >::handle_read_http_response | ( | lib::error_code const & | ec, |
size_t | bytes_transferred | ||
) |
Definition at line 1543 of file connection_impl.hpp.
References websocketpp::session::state::closed, websocketpp::session::state::connecting, websocketpp::config::core_client::connection_read_buffer_size, websocketpp::log::alevel::devel, websocketpp::transport::error::eof, websocketpp::error::extension_neg_failed, websocketpp::error::general, websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::session::state::open, websocketpp::session::internal_state::PROCESS_CONNECTION, websocketpp::session::internal_state::READ_HTTP_RESPONSE, websocketpp::log::elevel::rerror, and websocketpp::http::exception::what().
void websocketpp::connection< config >::handle_write_http_response | ( | lib::error_code const & | ec | ) |
Definition at line 1348 of file connection_impl.hpp.
References websocketpp::session::state::closed, websocketpp::session::state::connecting, websocketpp::log::alevel::devel, websocketpp::transport::error::eof, websocketpp::log::elevel::fatal, websocketpp::error::http_connection_ended, websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::session::state::open, websocketpp::session::internal_state::PROCESS_CONNECTION, websocketpp::session::internal_state::PROCESS_HTTP_REQUEST, websocketpp::log::elevel::rerror, and websocketpp::http::status_code::switching_protocols.
void websocketpp::connection< config >::handle_send_http_request | ( | lib::error_code const & | ec | ) |
Definition at line 1490 of file connection_impl.hpp.
References websocketpp::session::state::closed, websocketpp::session::state::connecting, websocketpp::config::core_client::connection_read_buffer_size, websocketpp::log::alevel::devel, websocketpp::transport::error::eof, websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::session::internal_state::READ_HTTP_RESPONSE, websocketpp::log::elevel::rerror, and websocketpp::session::internal_state::WRITE_HTTP_REQUEST.
void websocketpp::connection< config >::handle_open_handshake_timeout | ( | lib::error_code const & | ec | ) |
Definition at line 1663 of file connection_impl.hpp.
References websocketpp::log::alevel::devel, websocketpp::error::make_error_code(), websocketpp::error::open_handshake_timeout, and websocketpp::transport::error::operation_aborted.
void websocketpp::connection< config >::handle_close_handshake_timeout | ( | lib::error_code const & | ec | ) |
Definition at line 1679 of file connection_impl.hpp.
References websocketpp::error::close_handshake_timeout, websocketpp::log::alevel::devel, websocketpp::error::make_error_code(), and websocketpp::transport::error::operation_aborted.
void websocketpp::connection< config >::handle_read_frame | ( | lib::error_code const & | ec, |
size_t | bytes_transferred | ||
) |
Definition at line 965 of file connection_impl.hpp.
References websocketpp::transport::error::action_after_shutdown, close(), websocketpp::session::state::closed, websocketpp::session::state::closing, websocketpp::log::alevel::devel, websocketpp::config::core_client::drop_on_protocol_error, websocketpp::transport::error::eof, websocketpp::log::elevel::fatal, websocketpp::log::elevel::info, websocketpp::error::invalid_state, websocketpp::frame::opcode::is_control(), websocketpp::error::make_error_code(), websocketpp::session::state::open, websocketpp::session::internal_state::PROCESS_CONNECTION, websocketpp::log::elevel::rerror, websocketpp::transport::error::tls_short_read, websocketpp::utility::to_hex(), websocketpp::processor::error::to_ws(), and websocketpp::log::elevel::warn.
void websocketpp::connection< config >::read_frame | ( | ) |
Issue a new transport read unless reading is paused.
Definition at line 1113 of file connection_impl.hpp.
References websocketpp::config::core_client::connection_read_buffer_size.
std::vector< int > const & websocketpp::connection< config >::get_supported_versions | ( | ) | const |
Get array of WebSocket protocol versions that this connection supports.
Definition at line 1928 of file connection_impl.hpp.
References websocketpp::close::status::blank, websocketpp::frame::opcode::CLOSE, websocketpp::session::state::closed, websocketpp::session::state::closing, websocketpp::log::alevel::connect, websocketpp::log::alevel::control, websocketpp::log::elevel::devel, websocketpp::log::alevel::devel, websocketpp::log::alevel::disconnect, websocketpp::config::core_client::drop_on_protocol_error, websocketpp::close::extract_code(), websocketpp::close::extract_reason(), websocketpp::log::alevel::fail, websocketpp::processor::get_websocket_version(), websocketpp::log::alevel::http, websocketpp::processor::is_websocket_handshake(), websocketpp::error::make_error_code(), websocketpp::error::no_outgoing_buffers, websocketpp::close::status::no_status, websocketpp::close::status::normal, websocketpp::session::state::open, websocketpp::frame::opcode::PING, websocketpp::frame::opcode::pong, websocketpp::frame::opcode::PONG, websocketpp::close::status::protocol_error, websocketpp::connection< config >::set_max_message_size(), websocketpp::config::core_client::silent_close, websocketpp::utility::string_replace_all(), websocketpp::close::status::terminal(), websocketpp::http::parser::state::version, websocketpp::versions_supported(), and websocketpp::log::elevel::warn.
void websocketpp::connection< config >::set_termination_handler | ( | termination_handler | new_handler | ) |
Sets the handler for a terminating connection.
Should only be used internally by the endpoint class.
Definition at line 53 of file connection_impl.hpp.
References websocketpp::log::alevel::devel.
void websocketpp::connection< config >::terminate | ( | lib::error_code const & | ec | ) |
Definition at line 1695 of file connection_impl.hpp.
References websocketpp::close::status::abnormal_close, websocketpp::session::state::closed, websocketpp::session::http_state::closed, websocketpp::session::state::connecting, websocketpp::log::alevel::devel, websocketpp::error::http_connection_ended, and websocketpp::http::parser::body_encoding::unknown.
void websocketpp::connection< config >::handle_terminate | ( | terminate_status | tstat, |
lib::error_code const & | ec | ||
) |
Definition at line 1748 of file connection_impl.hpp.
References websocketpp::session::state::closed, websocketpp::log::elevel::devel, websocketpp::log::alevel::devel, websocketpp::error::http_connection_ended, websocketpp::log::elevel::rerror, and websocketpp::log::elevel::warn.
void websocketpp::connection< config >::write_frame | ( | ) |
Checks if there are frames in the send queue and if there are sends one.
This method locks the m_write_lock mutex
Definition at line 1790 of file connection_impl.hpp.
References websocketpp::log::alevel::frame_header, websocketpp::log::alevel::frame_payload, websocketpp::error::general, websocketpp::frame::opcode::text, and websocketpp::utility::to_hex().
void websocketpp::connection< config >::handle_write_frame | ( | lib::error_code const & | ec | ) |
Process the results of a frame write operation and start the next write.
This method locks the m_write_lock mutex
terminate | Whether or not to terminate the connection upon completion of this write. |
ec | A status code from the transport layer, zero on success, non-zero otherwise. |
Definition at line 1886 of file connection_impl.hpp.
References websocketpp::log::alevel::devel, websocketpp::log::elevel::fatal, and websocketpp::close::status::terminal().
void websocketpp::connection< config >::start | ( | ) |
Start the connection state machine.
Definition at line 716 of file connection_impl.hpp.
References websocketpp::log::alevel::devel, websocketpp::session::http_state::init, websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::session::internal_state::TRANSPORT_INIT, and websocketpp::session::internal_state::USER_INIT.
|
inline |
Set Connection Handle.
The connection handle is a token that can be shared outside the WebSocket++ core for the purposes of identifying a connection and sending it messages.
hdl | A connection_hdl that the connection will use to refer to itself. |
Definition at line 1356 of file connection.hpp.
|
protected |
Definition at line 740 of file connection_impl.hpp.
References websocketpp::config::core_client::client_version, websocketpp::log::alevel::devel, websocketpp::error::invalid_state, websocketpp::error::make_error_code(), websocketpp::session::internal_state::READ_HTTP_REQUEST, websocketpp::log::elevel::rerror, websocketpp::session::internal_state::TRANSPORT_INIT, and websocketpp::session::internal_state::WRITE_HTTP_REQUEST.
|
protected |
Set m_processor based on information in m_request.
Set m_response status and return an error code indicating status.
Definition at line 1134 of file connection_impl.hpp.
References websocketpp::http::status_code::bad_request, websocketpp::log::alevel::devel, websocketpp::processor::get_websocket_version(), websocketpp::error::invalid_version, websocketpp::processor::is_websocket_handshake(), websocketpp::error::make_error_code(), websocketpp::error::unsupported_version, websocketpp::http::parser::state::version, and websocketpp::versions_supported().
|
protected |
Perform WebSocket handshake validation of m_request using m_processor.
set m_response and return an error code indicating status.
Definition at line 1176 of file connection_impl.hpp.
References websocketpp::http::status_code::bad_request, websocketpp::session::state::closed, websocketpp::log::alevel::devel, websocketpp::error::general, websocketpp::processor::get_uri_from_host(), websocketpp::log::alevel::http, websocketpp::error::http_connection_ended, websocketpp::http::status_code::internal_server_error, websocketpp::error::invalid_uri, websocketpp::processor::is_websocket_handshake(), websocketpp::error::make_error_code(), websocketpp::error::rejected, websocketpp::connection< config >::set_status(), websocketpp::http::status_code::switching_protocols, websocketpp::utility::to_hex(), websocketpp::http::status_code::uninitialized, websocketpp::error::upgrade_required, and websocketpp::http::status_code::upgrade_required.