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

Server endpoint role based on the given config. More...

`#include <server_endpoint.hpp>`

Inheritance diagram for websocketpp::server< config >:

## Public Types

typedef server< config > | type
| Type of this endpoint.
typedef config::concurrency_type | concurrency_type
| Type of the endpoint concurrency component.
typedef config::transport_type | transport_type
| Type of the endpoint transport component.
typedef connection< config > | connection_type
| Type of the connections this server will create.
typedef connection_type::ptr | connection_ptr
| Type of a shared pointer to the connections this server will create.
typedef transport_type::transport_con_type | transport_con_type
| Type of the connection transport component.
typedef transport_con_type::ptr | transport_con_ptr
| Type of a shared pointer to the connection transport component.
typedef endpoint< connection_type, config > | endpoint_type
| Type of the endpoint component of this server.
typedef lib::function< void(lib::error_code const &, lib::error_code const &)> | accept_loop_handler
| The type and signature of the callback passed to the start_accept method.
Public Types inherited from websocketpp::endpoint< connection< config >, config >
typedef endpoint< connection, config > | type
typedef config::transport_type | transport_type
| Type of the transport component of this endpoint.
typedef config::concurrency_type | concurrency_type
| Type of the concurrency component of this endpoint.
typedef connection | connection_type
| Type of the connections that this endpoint creates.
typedef connection_type::ptr | connection_ptr
| Shared pointer to connection_type.
typedef connection_type::weak_ptr | connection_weak_ptr
| Weak pointer to connection type.
typedef transport_type::transport_con_type | transport_con_type
typedef transport_con_type::ptr | transport_con_ptr
typedef connection_type::message_handler | message_handler
| Type of message_handler.
typedef connection_type::message_ptr | message_ptr
| Type of message pointers that this endpoint uses.
typedef config::elog_type | elog_type
| Type of error logger.
typedef config::alog_type | alog_type
| Type of access logger.
typedef concurrency_type::scoped_lock_type | scoped_lock_type
| Type of our concurrency policy's scoped lock object.
typedef concurrency_type::mutex_type | mutex_type
| Type of our concurrency policy's mutex object.
typedef config::rng_type | rng_type
| Type of RNG.
typedef connection_type::termination_handler | termination_handler

## Public Member Functions

