Loading...
Searching...
No Matches
websocketpp::connection< config > Class Template Reference

Represents an individual WebSocket connection. More...

`#include <connection.hpp>`

Inheritance diagram for websocketpp::connection< config >:

## Public Types

typedef connection< config > | type
| Type of this connection.
typedef lib::shared_ptr< type > | ptr
| Type of a shared pointer to this connection.
typedef lib::weak_ptr< type > | weak_ptr
| Type of a weak pointer to this connection.
typedef config::concurrency_type | concurrency_type
| Type of the concurrency component of this connection.
typedef config::alog_type | alog_type
| Type of the access logging policy.
typedef config::elog_type | elog_type
| Type of the error logging policy.
typedef config::transport_type::transport_con_type | transport_con_type
| Type of the transport component of this connection.
typedef transport_con_type::ptr | transport_con_ptr
| Type of a shared pointer to the transport component of this connection.
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.
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.
typedef session::internal_state::value | istate_type

## Public Member Functions

| connection (bool p_is_server, std::string const &ua, const lib::shared_ptr< alog_type > &alog, const lib::shared_ptr< elog_type > &elog, rng_type &rng)
ptr | get_shared ()
| Get a shared pointer to this component.
void | set_open_handler (open_handler h)
| Set open handler.
void | set_close_handler (close_handler h)
| Set close handler.
void | set_fail_handler (fail_handler h)
| Set fail handler.
void | set_ping_handler (ping_handler h)
| Set ping handler.
void | set_pong_handler (pong_handler h)
| Set pong handler.
void | set_pong_timeout_handler (pong_timeout_handler h)
| Set pong timeout handler.
void | set_interrupt_handler (interrupt_handler h)
| Set interrupt handler.
void | set_http_handler (http_handler h)
| Set http handler.
void | set_validate_handler (validate_handler h)
| Set validate handler.
void | set_message_handler (message_handler h)
| Set message handler.
void | set_open_handshake_timeout (long dur)
| Set open handshake timeout.
void | set_close_handshake_timeout (long dur)
| Set close handshake timeout.
void | set_pong_timeout (long dur)
| Set pong timeout.
size_t | get_max_message_size () const
| Get maximum message size.
void | set_max_message_size (size_t new_value)
| Set maximum message size.
size_t | get_max_http_body_size () const
| Get maximum HTTP message body size.
void | set_max_http_body_size (size_t new_value)
| Set maximum HTTP message body size.
size_t | get_buffered_amount () const
| Get the size of the outgoing write buffer (in payload bytes).
size_t | buffered_amount () const
| Get the size of the outgoing write buffer (in payload bytes).
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.
lib::error_code | send (void const *payload, size_t len, frame::opcode::value op=frame::opcode::binary)
| Send a message (raw array overload).
lib::error_code | send (message_ptr msg)
| Add a message to the outgoing send queue.
lib::error_code | interrupt ()
| Asynchronously invoke handler::on_interrupt.
void | handle_interrupt ()
| Transport interrupt callback.
lib::error_code | pause_reading ()
| Pause reading of new data.
void | handle_pause_reading ()
| Pause reading callback.
lib::error_code | resume_reading ()
| Resume reading of new data.
void | handle_resume_reading ()
| Resume reading callback.
void | ping (std::string const &payload)
| Send a ping.
void | ping (std::string const &payload, lib::error_code &ec)
| exception free variant of ping
void | handle_pong_timeout (std::string payload, lib::error_code const &ec)
| Utility method that gets called back when the ping timer expires.
void | pong (std::string const &payload)
| Send a pong.
void | pong (std::string const &payload, lib::error_code &ec)
| exception free variant of pong
void | close (close::status::value const code, std::string const &reason)
| Close the connection.
void | close (close::status::value const code, std::string const &reason, lib::error_code &ec)
| exception free variant of close
bool | get_secure () const
| Returns the secure flag from the connection URI.
std::string const & | get_host () const
| Returns the host component of the connection URI.
std::string const & | get_resource () const
| Returns the resource component of the connection URI.
uint16_t | get_port () const
| Returns the port component of the connection URI.
uri_ptr | get_uri () const
| Gets the connection URI.
void | set_uri (uri_ptr uri)
| Sets the connection URI.
std::string const & | get_subprotocol () const
| Gets the negotiated subprotocol.
std::vector< std::string > const & | get_requested_subprotocols () const
| Gets all of the subprotocols requested by the client.
void | add_subprotocol (std::string const &request, lib::error_code &ec)
| Adds the given subprotocol string to the request list (exception free).
void | add_subprotocol (std::string const &request)
| Adds the given subprotocol string to the request list (exception).
void | select_subprotocol (std::string const &value, lib::error_code &ec)
| Select a subprotocol to use (exception free).
void | select_subprotocol (std::string const &value)
| Select a subprotocol to use (exception).
std::string const & | get_request_header (std::string const &key) const
| Retrieve a request header.
std::string const & | get_request_body () const
| Retrieve a request body.
std::string const & | get_response_header (std::string const &key) const
| Retrieve a response header.
http::status_code::value | get_response_code () const
| Get response HTTP status code.
std::string const & | get_response_msg () const
| Get response HTTP status message.
void | set_status (http::status_code::value code, lib::error_code &ec)
| Set response status code and message (exception free).
void | set_status (http::status_code::value code)
| Set response status code and message (exception).
void | set_status (http::status_code::value code, std::string const &msg, lib::error_code &ec)
| Set response status code and message (exception free).
void | set_status (http::status_code::value code, std::string const &msg)
| Set response status code and message (exception).
void | set_body (std::string const &value, lib::error_code &ec)
| Set response body content (exception free).
void | set_body (std::string const &value)
| Set response body content (exception).
void | append_header (std::string const &key, std::string const &val, lib::error_code &ec)
| Append a header (exception free).
void | append_header (std::string const &key, std::string const &val)
| Append a header (exception).
void | replace_header (std::string const &key, std::string const &val, lib::error_code &ec)
| Replace a header (exception free).
void | replace_header (std::string const &key, std::string const &val)
| Replace a header (exception).
void | remove_header (std::string const &key, lib::error_code &ec)
| Remove a header (exception free).
void | remove_header (std::string const &key)
| Remove a header (exception).
request_type const & | get_request () const
| Get request object.
response_type const & | get_response () const
| Get response object.
lib::error_code | defer_http_response ()
| Defer HTTP Response until later (Exception free).
void | send_http_response (lib::error_code &ec)
| Send deferred HTTP Response (exception free).
void | send_http_response ()
| Send deferred HTTP Response.
connection_hdl | get_handle () const
| Get Connection Handle.
bool | is_server () const
| Get whether or not this connection is part of a server or client.
std::string const & | get_origin () const
| Return the same origin policy origin value from the opening request.
session::state::value | get_state () const
| Return the connection state.
close::status::value | get_local_close_code () const
| Get the WebSocket close code sent by this endpoint.
std::string const & | get_local_close_reason () const
| Get the WebSocket close reason sent by this endpoint.
close::status::value | get_remote_close_code () const
| Get the WebSocket close code sent by the remote endpoint.
std::string const & | get_remote_close_reason () const
| Get the WebSocket close reason sent by the remote endpoint.
lib::error_code | get_ec () const
| Get the internal error code for a closed/failed connection.
message_ptr | get_message (websocketpp::frame::opcode::value op, size_t size) const
| Get a message buffer.
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.
std::vector< int > const & | get_supported_versions () const
| Get array of WebSocket protocol versions that this connection supports.
void | set_termination_handler (termination_handler new_handler)
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.
void | handle_write_frame (lib::error_code const &ec)
| Process the results of a frame write operation and start the next write.
void | start ()
| Start the connection state machine.
void | set_handle (connection_hdl hdl)
| Set Connection Handle.

