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

Asio based connection transport component. More...

`#include <connection.hpp>`

Inheritance diagram for websocketpp::transport::asio::connection< config >:

## Public Types

typedef connection< config > | type
| Type of this connection transport component.
typedef lib::shared_ptr< type > | ptr
| Type of a shared pointer to this connection transport component.
typedef config::socket_type::socket_con_type | socket_con_type
| Type of the socket connection component.
typedef socket_con_type::ptr | socket_con_ptr
| Type of a shared pointer to the socket connection component.
typedef config::alog_type | alog_type
| Type of this transport's access logging policy.
typedef config::elog_type | elog_type
| Type of this transport's error logging policy.
typedef config::request_type | request_type
typedef request_type::ptr | request_ptr
typedef config::response_type | response_type
typedef response_type::ptr | response_ptr
typedef lib::asio::io_context * | io_context_ptr
| Type of a pointer to the Asio io_context being used.
typedef lib::shared_ptr< lib::asio::io_context::strand > | strand_ptr
| Type of a pointer to the Asio io_context::strand being used.
typedef lib::shared_ptr< lib::asio::steady_timer > | timer_ptr
| Type of a pointer to the Asio timer class.

## Public Member Functions

| connection (bool is_server, const lib::shared_ptr< alog_type > &alog, const lib::shared_ptr< elog_type > &elog)
ptr | get_shared ()
| Get a shared pointer to this component.
bool | is_secure () const
void | set_uri (uri_ptr u)
| Set uri hook.
void | set_tcp_pre_init_handler (tcp_init_handler h)
| Sets the tcp pre init handler.
void | set_tcp_init_handler (tcp_init_handler h)
| Sets the tcp pre init handler (deprecated).
void | set_tcp_post_init_handler (tcp_init_handler h)
| Sets the tcp post init handler.
void | set_proxy (std::string const &uri, lib::error_code &ec)
| Set the proxy to connect through (exception free).
void | set_proxy (std::string const &uri)
| Set the proxy to connect through (exception).
void | set_proxy_basic_auth (std::string const &username, std::string const &password, lib::error_code &ec)
| Set the basic auth credentials to use (exception free).
void | set_proxy_basic_auth (std::string const &username, std::string const &password)
| Set the basic auth credentials to use (exception).
void | set_proxy_timeout (long duration, lib::error_code &ec)
| Set the proxy timeout duration (exception free).
void | set_proxy_timeout (long duration)
| Set the proxy timeout duration (exception).
std::string const & | get_proxy () const
std::string | get_remote_endpoint () const
| Get the remote endpoint address.
connection_hdl | get_handle () const
| Get the connection handle.
timer_ptr | set_timer (long duration, timer_handler callback)
| Call back a function after a period of time.
void | handle_timer (timer_ptr, timer_handler callback, lib::asio::error_code const &ec)
| Timer callback.
strand_ptr | get_strand ()
| Get a pointer to this connection's strand.
lib::asio::error_code | get_transport_ec () const
| Get the internal transport error code for a closed/failed connection.

## Protected Member Functions

void | init (init_handler callback)
| Initialize transport for reading.
lib::error_code | proxy_init (std::string const &authority)
| initialize the proxy buffers and http parsers
lib::error_code | init_asio (io_context_ptr io_context)
| Finish constructing the transport.
void | handle_pre_init (init_handler callback, lib::error_code const &ec)
void | post_init (init_handler callback)
void | handle_post_init_timeout (timer_ptr, init_handler callback, lib::error_code const &ec)
| Post init timeout callback.
void | handle_post_init (timer_ptr post_timer, init_handler callback, lib::error_code const &ec)
| Post init timeout callback.
void | proxy_write (init_handler callback)
void | handle_proxy_timeout (init_handler callback, lib::error_code const &ec)
void | handle_proxy_write (init_handler callback, lib::asio::error_code const &ec)
void | proxy_read (init_handler callback)
void | handle_proxy_read (init_handler callback, lib::asio::error_code const &ec, size_t)
| Proxy read callback.
void | async_read_at_least (size_t num_bytes, char *buf, size_t len, read_handler handler)
| read at least num_bytes bytes into buf and then call handler.
void | handle_async_read (read_handler handler, lib::asio::error_code const &ec, size_t bytes_transferred)
void | async_write (const char *buf, size_t len, write_handler handler)
| Initiate a potentially asyncronous write of the given buffer.
void | async_write (std::vector< buffer > const &bufs, write_handler handler)
| Initiate a potentially asyncronous write of the given buffers.
void | handle_async_write (write_handler handler, lib::asio::error_code const &ec, size_t)
| Async write callback.
void | set_handle (connection_hdl hdl)
| Set Connection Handle.
lib::error_code | interrupt (interrupt_handler handler)
| Trigger the on_interrupt handler.
lib::error_code | dispatch (dispatch_handler handler)
void | async_shutdown (shutdown_handler callback)
| close and clean up the underlying socket
void | handle_async_shutdown_timeout (timer_ptr, init_handler callback, lib::error_code const &ec)
| Async shutdown timeout handler.
void | handle_async_shutdown (timer_ptr shutdown_timer, shutdown_handler callback, lib::asio::error_code const &ec)
void | cancel_socket_checked ()
| Cancel the underlying socket and log any errors.