| ~server ()
| Destructor.
connection_ptr | get_connection ()
| Create and initialize a new connection.
connection_ptr | get_connection (lib::error_code &ec)
| Create and initialize a new connection.
void | start_accept (accept_loop_handler completion_handler)
| Starts the server's async connection acceptance loop (exception free).
*Starts the server s async connection acceptance | loop (exception) void start_accept()
*Handler callback for | start_accept (deprecated) void handle_accept_legacy(connection_ptr con
| start_accept (start_ec)
| if (start_ec==error::async_accept_not_listening)
else | if (start_ec)
*Handler callback for start_accept void | handle_accept (connection_ptr con, accept_loop_handler completion_handler, lib::error_code const &tec)
Public Member Functions inherited from websocketpp::endpoint< connection< config >, config >
| endpoint (bool p_is_server)
| ~endpoint ()
| Destructor.
std::string | get_user_agent () const
| Returns the user agent string that this endpoint will use.
void | set_user_agent (std::string const &ua)
| Sets the user agent string that this endpoint will use.
bool | is_server () const
| Returns whether or not this endpoint is a server.
void | set_access_channels (log::level channels)
| Set Access logging channel.
void | clear_access_channels (log::level channels)
| Clear Access logging channels.
void | set_error_channels (log::level channels)
| Set Error logging channel.
void | clear_error_channels (log::level channels)
| Clear Error logging channels.
alog_type & | get_alog ()
| Get reference to access logger.
elog_type & | get_elog ()
| Get reference to error logger.
void | set_open_handler (open_handler h)
void | set_close_handler (close_handler h)
void | set_fail_handler (fail_handler h)
void | set_ping_handler (ping_handler h)
void | set_pong_handler (pong_handler h)
void | set_pong_timeout_handler (pong_timeout_handler h)
void | set_interrupt_handler (interrupt_handler h)
void | set_http_handler (http_handler h)
void | set_validate_handler (validate_handler h)
void | set_message_handler (message_handler h)
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 default maximum message size.
void | set_max_message_size (size_t new_value)
| Set default 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.
void | interrupt (connection_hdl hdl, lib::error_code &ec)
void | pause_reading (connection_hdl hdl, lib::error_code &ec)
| Pause reading of new data (exception free).
void | resume_reading (connection_hdl hdl, lib::error_code &ec)
| Resume reading of new data (exception free).
void | send_http_response (connection_hdl hdl, lib::error_code &ec)
| Send deferred HTTP Response.
void | send (connection_hdl hdl, std::string const &payload, frame::opcode::value op, lib::error_code &ec)
| Create a message and add it to the outgoing send queue (exception free).
void | close (connection_hdl hdl, close::status::value const code, std::string const &reason, lib::error_code &ec)
void | ping (connection_hdl hdl, std::string const &payload, lib::error_code &ec)
| Send a ping to a specific connection.
void | pong (connection_hdl hdl, std::string const &payload, lib::error_code &ec)
| Send a pong to a specific connection.
connection_ptr | get_con_from_hdl (connection_hdl hdl, lib::error_code &ec)
| Retrieves a connection_ptr from a connection_hdl (exception free).

## Public Attributes

*Handler callback for lib::error_code const & | ec

## Friends

class | connection< config >

## Additional Inherited Members

Protected Member Functions inherited from websocketpp::endpoint< connection< config >, config >
connection_ptr | create_connection (lib::error_code &ec)
Protected Attributes inherited from websocketpp::endpoint< connection< config >, config >
lib::shared_ptr< alog_type > | m_alog
lib::shared_ptr< elog_type > | m_elog

## Detailed Description

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

Server endpoint role based on the given config.

Definition at line 44 of file server_endpoint.hpp.

## Member Typedef Documentation

## accept_loop_handler

template<typename config>

typedef lib::function<void(lib::error_code const &, lib::error_code const &)> websocketpp::server< config >::accept_loop_handler

The type and signature of the callback passed to the start_accept method.

Definition at line 68 of file server_endpoint.hpp.

## concurrency_type

template<typename config>

typedef config::concurrency_type websocketpp::server< config >::concurrency_type

Type of the endpoint concurrency component.

Definition at line 50 of file server_endpoint.hpp.

## connection_ptr

template<typename config>

typedef connection_type::ptr websocketpp::server< config >::connection_ptr

Type of a shared pointer to the connections this server will create.

Definition at line 57 of file server_endpoint.hpp.

## connection_type

template<typename config>

typedef connection<config> websocketpp::server< config >::connection_type

Type of the connections this server will create.

Definition at line 55 of file server_endpoint.hpp.

## endpoint_type

template<typename config>

typedef endpoint<connection_type,config> websocketpp::server< config >::endpoint_type

Type of the endpoint component of this server.

Definition at line 65 of file server_endpoint.hpp.

## transport_con_ptr

template<typename config>

typedef transport_con_type::ptr websocketpp::server< config >::transport_con_ptr

Type of a shared pointer to the connection transport component.

Definition at line 62 of file server_endpoint.hpp.

## transport_con_type

template<typename config>

typedef transport_type::transport_con_type websocketpp::server< config >::transport_con_type

Type of the connection transport component.

Definition at line 60 of file server_endpoint.hpp.

## transport_type

template<typename config>

typedef config::transport_type websocketpp::server< config >::transport_type

Type of the endpoint transport component.

Definition at line 52 of file server_endpoint.hpp.

## type

template<typename config>

typedef server<config> websocketpp::server< config >::type

Type of this endpoint.

Definition at line 47 of file server_endpoint.hpp.

## Constructor & Destructor Documentation

## server()

template<typename config>

websocketpp::server< config >::server | ( |  | ) |

inline explicit

Definition at line 72 of file server_endpoint.hpp.

## ~server()

template<typename config>

websocketpp::server< config >::~server | ( |  | ) |

inline

Destructor.

Definition at line 78 of file server_endpoint.hpp.

## Member Function Documentation

## get_connection() [1/2]

template<typename config>

connection_ptr websocketpp::server< config >::get_connection | ( |  | ) |

inline

Create and initialize a new connection.

The connection will be initialized and ready to begin. Call its start() method to begin the processing loop.

Note: The connection must either be started or terminated using connection::terminate in order to avoid memory leaks.

Deprecated
  0.9.0 use get_connection(lib::error_code &) instead.

See also
  get_connection(lib::error_code &) for an alternative that returns a detailed error code on failure.

Returns
  A pointer to the new connection.

Definition at line 114 of file server_endpoint.hpp.

## get_connection() [2/2]

template<typename config>

connection_ptr websocketpp::server< config >::get_connection | ( | lib::error_code & | ec | ) |

inline

Create and initialize a new connection.

The connection will be initialized and ready to begin. Call its start() method to begin the processing loop.

Note: The connection must either be started or terminated using connection::terminate in order to avoid memory leaks.

Since
  0.9.0

Parameters

  [out] | ec | A status code that indicates why the failure occurred if the returned pointer is blank.

Returns
  A pointer to the new connection.

Definition at line 133 of file server_endpoint.hpp.

## handle_accept()

template<typename config>

*Handler callback for start_accept void websocketpp::server< config >::handle_accept | ( | connection_ptr | con,
|  | accept_loop_handler | completion_handler,
|  | lib::error_code const & | tec )

inline

Definition at line 312 of file server_endpoint.hpp.

## if() [1/2]

template<typename config>

else websocketpp::server< config >::if | ( | start_ec |  | ) |

inline

Definition at line 305 of file server_endpoint.hpp.

## if() [2/2]

template<typename config>

websocketpp::server< config >::if | ( | start_ec | = = error::async_accept_not_listening | ) |

inline

Definition at line 302 of file server_endpoint.hpp.

## loop()

template<typename config>

*Starts the server s async connection acceptance websocketpp::server< config >::loop | ( | exception |  | ) |

inline

Initiates the server connection acceptance loop. Requires a transport policy that supports an asyncronous listen+accept loop. Must be called while the endpoint is listening (or start_accept will return immediately with an error that the server is not listening).

Consult the documentation for the underlying transport for information about exactly when this code will start running, when in the transport event loop it makes sense to call it, and for instructions on how to stop this acceptance loop.

Error handling: start_accept will throw an exception if there is a problem starting the accept loop. Once successfully started the loop will continue to renew itself after each connection. This method has no way of delivering that happen after the loop is started. Use start_accept(accept_loop_handler) instead to get full error information no matter when the async loop ends.

Deprecated
  use start_accept(accept_loop_handler) instead

Exceptions

  websocketpp::exception | If the accept loop fails to be set up.

Definition at line 252 of file server_endpoint.hpp.

## start_accept()

template<typename config>

void websocketpp::server< config >::start_accept | ( | accept_loop_handler | completion_handler | ) |

inline

Starts the server's async connection acceptance loop (exception free).

Initiates the server connection acceptance loop. Must be called after listen. This method will have no effect until the underlying io_context starts running. It may be called after the io_context is already running.

Refer to documentation for the transport policy you are using for instructions on how to stop this acceptance loop.

Error handling: start_accept will return an error via the ec parameter if there is a problem starting the accept loop. Once successfully started the loop will continue to renew itself after each connection. This method has no way of delivering that happen after the loop is started. Use start_accept(accept_loop_handler) instead to get full error information no matter when the async loop ends.

Deprecated
  use `start_accept(accept_loop_handler) instead

Parameters

  [out] | ec | A status code indicating an error, if any. */ void start_accept(lib::error_code & ec) { if (!transport_type::is_listening()) { ec = error::make_error_code(error::async_accept_not_listening); return; }

ec = lib::error_code(); connection_ptr con = get_connection(ec);

if (!con) { ec = error::make_error_code(error::con_creation_failed); return; }

transport_type::async_accept( lib::static_pointer_cast<transport_con_type>(con), lib::bind(&type::handle_accept_legacy,this,con,lib::placeholders::_1), ec );

if (ec && con) { If the connection was constructed but the accept failed, terminate the connection to prevent memory leaks con->terminate(lib::error_code()); } }

Starts the server's async connection acceptance loop (exception free) /** Initiates the server connection acceptance loop. Requires a transport policy that supports an asyncronous listen+accept loop. Must be called while the endpoint is listening (or start_accept will return immediately with an error that the server is not listening).

Consult the documentation for the underlying transport for information about exactly when this code will start running, when in the transport event loop it makes sense to call it, and for instructions on how to stop this acceptance loop.

Error handling: start_accept will attempt to start an asyncronous acceptance loop that accepts a connection and then re-issues a new accept command. If this loop ends or fails for any reason (including immediately) the completion_handler will be called with two status codes. The first is the library level status code the second is the underlying transport status code (if any).

Since
  0.9.0

Parameters

  completion_handler | A handler function to be called when the async accept loop ends.

Definition at line 209 of file server_endpoint.hpp.

## Friends And Related Symbol Documentation

## connection< config >

template<typename config>

friend class connection< config >

friend

Definition at line 68 of file server_endpoint.hpp.

## Member Data Documentation

## ec

template<typename config>

*Handler callback for lib::error_code const& websocketpp::server< config >::ec

Initial value:
{
if (ec) {
con->terminate(ec);
if (ec == error::operation_canceled) {
endpoint_type::m_elog->write(log::elevel::info,
"handle_accept error: "+ec.message());
} else {
endpoint_type::m_elog->write(log::elevel::rerror,
"handle_accept error: "+ec.message());
}
} else {
con->start();
}
lib::error_code start_ec
websocketpp::server
Server endpoint role based on the given config.
Definition server_endpoint.hpp:44
websocketpp::error::operation_canceled
@ operation_canceled
The requested operation was canceled.
Definition error.hpp:127
websocketpp::log::elevel::info
static level const info
Definition levels.hpp:69
websocketpp::log::elevel::rerror
static level const rerror
Definition levels.hpp:75

Definition at line 285 of file server_endpoint.hpp.

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

- websocketpp/roles/server_endpoint.hpp