## Protected Member Functions

void | handle_transport_init (lib::error_code const &ec)
lib::error_code | initialize_processor ()
lib::error_code | process_handshake_request ()

## Detailed Description

template<typename config>
class websocketpp::connection< config >

Represents an individual WebSocket connection.

Definition at line 235 of file connection.hpp.

## Member Typedef Documentation

## alog_type

template<typename config>

typedef config::alog_type websocketpp::connection< config >::alog_type

Type of the access logging policy.

Definition at line 250 of file connection.hpp.

## con_msg_manager_ptr

template<typename config>

typedef con_msg_manager_type::ptr websocketpp::connection< config >::con_msg_manager_ptr

Definition at line 272 of file connection.hpp.

## con_msg_manager_type

template<typename config>

typedef config::con_msg_manager_type websocketpp::connection< config >::con_msg_manager_type

Definition at line 271 of file connection.hpp.

## concurrency_type

template<typename config>

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.

## elog_type

template<typename config>

typedef config::elog_type websocketpp::connection< config >::elog_type

Type of the error logging policy.

Definition at line 252 of file connection.hpp.

## istate_type

template<typename config>

typedef session::internal_state::value websocketpp::connection< config >::istate_type

Definition at line 287 of file connection.hpp.

## message_handler

template<typename config>

typedef lib::function<void(connection_hdl,message_ptr)> websocketpp::connection< config >::message_handler

Definition at line 281 of file connection.hpp.

## message_ptr

template<typename config>

typedef message_type::ptr websocketpp::connection< config >::message_ptr

Definition at line 269 of file connection.hpp.

## message_type

template<typename config>

typedef config::message_type websocketpp::connection< config >::message_type