## Friends

class | endpoint< config >

## Detailed Description

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

Asio based connection transport component.

transport::asio::connection implements a connection transport component using Asio that works with the transport::asio::endpoint endpoint transport component.

Definition at line 67 of file connection.hpp.

## Member Typedef Documentation

## alog_type

template<typename config>

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

Type of this transport's access logging policy.

Definition at line 79 of file connection.hpp.

## elog_type

template<typename config>

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

Type of this transport's error logging policy.

Definition at line 81 of file connection.hpp.

## io_context_ptr

template<typename config>

typedef lib::asio::io_context* websocketpp::transport::asio::connection< config >::io_context_ptr

Type of a pointer to the Asio io_context being used.

Definition at line 89 of file connection.hpp.

## ptr

template<typename config>

typedef lib::shared_ptr<type> websocketpp::transport::asio::connection< config >::ptr

Type of a shared pointer to this connection transport component.

Definition at line 72 of file connection.hpp.

## request_ptr

template<typename config>

typedef request_type::ptr websocketpp::transport::asio::connection< config >::request_ptr

Definition at line 84 of file connection.hpp.

## request_type

template<typename config>

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

Definition at line 83 of file connection.hpp.

## response_ptr

template<typename config>

typedef response_type::ptr websocketpp::transport::asio::connection< config >::response_ptr

Definition at line 86 of file connection.hpp.

## response_type

template<typename config>

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

Definition at line 85 of file connection.hpp.

## socket_con_ptr

template<typename config>

typedef socket_con_type::ptr websocketpp::transport::asio::connection< config >::socket_con_ptr

Type of a shared pointer to the socket connection component.

Definition at line 77 of file connection.hpp.

## socket_con_type

template<typename config>

typedef config::socket_type::socket_con_type websocketpp::transport::asio::connection< config >::socket_con_type

Type of the socket connection component.

Definition at line 75 of file connection.hpp.

## strand_ptr

template<typename config>

typedef lib::shared_ptr<lib::asio::io_context::strand> websocketpp::transport::asio::connection< config >::strand_ptr

Type of a pointer to the Asio io_context::strand being used.

Definition at line 91 of file connection.hpp.

## timer_ptr

template<typename config>

typedef lib::shared_ptr<lib::asio::steady_timer> websocketpp::transport::asio::connection< config >::timer_ptr

Type of a pointer to the Asio timer class.

Definition at line 93 of file connection.hpp.

## type

template<typename config>

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

Type of this connection transport component.

Definition at line 70 of file connection.hpp.

## Constructor & Destructor Documentation

## connection()

template<typename config>

websocketpp::transport::asio::connection< config >::connection | ( | bool | is_server,
|  | const lib::shared_ptr< alog_type > & | alog,
|  | const lib::shared_ptr< elog_type > & | elog )

inline explicit

Definition at line 101 of file connection.hpp.

## Member Function Documentation

## async_read_at_least()

template<typename config>

void websocketpp::transport::asio::connection< config >::async_read_at_least | ( | size_t | num_bytes,
|  | char * | buf,
|  | size_t | len,
|  | read_handler | handler )

inline protected

read at least num_bytes bytes into buf and then call handler.

Definition at line 835 of file connection.hpp.

## async_shutdown()

template<typename config>

void websocketpp::transport::asio::connection< config >::async_shutdown | ( | shutdown_handler | callback | ) |

inline protected

close and clean up the underlying socket

Definition at line 1054 of file connection.hpp.

## async_write() [1/2]

template<typename config>

void websocketpp::transport::asio::connection< config >::async_write | ( | const char * | buf,
|  | size_t | len,
|  | write_handler | handler )

inline protected

Initiate a potentially asyncronous write of the given buffer.

Definition at line 921 of file connection.hpp.

## async_write() [2/2]

template<typename config>