Definition at line 268 of file connection.hpp.

## mutex_type

template<typename config>

typedef concurrency_type::mutex_type websocketpp::connection< config >::mutex_type

Definition at line 263 of file connection.hpp.

## processor_ptr

template<typename config>

typedef lib::shared_ptr<processor_type> websocketpp::connection< config >::processor_ptr

Definition at line 278 of file connection.hpp.

## processor_type

template<typename config>

typedef processor::processor<config> websocketpp::connection< config >::processor_type

Definition at line 277 of file connection.hpp.

## ptr

template<typename config>

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.

## request_type

template<typename config>

typedef config::request_type websocketpp::connection< config >::request_type

Definition at line 265 of file connection.hpp.

## response_type

template<typename config>

typedef config::response_type websocketpp::connection< config >::response_type

Definition at line 266 of file connection.hpp.

## rng_type

template<typename config>

typedef config::rng_type websocketpp::connection< config >::rng_type

Type of RNG.

Definition at line 275 of file connection.hpp.

## scoped_lock_type

template<typename config>

typedef concurrency_type::scoped_lock_type websocketpp::connection< config >::scoped_lock_type

Definition at line 262 of file connection.hpp.

## termination_handler

template<typename config>

typedef lib::function<void(ptr)> websocketpp::connection< config >::termination_handler

Definition at line 260 of file connection.hpp.

## timer_ptr

template<typename config>

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.

## transport_con_ptr

template<typename config>

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.

## transport_con_type

template<typename config>

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.

## type

template<typename config>

typedef connection<config> websocketpp::connection< config >::type

Type of this connection.

Definition at line 241 of file connection.hpp.

## weak_ptr

template<typename config>

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.

## Constructor & Destructor Documentation

## connection()

template<typename config>

websocketpp::connection< config >::connection | ( | bool | p_is_server,
|  | std::string const & | ua,
|  | const lib::shared_ptr< alog_type > & | alog,
|  | const lib::shared_ptr< elog_type > & | elog,
|  | rng_type & | rng )

inline explicit

Definition at line 297 of file connection.hpp.

## Member Function Documentation

## add_subprotocol() [1/2]

template<typename config>

void websocketpp::connection< config >::add_subprotocol | ( | std::string const & | request | ) |

Adds the given subprotocol string to the request list (exception).

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 response and the value will be available via get_subprotocol(). Subprotocol requests should be added in order of preference.

Parameters

  [in] | request | The subprotocol to request

Definition at line 485 of file connection_impl.hpp.

## add_subprotocol() [2/2]

template<typename config>

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 response and the value will be available via get_subprotocol(). Subprotocol requests should be added in order of preference.

Parameters

  [in] | request | The subprotocol to request
  [out] | ec | A status code describing the outcome of the operation

Definition at line 464 of file connection_impl.hpp.

## append_header() [1/2]

template<typename config>

void websocketpp::connection< config >::append_header | ( | std::string const & | key,
|  | std::string const & | val )

Append a header (exception).

Set the value of a header in the handshake HTTP request or response. 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.

When can this member function be called?

- Servers: Valid from the http and validate handlers
- Clients: Valid before websocketpp::client::connect() has been called

Parameters

  [in] | key | Name of the header to set
  [in] | val | Value to add

Exceptions

  websocketpp::exception |

See also
  connection::replace_header
  websocketpp::http::parser::parser::append_header
  append_header(std::string const &, std::string const &, lib::error_code &) (exception free version)

Definition at line 673 of file connection_impl.hpp.

## append_header() [2/2]

template<typename config>

void websocketpp::connection< config >::append_header | ( | std::string const & | key,
|  | std::string const & | val,
|  | lib::error_code & | ec )

Append a header (exception free).

Set the value of a header in the handshake HTTP request or response. 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.

When can this member function be called?

- Servers: Valid from the http and validate handlers
- Clients: Valid before websocketpp::client::connect() has been called

Since
  0.9.0

Parameters

  [in] | key | Name of the header to set
  [in] | val | Value to add
  [out] | ec | A status code describing the outcome of the operation

See also
  connection::replace_header
  websocketpp::http::parser::parser::append_header
  append_header(std::string const &, std::string const &) (exception version)

Definition at line 651 of file connection_impl.hpp.

## buffered_amount()

template<typename config>

size_t websocketpp::connection< config >::buffered_amount | ( |  | ) | const

inline

Get the size of the outgoing write buffer (in payload bytes).

Deprecated
  use get_buffered_amount instead

Definition at line 635 of file connection.hpp.

## close() [1/2]

template<typename config>

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.

Parameters

  code | The close code to send
  reason | The close reason to send

Definition at line 331 of file connection_impl.hpp.

## close() [2/2]

template<typename config>

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 308 of file connection_impl.hpp.

## defer_http_response()

template<typename config>

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.

Since
  0.6.0

Returns
  A status code, zero on success, non-zero otherwise

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.

Returns
  A status code, zero on success, non-zero otherwise

Definition at line 763 of file connection_impl.hpp.

## get_buffered_amount()

template<typename config>

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

Returns
  The current number of bytes in the outgoing send buffer.

Definition at line 71 of file connection_impl.hpp.

## get_ec()

template<typename config>

lib::error_code websocketpp::connection< config >::get_ec | ( |  | ) | const

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.

Returns
  Error code indicating the reason the connection was closed or failed

Definition at line 1405 of file connection.hpp.

## get_handle()

template<typename config>

connection_hdl websocketpp::connection< config >::get_handle | ( |  | ) | const

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.

Returns
  A handle to the connection

Definition at line 1334 of file connection.hpp.

## get_host()

template<typename config>

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.

Returns
  The host component of the connection URI

Definition at line 418 of file connection_impl.hpp.

## get_local_close_code()

template<typename config>

close::status::value websocketpp::connection< config >::get_local_close_code | ( |  | ) | const

inline

Get the WebSocket close code sent by this endpoint.

Returns
  The WebSocket close code sent by this endpoint.

Definition at line 1368 of file connection.hpp.

## get_local_close_reason()

template<typename config>

std::string const & websocketpp::connection< config >::get_local_close_reason | ( |  | ) | const

inline

Get the WebSocket close reason sent by this endpoint.

Returns
  The WebSocket close reason sent by this endpoint.

Definition at line 1376 of file connection.hpp.

## get_max_http_body_size()

template<typename config>

size_t websocketpp::connection< config >::get_max_http_body_size | ( |  | ) | const

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.

Since
  0.5.0

Returns
  The maximum HTTP message body size

Definition at line 594 of file connection.hpp.

## get_max_message_size()

template<typename config>

size_t websocketpp::connection< config >::get_max_message_size | ( |  | ) | const

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.

Since
  0.3.0

Definition at line 559 of file connection.hpp.

## get_message()

template<typename config>

message_ptr websocketpp::connection< config >::get_message | ( | websocketpp::frame::opcode::value | op,
|  | size_t | size ) const

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.

Parameters

  op | The opcode for the new message
  size | A hint to optimize the initial allocation of payload space.

Returns
  A new message buffer

Definition at line 1428 of file connection.hpp.

## get_origin()

template<typename config>

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.

Returns
  The connection's origin value from the opening handshake.

Definition at line 65 of file connection_impl.hpp.

## get_port()

template<typename config>

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.

Returns
  The port component of the connection URI

Definition at line 430 of file connection_impl.hpp.

## get_remote_close_code()

template<typename config>

close::status::value websocketpp::connection< config >::get_remote_close_code | ( |  | ) | const

inline

Get the WebSocket close code sent by the remote endpoint.

Returns
  The WebSocket close code sent by the remote endpoint.

Definition at line 1384 of file connection.hpp.

## get_remote_close_reason()

template<typename config>

std::string const & websocketpp::connection< config >::get_remote_close_reason | ( |  | ) | const

inline

Get the WebSocket close reason sent by the remote endpoint.

Returns
  The WebSocket close reason sent by the remote endpoint.

Definition at line 1392 of file connection.hpp.

## get_request()

template<typename config>

request_type const & websocketpp::connection< config >::get_request | ( |  | ) | const

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.

Since
  0.3.0-alpha3

Returns
  A const reference to the raw request object

Definition at line 1253 of file connection.hpp.

## get_request_body()

template<typename config>

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.

Returns
  The value of the request body.

Definition at line 544 of file connection_impl.hpp.

## get_request_header()

template<typename config>

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.

Parameters

  [in] | key | Name of the header to get

Returns
  The value of the header

Definition at line 538 of file connection_impl.hpp.

## get_requested_subprotocols()

template<typename config>

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.

Returns
  A vector of the requested subprotocol

Definition at line 459 of file connection_impl.hpp.

## get_resource()

template<typename config>

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.

Returns
  The resource component of the connection URI

Definition at line 424 of file connection_impl.hpp.

## get_response()

template<typename config>

response_type const & websocketpp::connection< config >::get_response | ( |  | ) | const

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.

Since
  0.7.0

Returns
  A const reference to the raw response object

Definition at line 1272 of file connection.hpp.

## get_response_code()

template<typename config>

http::status_code::value websocketpp::connection< config >::get_response_code | ( |  | ) | const

inline

Get response HTTP status code.

Gets the response status code

Since
  0.7.0

Returns
  The response status code sent

Definition at line 981 of file connection.hpp.

## get_response_header()

template<typename config>

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.

Parameters

  [in] | key | Name of the header to get

Returns
  The value of the header