void websocketpp::transport::asio::connection< config >::async_write | ( | std::vector< buffer > const & | bufs,
|  | write_handler | handler )

inline protected

Initiate a potentially asyncronous write of the given buffers.

Definition at line 954 of file connection.hpp.

## cancel_socket_checked()

template<typename config>

void websocketpp::transport::asio::connection< config >::cancel_socket_checked | ( |  | ) |

inline protected

Cancel the underlying socket and log any errors.

Definition at line 1152 of file connection.hpp.

## dispatch()

template<typename config>

lib::error_code websocketpp::transport::asio::connection< config >::dispatch | ( | dispatch_handler | handler | ) |

inline protected

Definition at line 1040 of file connection.hpp.

## get_handle()

template<typename config>

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

inline

Get the connection handle.

Definition at line 301 of file connection.hpp.

## get_proxy()

template<typename config>

std::string const & websocketpp::transport::asio::connection< config >::get_proxy | ( |  | ) | const

inline

Definition at line 273 of file connection.hpp.

## get_remote_endpoint()

template<typename config>

std::string websocketpp::transport::asio::connection< config >::get_remote_endpoint | ( |  | ) | const

inline

Get the remote endpoint address.

The iostream transport has no information about the ultimate remote endpoint. It will return the string "iostream transport". To indicate this.

TODO: allow user settable remote endpoint addresses if this seems useful

Returns
  A string identifying the address of the remote endpoint

Definition at line 287 of file connection.hpp.

## get_shared()

template<typename config>

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

inline

Get a shared pointer to this component.

Definition at line 110 of file connection.hpp.

## get_strand()

template<typename config>

strand_ptr websocketpp::transport::asio::connection< config >::get_strand | ( |  | ) |

inline

Get a pointer to this connection's strand.

Definition at line 372 of file connection.hpp.

## get_transport_ec()

template<typename config>

lib::asio::error_code websocketpp::transport::asio::connection< config >::get_transport_ec | ( |  | ) | const

inline

Get the internal transport 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.

Primarily used if you are using mismatched asio / system_error implementations such as boost::asio with std::system_error. In these cases the transport error type is different than the library error type and some WebSocket++ functions that return transport errors via the library error code type will be coerced into a catch all pass_through or tls_error error. This method will return the original machine readable transport error in the native type.

Since
  0.7.0

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

Definition at line 395 of file connection.hpp.

## handle_async_read()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_async_read | ( | read_handler | handler,
|  | lib::asio::error_code const & | ec,
|  | size_t | bytes_transferred )

inline protected

Definition at line 886 of file connection.hpp.

## handle_async_shutdown()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_async_shutdown | ( | timer_ptr | shutdown_timer,
|  | shutdown_handler | callback,
|  | lib::asio::error_code const & | ec )

inline protected

Definition at line 1112 of file connection.hpp.

## handle_async_shutdown_timeout()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_async_shutdown_timeout | ( | timer_ptr | ,
|  | init_handler | callback,
|  | lib::error_code const & | ec )

inline protected

Async shutdown timeout handler.

Parameters

  shutdown_timer | A pointer to the timer to keep it in scope
  callback | The function to call back
  ec | The status code

Definition at line 1088 of file connection.hpp.

## handle_async_write()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_async_write | ( | write_handler | handler,
|  | lib::asio::error_code const & | ec,
|  | size_t | )

inline protected

Async write callback.

Parameters

  ec | The status code
  bytes_transferred | The number of bytes read

Definition at line 998 of file connection.hpp.

## handle_post_init()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_post_init | ( | timer_ptr | post_timer,
|  | init_handler | callback,
|  | lib::error_code const & | ec )

inline protected

Post init timeout callback.

The timer pointer is included to ensure the timer isn't destroyed until after it has expired.

Parameters

  post_timer | Pointer to the timer in question
  callback | The function to call back
  ec | The status code

Definition at line 578 of file connection.hpp.

## handle_post_init_timeout()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_post_init_timeout | ( | timer_ptr | ,
|  | init_handler | callback,
|  | lib::error_code const & | ec )

inline protected

Post init timeout callback.

The timer pointer is included to ensure the timer isn't destroyed until after it has expired.

Parameters

  post_timer | Pointer to the timer in question
  callback | The function to call back
  ec | The status code

Definition at line 542 of file connection.hpp.

## handle_pre_init()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_pre_init | ( | init_handler | callback,
|  | lib::error_code const & | ec )

inline protected

Definition at line 480 of file connection.hpp.

## handle_proxy_read()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_proxy_read | ( | init_handler | callback,
|  | lib::asio::error_code const & | ec,
|  | size_t | )