Definition at line 550 of file connection_impl.hpp.

## get_response_msg()

template<typename config>

std::string const & websocketpp::connection< config >::get_response_msg | ( |  | ) | const

inline

Get response HTTP status message.

Gets the response status message

Since
  0.7.0

Returns
  The response status message sent

Definition at line 993 of file connection.hpp.

## get_secure()

template<typename config>

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.

Returns
  Whether or not the connection URI is flagged secure.

Definition at line 412 of file connection_impl.hpp.

## get_shared()

template<typename config>

ptr websocketpp::connection< config >::get_shared | ( |  | ) |

inline

Get a shared pointer to this component.

Definition at line 336 of file connection.hpp.

## get_state()

template<typename config>

session::state::value websocketpp::connection< config >::get_state | ( |  | ) | const

Return the connection state.

Values can be connecting, open, closing, and closed

Returns
  The connection's current state.

Definition at line 77 of file connection_impl.hpp.

## get_subprotocol()

template<typename config>

std::string const & websocketpp::connection< config >::get_subprotocol | ( |  | ) | const

Gets the negotiated subprotocol.

Retrieves the subprotocol that was negotiated during the handshake. This method is valid in the open handler and later.

Returns
  The negotiated subprotocol

Definition at line 453 of file connection_impl.hpp.

## get_supported_versions()

template<typename config>

std::vector< int > const & websocketpp::connection< config >::get_supported_versions | ( |  | ) | const

Get array of WebSocket protocol versions that this connection supports.

Definition at line 2070 of file connection_impl.hpp.

## get_uri()

template<typename config>

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.

Returns
  A pointer to the connection's URI

Definition at line 436 of file connection_impl.hpp.

## handle_close_handshake_timeout()

template<typename config>

void websocketpp::connection< config >::handle_close_handshake_timeout | ( | lib::error_code const & | ec | ) |

Definition at line 1810 of file connection_impl.hpp.

## handle_interrupt()

template<typename config>

void websocketpp::connection< config >::handle_interrupt | ( |  | ) |

Transport interrupt callback.

Definition at line 359 of file connection_impl.hpp.

## handle_open_handshake_timeout()

template<typename config>

void websocketpp::connection< config >::handle_open_handshake_timeout | ( | lib::error_code const & | ec | ) |

Definition at line 1794 of file connection_impl.hpp.

## handle_pause_reading()

template<typename config>

void websocketpp::connection< config >::handle_pause_reading | ( |  | ) |

Pause reading callback.

Pause reading handler. Not safe to call directly.

Definition at line 378 of file connection_impl.hpp.

## handle_pong_timeout()

template<typename config>

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 235 of file connection_impl.hpp.

## handle_read_frame()

template<typename config>

void websocketpp::connection< config >::handle_read_frame | ( | lib::error_code const & | ec,
|  | size_t | bytes_transferred )

Definition at line 1080 of file connection_impl.hpp.

## handle_read_handshake()

template<typename config>

void websocketpp::connection< config >::handle_read_handshake | ( | lib::error_code const & | ec,
|  | size_t | bytes_transferred )

Definition at line 908 of file connection_impl.hpp.

## handle_read_http_response()

template<typename config>

void websocketpp::connection< config >::handle_read_http_response | ( | lib::error_code const & | ec,
|  | size_t | bytes_transferred )

Definition at line 1662 of file connection_impl.hpp.

## handle_resume_reading()

template<typename config>

void websocketpp::connection< config >::handle_resume_reading | ( |  | ) |

Resume reading callback.

Resume reading helper method. Not safe to call directly.

Definition at line 396 of file connection_impl.hpp.

## handle_send_http_request()

template<typename config>

void websocketpp::connection< config >::handle_send_http_request | ( | lib::error_code const & | ec | ) |

Definition at line 1609 of file connection_impl.hpp.

## handle_terminate()

template<typename config>

void websocketpp::connection< config >::handle_terminate | ( | terminate_status | tstat,
|  | lib::error_code const & | ec )

Definition at line 1885 of file connection_impl.hpp.

## handle_transport_init()

template<typename config>

void websocketpp::connection< config >::handle_transport_init | ( | lib::error_code const & | ec | ) |

protected

Definition at line 844 of file connection_impl.hpp.

## handle_write_frame()

template<typename config>

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.

Todo
  unit tests

This method locks the m_write_lock mutex

Parameters

  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 2028 of file connection_impl.hpp.

## handle_write_http_response()

template<typename config>

void websocketpp::connection< config >::handle_write_http_response | ( | lib::error_code const & | ec | ) |

Definition at line 1467 of file connection_impl.hpp.

## initialize_processor()

template<typename config>

lib::error_code websocketpp::connection< config >::initialize_processor | ( |  | ) |

protected

Set m_processor based on information in m_request. Set m_response status and return an error code indicating status.