inline protected

Proxy read callback.

Parameters

  init_handler | The function to call back
  ec | The status code
  bytes_transferred | The number of bytes read

Definition at line 747 of file connection.hpp.

## handle_proxy_timeout()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_proxy_timeout | ( | init_handler | callback,
|  | lib::error_code const & | ec )

inline protected

Definition at line 657 of file connection.hpp.

## handle_proxy_write()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_proxy_write | ( | init_handler | callback,
|  | lib::asio::error_code const & | ec )

inline protected

Definition at line 674 of file connection.hpp.

## handle_timer()

template<typename config>

void websocketpp::transport::asio::connection< config >::handle_timer | ( | timer_ptr | ,
|  | timer_handler | callback,
|  | lib::asio::error_code const & | ec )

inline

Timer callback.

The timer pointer is included to ensure the timer isn't destroyed until after it has expired.

TODO: candidate for protected status

Parameters

  post_timer | Pointer to the timer in question
  callback | The function to call back
  ec | The status code

Definition at line 356 of file connection.hpp.

## init()

template<typename config>

void websocketpp::transport::asio::connection< config >::init | ( | init_handler | callback | ) |

inline protected

Initialize transport for reading.

init_asio is called once immediately after construction to initialize Asio components to the io_context

The transport initialization sequence consists of the following steps:

- Pre-init: the underlying socket is initialized to the point where bytes may be written. No bytes are actually written in this stage
- Proxy negotiation: if a proxy is set, a request is made to it to start a tunnel to the final destination. This stage ends when the proxy is ready to forward the next byte to the remote endpoint.
- Post-init: Perform any i/o with the remote endpoint, such as setting up tunnels for encryption. This stage ends when the connection is ready to read or write the WebSocket handshakes. At this point the original callback function is called.

Definition at line 417 of file connection.hpp.

## init_asio()

template<typename config>

lib::error_code websocketpp::transport::asio::connection< config >::init_asio | ( | io_context_ptr | io_context | ) |

inline protected

Finish constructing the transport.

init_asio is called once immediately after construction to initialize Asio components to the io_context.

Parameters

  io_context | A pointer to the io_context to register with this connection

Returns
  Status code for the success or failure of the initialization

Definition at line 467 of file connection.hpp.

## interrupt()

template<typename config>

lib::error_code websocketpp::transport::asio::connection< config >::interrupt | ( | interrupt_handler | handler | ) |

inline protected

Trigger the on_interrupt handler.

This needs to be thread safe

Definition at line 1031 of file connection.hpp.

## is_secure()

template<typename config>

bool websocketpp::transport::asio::connection< config >::is_secure | ( |  | ) | const

inline

Definition at line 114 of file connection.hpp.

## post_init()

template<typename config>

void websocketpp::transport::asio::connection< config >::post_init | ( | init_handler | callback | ) |

inline protected

Definition at line 502 of file connection.hpp.

## proxy_init()

template<typename config>

lib::error_code websocketpp::transport::asio::connection< config >::proxy_init | ( | std::string const & | authority | ) |

inline protected

initialize the proxy buffers and http parsers

Parameters

  authority | The address of the server we want the proxy to tunnel to in the format of a URI authority (host:port)

Returns
  Status code indicating what errors occurred, if any

Definition at line 443 of file connection.hpp.

## proxy_read()

template<typename config>

void websocketpp::transport::asio::connection< config >::proxy_read | ( | init_handler | callback | ) |

inline protected

Definition at line 704 of file connection.hpp.

## proxy_write()

template<typename config>

void websocketpp::transport::asio::connection< config >::proxy_write | ( | init_handler | callback | ) |

inline protected

Definition at line 603 of file connection.hpp.

## set_handle()

template<typename config>

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

inline protected

Set Connection Handle.

See common/connection_hdl.hpp for information

Parameters

  hdl | A connection_hdl that the transport will use to refer to itself

Definition at line 1022 of file connection.hpp.

## set_proxy() [1/2]

template<typename config>

void websocketpp::transport::asio::connection< config >::set_proxy | ( | std::string const & | uri | ) |

inline

Set the proxy to connect through (exception).

Definition at line 199 of file connection.hpp.

## set_proxy() [2/2]

template<typename config>

void websocketpp::transport::asio::connection< config >::set_proxy | ( | std::string const & | uri,
|  | lib::error_code & | ec )

inline

Set the proxy to connect through (exception free).

The URI passed should be a complete URI including scheme. For example: http://proxy.example.com:8080/