Definition at line 1246 of file connection_impl.hpp.

## interrupt()

template<typename config>

lib::error_code websocketpp::connection< config >::interrupt | ( |  | ) |

Asynchronously invoke handler::on_interrupt.

Trigger the on_interrupt handler.

Signals to the connection to asynchronously invoke the on_interrupt callback for this connection's handler once it is safe to do so.

When the on_interrupt 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 interrupt signals can be active at once on the same connection

Returns
  An error code

This is thread safe if the transport is thread safe

Definition at line 347 of file connection_impl.hpp.

## is_server()

template<typename config>

bool websocketpp::connection< config >::is_server | ( |  | ) | const

inline

Get whether or not this connection is part of a server or client.

Returns
  whether or not the connection is attached to a server endpoint

Definition at line 1342 of file connection.hpp.

## pause_reading()

template<typename config>

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 366 of file connection_impl.hpp.

## ping() [1/2]

template<typename config>

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

Parameters

  payload | Payload to be used for the ping

Definition at line 225 of file connection_impl.hpp.

## ping() [2/2]

template<typename config>

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.

## pong() [1/2]

template<typename config>

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

Parameters

  payload | Payload to be used for the pong

Definition at line 298 of file connection_impl.hpp.

## pong() [2/2]

template<typename config>

void websocketpp::connection< config >::pong | ( | std::string const & | payload,
|  | lib::error_code & | ec )

exception free variant of pong

Definition at line 254 of file connection_impl.hpp.

## process_handshake_request()

template<typename config>

lib::error_code websocketpp::connection< config >::process_handshake_request | ( |  | ) |

protected

Perform WebSocket handshake validation of m_request using m_processor. set m_response and return an error code indicating status.

Definition at line 1288 of file connection_impl.hpp.

## read_frame()

template<typename config>

void websocketpp::connection< config >::read_frame | ( |  | ) |

Issue a new transport read unless reading is paused.

Definition at line 1225 of file connection_impl.hpp.

## read_handshake()

template<typename config>

void websocketpp::connection< config >::read_handshake | ( | size_t | num_bytes | ) |

Definition at line 878 of file connection_impl.hpp.

## remove_header() [1/2]

template<typename config>

void websocketpp::connection< config >::remove_header | ( | std::string const & | key | ) |

Remove a header (exception).

Removes a header from the handshake HTTP request or response.

When can this member function be called?

- Servers: Valid from the http and validate handlers
- Clients: Valid before websocketpp::client::connect() has been called

Parameters

  [in] | key | The name of the header to remove

Exceptions

  websocketpp::exception |

See also
  websocketpp::http::parser::parser::remove_header
  remove_header(std::string const &, lib::error_code &) (exception free version)

Definition at line 741 of file connection_impl.hpp.

## remove_header() [2/2]

template<typename config>

void websocketpp::connection< config >::remove_header | ( | std::string const & | key,
|  | lib::error_code & | ec )

Remove a header (exception free).

Removes a header from the handshake HTTP request or response.

When can this member function be called?

- Servers: Valid from the http and validate handlers
- Clients: Valid before websocketpp::client::connect() has been called

Parameters

  [in] | key | The name of the header to remove
  [out] | ec | A status code describing the outcome of the operation

See also
  websocketpp::http::parser::parser::remove_header
  remove_header(std::string const &) (exception version)

Definition at line 719 of file connection_impl.hpp.

## replace_header() [1/2]

template<typename config>

void websocketpp::connection< config >::replace_header | ( | std::string const & | key,
|  | std::string const & | val )

Replace a header (exception).

Set the value of a header in the handshake HTTP request or response. 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.

When can this member function be called?

- Servers: Valid from the http and validate handlers
- Clients: Valid before websocketpp::client::connect() has been called

Parameters

  [in] | key | Name of the header to set
  [in] | val | Value to set

Exceptions

  websocketpp::exception |

See also
  connection::append_header
  websocketpp::http::parser::parser::replace_header
  replace_header(std::string const & key, std::string const & val, lib::error_code & ec) (exception free version)

Definition at line 707 of file connection_impl.hpp.

## replace_header() [2/2]

template<typename config>

void websocketpp::connection< config >::replace_header | ( | std::string const & | key,
|  | std::string const & | val,
|  | lib::error_code & | ec )

Replace a header (exception free).

Set the value of a header in the handshake HTTP request or response. 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.

When can this member function be called?

- Servers: Valid from the http and validate handlers
- Clients: Valid before websocketpp::client::connect() has been called

Parameters

  [in] | key | Name of the header to set
  [in] | val | Value to set
  [out] | ec | A status code describing the outcome of the operation

See also
  connection::append_header
  websocketpp::http::parser::parser::replace_header
  replace_header(std::string const &, std::string const &) (exception version)

Definition at line 685 of file connection_impl.hpp.

## resume_reading()

template<typename config>

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 384 of file connection_impl.hpp.

## select_subprotocol() [1/2]

template<typename config>

void websocketpp::connection< config >::select_subprotocol | ( | std::string const & | value | ) |

Select a subprotocol to use (exception).

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

Parameters

  [in] | value | The subprotocol to select

Definition at line 526 of file connection_impl.hpp.

## select_subprotocol() [2/2]

template<typename config>

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

Parameters

  [in] | value | The subprotocol to select
  [out] | ec | A status code describing the outcome of the operation

Definition at line 496 of file connection_impl.hpp.

## send() [1/3]

template<typename config>

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

Todo
  make exception system_error rather than error_code

This method invokes the m_write_lock mutex

Parameters

  msg | A message_ptr to the message to send.

## send() [2/3]

template<typename config>

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

Parameters

  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.

## send() [3/3]

template<typename config>

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

Parameters

  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.

## send_http_response() [1/2]

template<typename config>

void websocketpp::connection< config >::send_http_response | ( |  | ) |

Send deferred HTTP Response.

Definition at line 805 of file connection_impl.hpp.

## send_http_response() [2/2]

template<typename config>

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.

Since
  0.6.0

Parameters

  ec | A status code, zero on success, non-zero otherwise

Definition at line 788 of file connection_impl.hpp.

## set_body() [1/2]

template<typename config>

void websocketpp::connection< config >::set_body | ( | std::string const & | value | ) |

Set response body content (exception).

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.

Parameters

  [in] | value | String data to include as the body content.

Exceptions

  websocketpp::exception |

See also
  websocketpp::http::response::set_body
  set_body(std::string const &, lib::error_code &) (exception free version)

Definition at line 616 of file connection_impl.hpp.

## set_body() [2/2]

template<typename config>

void websocketpp::connection< config >::set_body | ( | std::string const & | value,
|  | lib::error_code & | ec )

Set response body content (exception free).

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.

Since
  0.9.0

Parameters

  [in] | value | String data to include as the body content.
  [out] | ec | A status code describing the outcome of the operation

See also
  websocketpp::http::response::set_body
  set_body(std::string const &) (exception version)

Definition at line 603 of file connection_impl.hpp.

## set_close_handler()

template<typename config>

void websocketpp::connection< config >::set_close_handler | ( | close_handler | h | ) |

inline

Set close handler.

The close handler is called immediately after the connection is closed.

Parameters

  h | The new close_handler

Definition at line 361 of file connection.hpp.

## set_close_handshake_timeout()

template<typename config>

void websocketpp::connection< config >::set_close_handshake_timeout | ( | long | dur | ) |

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.

Parameters

  dur | The length of the close handshake timeout in ms

Definition at line 525 of file connection.hpp.

## set_fail_handler()

template<typename config>

void websocketpp::connection< config >::set_fail_handler | ( | fail_handler | h | ) |

inline

Set fail handler.

The fail handler is called whenever the connection fails while the handshake is bring processed.

Parameters

  h | The new fail_handler

Definition at line 372 of file connection.hpp.

## set_handle()

template<typename config>

void websocketpp::connection< config >::set_handle | ( | connection_hdl | hdl | ) |

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.

Parameters

  hdl | A connection_hdl that the connection will use to refer to itself.

Definition at line 1507 of file connection.hpp.

## set_http_handler()

template<typename config>

void websocketpp::connection< config >::set_http_handler | ( | http_handler | h | ) |

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.

Parameters

  h | The new http_handler

Definition at line 447 of file connection.hpp.

## set_interrupt_handler()

template<typename config>

void websocketpp::connection< config >::set_interrupt_handler | ( | interrupt_handler | h | ) |

inline

Set interrupt handler.

The interrupt handler is called whenever the connection is manually interrupted by the application.

Parameters

  h | The new interrupt_handler

Definition at line 432 of file connection.hpp.

## set_max_http_body_size()

template<typename config>

void websocketpp::connection< config >::set_max_http_body_size | ( | size_t | new_value | ) |

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.

Since
  0.5.0

Parameters

  new_value | The value to set as the maximum message size.

Definition at line 610 of file connection.hpp.

## set_max_message_size()

template<typename config>

void websocketpp::connection< config >::set_max_message_size | ( | size_t | new_value | ) |

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.

Since
  0.3.0

Parameters

  new_value | The value to set as the maximum message size.

Definition at line 575 of file connection.hpp.

## set_message_handler()

template<typename config>

void websocketpp::connection< config >::set_message_handler | ( | message_handler | h | ) |

inline

Set message handler.

The message handler is called after a new message has been received.

Parameters

  h | The new message_handler

Definition at line 473 of file connection.hpp.