The proxy must be set up as an explicit (CONNECT) proxy allowed to connect to the port you specify. Traffic to the proxy is not encrypted.

Parameters

  uri | The full URI of the proxy to connect to.
  ec | A status value

Definition at line 189 of file connection.hpp.

## set_proxy_basic_auth() [1/2]

template<typename config>

void websocketpp::transport::asio::connection< config >::set_proxy_basic_auth | ( | std::string const & | username,
|  | std::string const & | password )

inline

Set the basic auth credentials to use (exception).

Definition at line 235 of file connection.hpp.

## set_proxy_basic_auth() [2/2]

template<typename config>

void websocketpp::transport::asio::connection< config >::set_proxy_basic_auth | ( | std::string const & | username,
|  | std::string const & | password,
|  | lib::error_code & | ec )

inline

Set the basic auth credentials to use (exception free).

The URI passed should be a complete URI including scheme. For example: http://proxy.example.com:8080/

The proxy must be set up as an explicit proxy

Parameters

  username | The username to send
  password | The password to send
  ec | A status value

Definition at line 219 of file connection.hpp.

## set_proxy_timeout() [1/2]

template<typename config>

void websocketpp::transport::asio::connection< config >::set_proxy_timeout | ( | long | duration | ) |

inline

Set the proxy timeout duration (exception).

Definition at line 266 of file connection.hpp.

## set_proxy_timeout() [2/2]

template<typename config>

void websocketpp::transport::asio::connection< config >::set_proxy_timeout | ( | long | duration,
|  | lib::error_code & | ec )

inline

Set the proxy timeout duration (exception free).

Duration is in milliseconds. Default value is based on the transport config

Parameters

  duration | The number of milliseconds to wait before aborting the proxy connection.
  ec | A status value

Definition at line 254 of file connection.hpp.

## set_tcp_init_handler()

template<typename config>

void websocketpp::transport::asio::connection< config >::set_tcp_init_handler | ( | tcp_init_handler | h | ) |

inline

Sets the tcp pre init handler (deprecated).

The tcp pre init handler is called after the raw tcp connection has been established but before any additional wrappers (proxy connects, TLS handshakes, etc) have been performed.

Deprecated
  Use set_tcp_pre_init_handler instead

Parameters

  h | The handler to call on tcp pre init.

Definition at line 158 of file connection.hpp.

## set_tcp_post_init_handler()

template<typename config>

void websocketpp::transport::asio::connection< config >::set_tcp_post_init_handler | ( | tcp_init_handler | h | ) |

inline

Sets the tcp post init handler.

The tcp post init handler is called after the tcp connection has been established and all additional wrappers (proxy connects, TLS handshakes, etc have been performed. This is fired before any bytes are read or any WebSocket specific handshake logic has been performed.

Since
  0.3.0

Parameters

  h | The handler to call on tcp post init.

Definition at line 173 of file connection.hpp.

## set_tcp_pre_init_handler()

template<typename config>

void websocketpp::transport::asio::connection< config >::set_tcp_pre_init_handler | ( | tcp_init_handler | h | ) |

inline

Sets the tcp pre init handler.

The tcp pre init handler is called after the raw tcp connection has been established but before any additional wrappers (proxy connects, TLS handshakes, etc) have been performed.

Since
  0.3.0

Parameters

  h | The handler to call on tcp pre init.

Definition at line 144 of file connection.hpp.

## set_timer()

template<typename config>

timer_ptr websocketpp::transport::asio::connection< config >::set_timer | ( | long | duration,
|  | timer_handler | callback )

inline

Call back a function after a period of time.

Sets a timer that calls back a function after the specified period of milliseconds. Returns a handle that can be used to cancel the timer. A cancelled timer will return the error code error::operation_aborted A timer that expired will return no error.

Parameters

  duration | Length of time to wait in milliseconds
  callback | The function to call back when the timer has expired

Returns
  A handle that can be used to cancel the timer if it is no longer needed.

Definition at line 319 of file connection.hpp.

## set_uri()

template<typename config>

void websocketpp::transport::asio::connection< config >::set_uri | ( | uri_ptr | u | ) |

inline

Set uri hook.

Called by the endpoint as a connection is being established to provide the uri being connected to to the transport layer.

This transport policy doesn't use the uri except to forward it to the socket layer.

Since
  0.6.0

Parameters

  u | The uri to set

Definition at line 130 of file connection.hpp.

## Friends And Related Symbol Documentation

## endpoint< config >

template<typename config>

friend class endpoint< config >

friend

Definition at line 93 of file connection.hpp.

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

- websocketpp/transport/asio/connection.hpp