## set_open_handler()

template<typename config>

void websocketpp::connection< config >::set_open_handler | ( | open_handler | h | ) |

inline

Set open handler.

The open handler is called after the WebSocket handshake is complete and the connection is considered OPEN.

Parameters

  h | The new open_handler

Definition at line 351 of file connection.hpp.

## set_open_handshake_timeout()

template<typename config>

void websocketpp::connection< config >::set_open_handshake_timeout | ( | long | dur | ) |

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.

Parameters

  dur | The length of the open handshake timeout in ms

Definition at line 501 of file connection.hpp.

## set_ping_handler()

template<typename config>

void websocketpp::connection< config >::set_ping_handler | ( | ping_handler | h | ) |

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.

Parameters

  h | The new ping_handler

Definition at line 387 of file connection.hpp.

## set_pong_handler()

template<typename config>

void websocketpp::connection< config >::set_pong_handler | ( | pong_handler | h | ) |

inline

Set pong handler.

The pong handler is called whenever the connection receives a pong control frame. The pong payload is included.

Parameters

  h | The new pong_handler

Definition at line 398 of file connection.hpp.

## set_pong_timeout()

template<typename config>

void websocketpp::connection< config >::set_pong_timeout | ( | long | dur | ) |

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.

Parameters

  dur | The length of the pong timeout in ms

Definition at line 546 of file connection.hpp.

## set_pong_timeout_handler()

template<typename config>

void websocketpp::connection< config >::set_pong_timeout_handler | ( | pong_timeout_handler | h | ) |

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.

Parameters

  h | The new pong_timeout_handler

Definition at line 421 of file connection.hpp.

## set_status() [1/4]

template<typename config>

void websocketpp::connection< config >::set_status | ( | http::status_code::value | code | ) |

Set response status code and message (exception).

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.

Parameters

  [in] | code | Code to set
  [in] | msg | Message to set

Exceptions

  websocketpp::exception |

See also
  websocketpp::http::parser::response::set_status()
  websocketpp::http::status_code::value (list of valid codes)

Definition at line 567 of file connection_impl.hpp.

## set_status() [2/4]

template<typename config>

void websocketpp::connection< config >::set_status | ( | http::status_code::value | code,
|  | lib::error_code & | ec )

Set response status code and message (exception free).

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.

Since
  0.9.0

Parameters

  [in] | code | Code to set
  [in] | msg | Message to set
  [out] | ec | A status code describing the outcome of the operation

See also
  websocketpp::http::parser::response::set_status
  websocketpp::http::status_code::value (list of valid codes)

Definition at line 555 of file connection_impl.hpp.

## set_status() [3/4]

template<typename config>

void websocketpp::connection< config >::set_status | ( | http::status_code::value | code,
|  | std::string const & | msg )

Set response status code and message (exception).

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.

Parameters

  [in] | code | Code to set
  [in] | msg | Message to set

Exceptions

  websocketpp::exception |

See also
  websocketpp::http::parser::response::set_status()
  websocketpp::http::status_code::value (list of valid codes)

Definition at line 591 of file connection_impl.hpp.

## set_status() [4/4]

template<typename config>

void websocketpp::connection< config >::set_status | ( | http::status_code::value | code,
|  | std::string const & | msg,
|  | lib::error_code & | ec )

Set response status code and message (exception free).

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.

Since
  0.9.0

Parameters

  [in] | code | Code to set
  [in] | msg | Message to set
  [out] | ec | A status code describing the outcome of the operation

See also
  websocketpp::http::response::set_status()
  websocketpp::http::status_code::value (list of valid codes)

Definition at line 578 of file connection_impl.hpp.

## set_termination_handler()

template<typename config>

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.

## set_uri()

template<typename config>

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.

Parameters

  uri | The new URI to set

Definition at line 442 of file connection_impl.hpp.

## set_validate_handler()

template<typename config>

void websocketpp::connection< config >::set_validate_handler | ( | validate_handler | h | ) |

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.

Parameters

  h | The new validate_handler

Definition at line 463 of file connection.hpp.

## start()

template<typename config>

void websocketpp::connection< config >::start | ( |  | ) |

Start the connection state machine.

Definition at line 820 of file connection_impl.hpp.

## terminate()

template<typename config>

void websocketpp::connection< config >::terminate | ( | lib::error_code const & | ec | ) |

Definition at line 1826 of file connection_impl.hpp.

## write_frame()

template<typename config>

void websocketpp::connection< config >::write_frame | ( |  | ) |

Checks if there are frames in the send queue and if there are sends one.

Todo
  unit tests

This method locks the m_write_lock mutex

Definition at line 1932 of file connection_impl.hpp.

The documentation for this class was generated from the following files:

- websocketpp/connection.hpp
- websocketpp/impl/connection_impl.hpp