Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
websocketpp::transport::asio::endpoint< config > Class Template Reference

Asio based endpoint transport component. More...

#include <endpoint.hpp>

Inheritance diagram for websocketpp::transport::asio::endpoint< config >:
Collaboration diagram for websocketpp::transport::asio::endpoint< config >:

Public Types

typedef endpoint< configtype
 Type of this endpoint transport component.
 
typedef config::concurrency_type concurrency_type
 Type of the concurrency policy.
 
typedef config::socket_type socket_type
 Type of the socket policy.
 
typedef config::elog_type elog_type
 Type of the error logging policy.
 
typedef config::alog_type alog_type
 Type of the access logging policy.
 
typedef 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 asio::connection< configtransport_con_type
 
typedef transport_con_type::ptr transport_con_ptr
 
typedef lib::asio::io_service * io_service_ptr
 Type of a pointer to the ASIO io_service being used.
 
typedef lib::shared_ptr< lib::asio::ip::tcp::acceptor > acceptor_ptr
 Type of a shared pointer to the acceptor being used.
 
typedef lib::shared_ptr< lib::asio::ip::tcp::resolver > resolver_ptr
 Type of a shared pointer to the resolver being used.
 
typedef lib::shared_ptr< lib::asio::steady_timertimer_ptr
 Type of timer handle.
 
typedef lib::shared_ptr< lib::asio::io_service::work > work_ptr
 Type of a shared pointer to an io_service work object.
 

Public Member Functions

 endpoint ()
 
 ~endpoint ()
 
bool is_secure () const
 Return whether or not the endpoint produces secure connections.
 
void init_asio (io_service_ptr ptr, lib::error_code &ec)
 initialize asio transport with external io_service (exception free)
 
void init_asio (io_service_ptr ptr)
 initialize asio transport with external io_service
 
void init_asio (lib::error_code &ec)
 Initialize asio transport with internal io_service (exception free)
 
void init_asio ()
 Initialize asio transport with internal io_service.
 
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_listen_backlog (int backlog)
 Sets the maximum length of the queue of pending connections.
 
void set_reuse_addr (bool value)
 Sets whether to use the SO_REUSEADDR flag when opening listening sockets.
 
lib::asio::io_service & get_io_service ()
 Retrieve a reference to the endpoint's io_service.
 
lib::asio::ip::tcp::endpoint get_local_endpoint (lib::asio::error_code &ec)
 Get local TCP endpoint.
 
void listen (lib::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
 Set up endpoint for listening manually (exception free)
 
void listen (lib::asio::ip::tcp::endpoint const &ep)
 Set up endpoint for listening manually.
 
template<typename InternetProtocol >
void listen (InternetProtocol const &internet_protocol, uint16_t port, lib::error_code &ec)
 Set up endpoint for listening with protocol and port (exception free)
 
template<typename InternetProtocol >
void listen (InternetProtocol const &internet_protocol, uint16_t port)
 Set up endpoint for listening with protocol and port.
 
void listen (uint16_t port, lib::error_code &ec)
 Set up endpoint for listening on a port (exception free)
 
void listen (uint16_t port)
 Set up endpoint for listening on a port.
 
void listen (std::string const &host, std::string const &service, lib::error_code &ec)
 Set up endpoint for listening on a host and service (exception free)
 
void listen (std::string const &host, std::string const &service)
 Set up endpoint for listening on a host and service.
 
void stop_listening (lib::error_code &ec)
 Stop listening (exception free)
 
void stop_listening ()
 Stop listening.
 
bool is_listening () const
 Check if the endpoint is listening.
 
std::size_t run ()
 wraps the run method of the internal io_service object
 
std::size_t run_one ()
 wraps the run_one method of the internal io_service object
 
void stop ()
 wraps the stop method of the internal io_service object
 
std::size_t poll ()
 wraps the poll method of the internal io_service object
 
std::size_t poll_one ()
 wraps the poll_one method of the internal io_service object
 
void reset ()
 wraps the reset method of the internal io_service object
 
bool stopped () const
 wraps the stopped method of the internal io_service object
 
void start_perpetual ()
 Marks the endpoint as perpetual, stopping it from exiting when empty.
 
void stop_perpetual ()
 Clears the endpoint's perpetual flag, allowing it to exit when empty.
 
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 handler.
 
void async_accept (transport_con_ptr tcon, accept_handler callback, lib::error_code &ec)
 Accept the next connection attempt and assign it to con (exception free)
 
void async_accept (transport_con_ptr tcon, accept_handler callback)
 Accept the next connection attempt and assign it to con.
 

Protected Member Functions

void init_logging (alog_type *a, elog_type *e)
 Initialize logging.
 
void handle_accept (accept_handler callback, lib::asio::error_code const &asio_ec)
 
void async_connect (transport_con_ptr tcon, uri_ptr u, connect_handler cb)
 Initiate a new connection.
 
void handle_resolve_timeout (timer_ptr, connect_handler callback, lib::error_code const &ec)
 DNS resolution timeout handler.
 
void handle_resolve (transport_con_ptr tcon, timer_ptr dns_timer, connect_handler callback, lib::asio::error_code const &ec, lib::asio::ip::tcp::resolver::iterator iterator)
 
void handle_connect_timeout (transport_con_ptr tcon, timer_ptr, connect_handler callback, lib::error_code const &ec)
 Asio connect timeout handler.
 
void handle_connect (transport_con_ptr tcon, timer_ptr con_timer, connect_handler callback, lib::asio::error_code const &ec)
 
lib::error_code init (transport_con_ptr tcon)
 Initialize a connection.
 

Detailed Description

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

transport::asio::endpoint implements an endpoint transport component using Asio.

Definition at line 53 of file endpoint.hpp.

Member Typedef Documentation

◆ acceptor_ptr

template<typename config >
lib::shared_ptr<lib::asio::ip::tcp::acceptor> websocketpp::transport::asio::endpoint< config >::acceptor_ptr

Definition at line 82 of file endpoint.hpp.

◆ alog_type

template<typename config >
config::alog_type websocketpp::transport::asio::endpoint< config >::alog_type

Definition at line 65 of file endpoint.hpp.

◆ concurrency_type

template<typename config >
config::concurrency_type websocketpp::transport::asio::endpoint< config >::concurrency_type

Definition at line 59 of file endpoint.hpp.

◆ elog_type

template<typename config >
config::elog_type websocketpp::transport::asio::endpoint< config >::elog_type

Definition at line 63 of file endpoint.hpp.

◆ io_service_ptr

template<typename config >
lib::asio::io_service* websocketpp::transport::asio::endpoint< config >::io_service_ptr

Definition at line 80 of file endpoint.hpp.

◆ resolver_ptr

template<typename config >
lib::shared_ptr<lib::asio::ip::tcp::resolver> websocketpp::transport::asio::endpoint< config >::resolver_ptr

Definition at line 84 of file endpoint.hpp.

◆ socket_con_ptr

template<typename config >
socket_con_type::ptr websocketpp::transport::asio::endpoint< config >::socket_con_ptr

Definition at line 70 of file endpoint.hpp.

◆ socket_con_type

template<typename config >
socket_type::socket_con_type websocketpp::transport::asio::endpoint< config >::socket_con_type

Definition at line 68 of file endpoint.hpp.

◆ socket_type

template<typename config >
config::socket_type websocketpp::transport::asio::endpoint< config >::socket_type

Definition at line 61 of file endpoint.hpp.

◆ timer_ptr

template<typename config >
lib::shared_ptr<lib::asio::steady_timer> websocketpp::transport::asio::endpoint< config >::timer_ptr

Definition at line 86 of file endpoint.hpp.

◆ transport_con_ptr

template<typename config >
transport_con_type::ptr websocketpp::transport::asio::endpoint< config >::transport_con_ptr

Type of a shared pointer to the connection transport component associated with this endpoint transport component

Definition at line 77 of file endpoint.hpp.

◆ transport_con_type

template<typename config >
asio::connection<config> websocketpp::transport::asio::endpoint< config >::transport_con_type

Type of the connection transport component associated with this endpoint transport component

Definition at line 74 of file endpoint.hpp.

◆ type

Definition at line 56 of file endpoint.hpp.

◆ work_ptr

template<typename config >
lib::shared_ptr<lib::asio::io_service::work> websocketpp::transport::asio::endpoint< config >::work_ptr

Definition at line 88 of file endpoint.hpp.

Constructor & Destructor Documentation

◆ endpoint()

template<typename config >
websocketpp::transport::asio::endpoint< config >::endpoint ( )
inlineexplicit

Definition at line 91 of file endpoint.hpp.

92 : m_io_service(NULL)
93 , m_external_io_service(false)
94 , m_listen_backlog(lib::asio::socket_base::max_connections)
95 , m_reuse_addr(false)
96 , m_state(UNINITIALIZED)
97 {
98 //std::cout << "transport::asio::endpoint constructor" << std::endl;
99 }

◆ ~endpoint()

template<typename config >
websocketpp::transport::asio::endpoint< config >::~endpoint ( )
inline

Definition at line 101 of file endpoint.hpp.

101 {
102 // clean up our io_service if we were initialized with an internal one.
103
104 // Explicitly destroy local objects
105 m_acceptor.reset();
106 m_resolver.reset();
107 m_work.reset();
108 if (m_state != UNINITIALIZED && !m_external_io_service) {
109 delete m_io_service;
110 }
111 }

Member Function Documentation

◆ async_accept() [1/2]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::async_accept ( transport_con_ptr tcon,
accept_handler callback )
inline
Parameters
tconThe connection to accept into.
callbackThe function to call when the operation is complete.

Definition at line 779 of file endpoint.hpp.

779 {
780 lib::error_code ec;
781 async_accept(tcon,callback,ec);
782 if (ec) { throw exception(ec); }
783 }
void async_accept(transport_con_ptr tcon, accept_handler callback, lib::error_code &ec)
Accept the next connection attempt and assign it to con (exception free)
Definition endpoint.hpp:740
Here is the call graph for this function:

◆ async_accept() [2/2]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::async_accept ( transport_con_ptr tcon,
accept_handler callback,
lib::error_code & ec )
inline
Parameters
tconThe connection to accept into.
callbackThe function to call when the operation is complete.
ecA status code indicating an error, if any.

Definition at line 740 of file endpoint.hpp.

742 {
743 if (m_state != LISTENING) {
746 return;
747 }
748
749 m_alog->write(log::alevel::devel, "asio::async_accept");
750
751 if (config::enable_multithreading) {
752 m_acceptor->async_accept(
753 tcon->get_raw_socket(),
754 tcon->get_strand()->wrap(lib::bind(
756 this,
757 callback,
758 lib::placeholders::_1
759 ))
760 );
761 } else {
762 m_acceptor->async_accept(
763 tcon->get_raw_socket(),
764 lib::bind(
766 this,
767 callback,
768 lib::placeholders::_1
769 )
770 );
771 }
772 }
void handle_accept(accept_handler callback, lib::asio::error_code const &asio_ec)
Definition endpoint.hpp:800
lib::error_code make_error_code(error::value e)
Definition error.hpp:235
static level const devel
Development messages (warning: very chatty)
Definition levels.hpp:141
Here is the call graph for this function:
Here is the caller graph for this function:

◆ async_connect()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::async_connect ( transport_con_ptr tcon,
uri_ptr u,
connect_handler cb )
inlineprotected

Definition at line 821 of file endpoint.hpp.

821 {
822 using namespace lib::asio::ip;
823
824 // Create a resolver
825 if (!m_resolver) {
826 m_resolver = lib::make_shared<lib::asio::ip::tcp::resolver>(*m_io_service);
827 }
828
829 tcon->set_uri(u);
830
831 std::string proxy = tcon->get_proxy();
832 std::string host;
833 std::string port;
834
835 if (proxy.empty()) {
836 host = u->get_host();
837 port = u->get_port_str();
838 } else {
839 lib::error_code ec;
840
841 uri_ptr pu = lib::make_shared<uri>(proxy);
842
843 if (!pu->get_valid()) {
844 cb(make_error_code(error::proxy_invalid));
845 return;
846 }
847
848 ec = tcon->proxy_init(u->get_authority());
849 if (ec) {
850 cb(ec);
851 return;
852 }
853
854 host = pu->get_host();
855 port = pu->get_port_str();
856 }
857
858 tcp::resolver::query query(host,port);
859
860 if (m_alog->static_test(log::alevel::devel)) {
861 m_alog->write(log::alevel::devel,
862 "starting async DNS resolve for "+host+":"+port);
863 }
864
865 timer_ptr dns_timer;
866
867 dns_timer = tcon->set_timer(
868 config::timeout_dns_resolve,
869 lib::bind(
871 this,
872 dns_timer,
873 cb,
874 lib::placeholders::_1
875 )
876 );
877
878 if (config::enable_multithreading) {
879 m_resolver->async_resolve(
880 query,
881 tcon->get_strand()->wrap(lib::bind(
883 this,
884 tcon,
885 dns_timer,
886 cb,
887 lib::placeholders::_1,
888 lib::placeholders::_2
889 ))
890 );
891 } else {
892 m_resolver->async_resolve(
893 query,
894 lib::bind(
896 this,
897 tcon,
898 dns_timer,
899 cb,
900 lib::placeholders::_1,
901 lib::placeholders::_2
902 )
903 );
904 }
905 }
lib::shared_ptr< lib::asio::steady_timer > timer_ptr
Type of timer handle.
Definition endpoint.hpp:86
void handle_resolve(transport_con_ptr tcon, timer_ptr dns_timer, connect_handler callback, lib::asio::error_code const &ec, lib::asio::ip::tcp::resolver::iterator iterator)
Definition endpoint.hpp:939
void handle_resolve_timeout(timer_ptr, connect_handler callback, lib::error_code const &ec)
DNS resolution timeout handler.
Definition endpoint.hpp:916
@ proxy_invalid
Invalid Proxy URI.
Definition base.hpp:177
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Definition uri.hpp:351
schedule config_dir_name data_dir_name p2p_port http_port file_size name host(p2p_endpoint)) FC_REFLECT(tn_node_def
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_io_service()

template<typename config >
lib::asio::io_service & websocketpp::transport::asio::endpoint< config >::get_io_service ( )
inline

The io_service may be an internal or external one. This may be used to call methods of the io_service that are not explicitly wrapped by the endpoint.

This method is only valid after the endpoint has been initialized with init_asio. No error will be returned if it isn't.

Returns
A reference to the endpoint's io_service

Definition at line 356 of file endpoint.hpp.

356 {
357 return *m_io_service;
358 }

◆ get_local_endpoint()

template<typename config >
lib::asio::ip::tcp::endpoint websocketpp::transport::asio::endpoint< config >::get_local_endpoint ( lib::asio::error_code & ec)
inline

Extracts the local endpoint from the acceptor. This represents the address that WebSocket++ is listening on.

Sets a bad_descriptor error if the acceptor is not currently listening or otherwise unavailable.

Since
0.7.0
Parameters
ecSet to indicate what error occurred, if any.
Returns
The local endpoint

Definition at line 373 of file endpoint.hpp.

373 {
374 if (m_acceptor) {
375 return m_acceptor->local_endpoint(ec);
376 } else {
377 ec = lib::asio::error::make_error_code(lib::asio::error::bad_descriptor);
378 return lib::asio::ip::tcp::endpoint();
379 }
380 }

◆ handle_accept()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::handle_accept ( accept_handler callback,
lib::asio::error_code const & asio_ec )
inlineprotected

Definition at line 800 of file endpoint.hpp.

802 {
803 lib::error_code ret_ec;
804
805 m_alog->write(log::alevel::devel, "asio::handle_accept");
806
807 if (asio_ec) {
808 if (asio_ec == lib::asio::errc::operation_canceled) {
809 ret_ec = make_error_code(websocketpp::error::operation_canceled);
810 } else {
811 log_err(log::elevel::info,"asio handle_accept",asio_ec);
812 ret_ec = asio_ec;
813 }
814 }
815
816 callback(ret_ec);
817 }
@ operation_canceled
The requested operation was canceled.
Definition error.hpp:127
static level const info
Definition levels.hpp:69
Here is the caller graph for this function:

◆ handle_connect()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::handle_connect ( transport_con_ptr tcon,
timer_ptr con_timer,
connect_handler callback,
lib::asio::error_code const & ec )
inlineprotected

Definition at line 1048 of file endpoint.hpp.

1050 {
1051 if (ec == lib::asio::error::operation_aborted ||
1052 lib::asio::is_neg(con_timer->expires_from_now()))
1053 {
1054 m_alog->write(log::alevel::devel,"async_connect cancelled");
1055 return;
1056 }
1057
1058 con_timer->cancel();
1059
1060 if (ec) {
1061 log_err(log::elevel::info,"asio async_connect",ec);
1062 callback(ec);
1063 return;
1064 }
1065
1066 if (m_alog->static_test(log::alevel::devel)) {
1067 m_alog->write(log::alevel::devel,
1068 "Async connect to "+tcon->get_remote_endpoint()+" successful.");
1069 }
1070
1071 callback(lib::error_code());
1072 }
bool is_neg(T duration)
Definition asio.hpp:114
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_connect_timeout()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::handle_connect_timeout ( transport_con_ptr tcon,
timer_ptr ,
connect_handler callback,
lib::error_code const & ec )
inlineprotected

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

Parameters
tconPointer to the transport connection that is being connected
con_timerPointer to the timer in question
callbackThe function to call back
ecA status code indicating an error, if any.

Definition at line 1025 of file endpoint.hpp.

1027 {
1028 lib::error_code ret_ec;
1029
1030 if (ec) {
1032 m_alog->write(log::alevel::devel,
1033 "asio handle_connect_timeout timer cancelled");
1034 return;
1035 }
1036
1037 log_err(log::elevel::devel,"asio handle_connect_timeout",ec);
1038 ret_ec = ec;
1039 } else {
1040 ret_ec = make_error_code(transport::error::timeout);
1041 }
1042
1043 m_alog->write(log::alevel::devel,"TCP connect timed out");
1044 tcon->cancel_socket_checked();
1045 callback(ret_ec);
1046 }
@ operation_aborted
Operation aborted.
static level const devel
Low level debugging information (warning: very chatty)
Definition levels.hpp:63
Here is the caller graph for this function:

◆ handle_resolve()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::handle_resolve ( transport_con_ptr tcon,
timer_ptr dns_timer,
connect_handler callback,
lib::asio::error_code const & ec,
lib::asio::ip::tcp::resolver::iterator iterator )
inlineprotected

Definition at line 939 of file endpoint.hpp.

942 {
943 if (ec == lib::asio::error::operation_aborted ||
944 lib::asio::is_neg(dns_timer->expires_from_now()))
945 {
946 m_alog->write(log::alevel::devel,"async_resolve cancelled");
947 return;
948 }
949
950 dns_timer->cancel();
951
952 if (ec) {
953 log_err(log::elevel::info,"asio async_resolve",ec);
954 callback(ec);
955 return;
956 }
957
958 if (m_alog->static_test(log::alevel::devel)) {
959 std::stringstream s;
960 s << "Async DNS resolve successful. Results: ";
961
962 lib::asio::ip::tcp::resolver::iterator it, end;
963 for (it = iterator; it != end; ++it) {
964 s << (*it).endpoint() << " ";
965 }
966
967 m_alog->write(log::alevel::devel,s.str());
968 }
969
970 m_alog->write(log::alevel::devel,"Starting async connect");
971
972 timer_ptr con_timer;
973
974 con_timer = tcon->set_timer(
975 config::timeout_connect,
976 lib::bind(
978 this,
979 tcon,
980 con_timer,
981 callback,
982 lib::placeholders::_1
983 )
984 );
985
986 if (config::enable_multithreading) {
987 lib::asio::async_connect(
988 tcon->get_raw_socket(),
989 iterator,
990 tcon->get_strand()->wrap(lib::bind(
992 this,
993 tcon,
994 con_timer,
995 callback,
996 lib::placeholders::_1
997 ))
998 );
999 } else {
1000 lib::asio::async_connect(
1001 tcon->get_raw_socket(),
1002 iterator,
1003 lib::bind(
1005 this,
1006 tcon,
1007 con_timer,
1008 callback,
1009 lib::placeholders::_1
1010 )
1011 );
1012 }
1013 }
void handle_connect(transport_con_ptr tcon, timer_ptr con_timer, connect_handler callback, lib::asio::error_code const &ec)
void handle_connect_timeout(transport_con_ptr tcon, timer_ptr, connect_handler callback, lib::error_code const &ec)
Asio connect timeout handler.
char * s
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_resolve_timeout()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::handle_resolve_timeout ( timer_ptr ,
connect_handler callback,
lib::error_code const & ec )
inlineprotected

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

Parameters
dns_timerPointer to the timer in question
callbackThe function to call back
ecA status code indicating an error, if any.

Definition at line 916 of file endpoint.hpp.

918 {
919 lib::error_code ret_ec;
920
921 if (ec) {
923 m_alog->write(log::alevel::devel,
924 "asio handle_resolve_timeout timer cancelled");
925 return;
926 }
927
928 log_err(log::elevel::devel,"asio handle_resolve_timeout",ec);
929 ret_ec = ec;
930 } else {
931 ret_ec = make_error_code(transport::error::timeout);
932 }
933
934 m_alog->write(log::alevel::devel,"DNS resolution timed out");
935 m_resolver->cancel();
936 callback(ret_ec);
937 }
Here is the caller graph for this function:

◆ handle_timer()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::handle_timer ( timer_ptr ,
timer_handler callback,
lib::asio::error_code const & ec )
inline

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

Parameters
tPointer to the timer in question
callbackThe function to call back
ecA status code indicating an error, if any.

Definition at line 717 of file endpoint.hpp.

719 {
720 if (ec) {
721 if (ec == lib::asio::error::operation_aborted) {
722 callback(make_error_code(transport::error::operation_aborted));
723 } else {
724 m_elog->write(log::elevel::info,
725 "asio handle_timer error: "+ec.message());
726 log_err(log::elevel::info,"asio handle_timer",ec);
727 callback(ec);
728 }
729 } else {
730 callback(lib::error_code());
731 }
732 }
Here is the caller graph for this function:

◆ init()

template<typename config >
lib::error_code websocketpp::transport::asio::endpoint< config >::init ( transport_con_ptr tcon)
inlineprotected

init is called by an endpoint once for each newly created connection. It's purpose is to give the transport policy the chance to perform any transport specific initialization that couldn't be done via the default constructor.

Parameters
tconA pointer to the transport portion of the connection.
Returns
A status code indicating the success or failure of the operation

Definition at line 1085 of file endpoint.hpp.

1085 {
1086 m_alog->write(log::alevel::devel, "transport::asio::init");
1087
1088 // Initialize the connection socket component
1089 socket_type::init(lib::static_pointer_cast<socket_con_type,
1090 transport_con_type>(tcon));
1091
1092 lib::error_code ec;
1093
1094 ec = tcon->init_asio(m_io_service);
1095 if (ec) {return ec;}
1096
1097 tcon->set_tcp_pre_init_handler(m_tcp_pre_init_handler);
1098 tcon->set_tcp_post_init_handler(m_tcp_post_init_handler);
1099
1100 return lib::error_code();
1101 }
asio::connection< config > transport_con_type
Definition endpoint.hpp:74
socket_type::socket_con_type socket_con_type
Type of the socket connection component.
Definition endpoint.hpp:68
Here is the caller graph for this function:

◆ init_asio() [1/4]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::init_asio ( )
inline

This method of initialization will allocate and use an internally managed io_service.

See also
init_asio(io_service_ptr ptr)

Definition at line 245 of file endpoint.hpp.

245 {
246 // Use a smart pointer until the call is successful and ownership has
247 // successfully been taken. Use unique_ptr when available.
248 // TODO: remove the use of auto_ptr when C++98/03 support is no longer
249 // necessary.
250#ifdef _WEBSOCKETPP_CPP11_MEMORY_
251 lib::unique_ptr<lib::asio::io_service> service(new lib::asio::io_service());
252#else
253 lib::auto_ptr<lib::asio::io_service> service(new lib::asio::io_service());
254#endif
255 init_asio( service.get() );
256 // If control got this far without an exception, then ownership has successfully been taken
257 service.release();
258 m_external_io_service = false;
259 }
void init_asio()
Initialize asio transport with internal io_service.
Definition endpoint.hpp:245
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_asio() [2/4]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::init_asio ( io_service_ptr ptr)
inline

Initialize the ASIO transport policy for this endpoint using the provided io_service object. asio_init must be called exactly once on any endpoint that uses transport::asio before it can be used.

Parameters
ptrA pointer to the io_service to use for asio events

Definition at line 208 of file endpoint.hpp.

208 {
209 lib::error_code ec;
210 init_asio(ptr,ec);
211 if (ec) { throw exception(ec); }
212 }
Here is the call graph for this function:

◆ init_asio() [3/4]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::init_asio ( io_service_ptr ptr,
lib::error_code & ec )
inline

Initialize the ASIO transport policy for this endpoint using the provided io_service object. asio_init must be called exactly once on any endpoint that uses transport::asio before it can be used.

Parameters
ptrA pointer to the io_service to use for asio events
ecSet to indicate what error occurred, if any.

Definition at line 181 of file endpoint.hpp.

181 {
182 if (m_state != UNINITIALIZED) {
183 m_elog->write(log::elevel::library,
184 "asio::init_asio called from the wrong state");
186 ec = make_error_code(websocketpp::error::invalid_state);
187 return;
188 }
189
190 m_alog->write(log::alevel::devel,"asio::init_asio");
191
192 m_io_service = ptr;
193 m_external_io_service = true;
194 m_acceptor = lib::make_shared<lib::asio::ip::tcp::acceptor>(*m_io_service);
195
196 m_state = READY;
197 ec = lib::error_code();
198 }
@ invalid_state
The connection was in the wrong state for this operation.
Definition error.hpp:74
static level const library
Definition levels.hpp:66
Here is the call graph for this function:

◆ init_asio() [4/4]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::init_asio ( lib::error_code & ec)
inline

This method of initialization will allocate and use an internally managed io_service.

See also
init_asio(io_service_ptr ptr)
Parameters
ecSet to indicate what error occurred, if any.

Definition at line 223 of file endpoint.hpp.

223 {
224 // Use a smart pointer until the call is successful and ownership has
225 // successfully been taken. Use unique_ptr when available.
226 // TODO: remove the use of auto_ptr when C++98/03 support is no longer
227 // necessary.
228#ifdef _WEBSOCKETPP_CPP11_MEMORY_
229 lib::unique_ptr<lib::asio::io_service> service(new lib::asio::io_service());
230#else
231 lib::auto_ptr<lib::asio::io_service> service(new lib::asio::io_service());
232#endif
233 init_asio(service.get(), ec);
234 if( !ec ) service.release(); // Call was successful, transfer ownership
235 m_external_io_service = false;
236 }
Here is the call graph for this function:

◆ init_logging()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::init_logging ( alog_type * a,
elog_type * e )
inlineprotected

The loggers are located in the main endpoint class. As such, the transport doesn't have direct access to them. This method is called by the endpoint constructor to allow shared logging from the transport component. These are raw pointers to member variables of the endpoint. In particular, they cannot be used in the transport constructor as they haven't been constructed yet, and cannot be used in the transport destructor as they will have been destroyed by then.

Definition at line 795 of file endpoint.hpp.

795 {
796 m_alog = a;
797 m_elog = e;
798 }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
Here is the caller graph for this function:

◆ is_listening()

template<typename config >
bool websocketpp::transport::asio::endpoint< config >::is_listening ( ) const
inline
Returns
Whether or not the endpoint is listening.

Definition at line 607 of file endpoint.hpp.

607 {
608 return (m_state == LISTENING);
609 }

◆ is_secure()

template<typename config >
bool websocketpp::transport::asio::endpoint< config >::is_secure ( ) const
inline

Definition at line 168 of file endpoint.hpp.

168 {
169 return socket_type::is_secure();
170 }

◆ listen() [1/8]

template<typename config >
template<typename InternetProtocol >
void websocketpp::transport::asio::endpoint< config >::listen ( InternetProtocol const & internet_protocol,
uint16_t port )
inline

Bind the internal acceptor using the given internet protocol and port. The endpoint must have been initialized by calling init_asio before listening.

Common options include:

  • IPv6 with mapped IPv4 for dual stack hosts lib::asio::ip::tcp::v6()
  • IPv4 only: lib::asio::ip::tcp::v4()
Parameters
internet_protocolThe internet protocol to use.
portThe port to listen on.

Definition at line 474 of file endpoint.hpp.

475 {
476 lib::asio::ip::tcp::endpoint ep(internet_protocol, port);
477 listen(ep);
478 }
void listen(lib::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
Definition endpoint.hpp:390
Here is the call graph for this function:

◆ listen() [2/8]

template<typename config >
template<typename InternetProtocol >
void websocketpp::transport::asio::endpoint< config >::listen ( InternetProtocol const & internet_protocol,
uint16_t port,
lib::error_code & ec )
inline

Bind the internal acceptor using the given internet protocol and port. The endpoint must have been initialized by calling init_asio before listening.

Common options include:

  • IPv6 with mapped IPv4 for dual stack hosts lib::asio::ip::tcp::v6()
  • IPv4 only: lib::asio::ip::tcp::v4()
Parameters
internet_protocolThe internet protocol to use.
portThe port to listen on.
ecSet to indicate what error occurred, if any.

Definition at line 453 of file endpoint.hpp.

455 {
456 lib::asio::ip::tcp::endpoint ep(internet_protocol, port);
457 listen(ep,ec);
458 }
Here is the call graph for this function:

◆ listen() [3/8]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::listen ( lib::asio::ip::tcp::endpoint< config > const & ep)
inline

Bind the internal acceptor using the settings specified by the endpoint e

Parameters
epAn endpoint to read settings from

Definition at line 432 of file endpoint.hpp.

432 {
433 lib::error_code ec;
434 listen(ep,ec);
435 if (ec) { throw exception(ec); }
436 }
Here is the call graph for this function:

◆ listen() [4/8]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::listen ( lib::asio::ip::tcp::endpoint< config > const & ep,
lib::error_code & ec )
inline

Bind the internal acceptor using the specified settings. The endpoint must have been initialized by calling init_asio before listening.

Parameters
epAn endpoint to read settings from
ecSet to indicate what error occurred, if any.

Definition at line 390 of file endpoint.hpp.

391 {
392 if (m_state != READY) {
393 m_elog->write(log::elevel::library,
394 "asio::listen called from the wrong state");
396 ec = make_error_code(websocketpp::error::invalid_state);
397 return;
398 }
399
400 m_alog->write(log::alevel::devel,"asio::listen");
401
402 lib::asio::error_code bec;
403
404 m_acceptor->open(ep.protocol(),bec);
405 if (!bec) {
406 m_acceptor->set_option(lib::asio::socket_base::reuse_address(m_reuse_addr),bec);
407 }
408 if (!bec) {
409 m_acceptor->bind(ep,bec);
410 }
411 if (!bec) {
412 m_acceptor->listen(m_listen_backlog,bec);
413 }
414 if (bec) {
415 if (m_acceptor->is_open()) {
416 m_acceptor->close();
417 }
418 log_err(log::elevel::info,"asio listen",bec);
419 ec = bec;//make_error_code(error::pass_through);
420 } else {
421 m_state = LISTENING;
422 ec = lib::error_code();
423 }
424 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ listen() [5/8]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::listen ( std::string const & host,
std::string const & service )
inline

Bind the internal acceptor using the given host and service. More details about what host and service can be are available in the Asio documentation for ip::basic_resolver_query::basic_resolver_query's constructors.

The endpoint must have been initialized by calling init_asio before listening.

Parameters
hostA string identifying a location. May be a descriptive name or a numeric address string.
serviceA string identifying the requested service. This may be a descriptive name or a numeric string corresponding to a port number.
ecSet to indicate what error occurred, if any.

Definition at line 561 of file endpoint.hpp.

562 {
563 lib::error_code ec;
564 listen(host,service,ec);
565 if (ec) { throw exception(ec); }
566 }
Here is the call graph for this function:

◆ listen() [6/8]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::listen ( std::string const & host,
std::string const & service,
lib::error_code & ec )
inline

Bind the internal acceptor using the given host and service. More details about what host and service can be are available in the Asio documentation for ip::basic_resolver_query::basic_resolver_query's constructors.

The endpoint must have been initialized by calling init_asio before listening.

Parameters
hostA string identifying a location. May be a descriptive name or a numeric address string.
serviceA string identifying the requested service. This may be a descriptive name or a numeric string corresponding to a port number.
ecSet to indicate what error occurred, if any.

Definition at line 528 of file endpoint.hpp.

530 {
531 using lib::asio::ip::tcp;
532 tcp::resolver r(*m_io_service);
533 tcp::resolver::query query(host, service);
534 tcp::resolver::iterator endpoint_iterator = r.resolve(query);
535 tcp::resolver::iterator end;
536 if (endpoint_iterator == end) {
537 m_elog->write(log::elevel::library,
538 "asio::listen could not resolve the supplied host or service");
539 ec = make_error_code(error::invalid_host_service);
540 return;
541 }
542 listen(*endpoint_iterator,ec);
543 }
const mie::Vuint & r
Definition bn.cpp:28
@ invalid_host_service
Invalid host or service.
Definition base.hpp:180
Here is the call graph for this function:

◆ listen() [7/8]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::listen ( uint16_t port)
inline

Bind the internal acceptor using the given port. The IPv6 protocol with mapped IPv4 for dual stack hosts will be used. If you need IPv4 only use the overload that allows specifying the protocol explicitly.

The endpoint must have been initialized by calling init_asio before listening.

Parameters
portThe port to listen on.
ecSet to indicate what error occurred, if any.

Definition at line 508 of file endpoint.hpp.

508 {
509 listen(lib::asio::ip::tcp::v6(), port);
510 }
Here is the call graph for this function:

◆ listen() [8/8]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::listen ( uint16_t port,
lib::error_code & ec )
inline

Bind the internal acceptor using the given port. The IPv6 protocol with mapped IPv4 for dual stack hosts will be used. If you need IPv4 only use the overload that allows specifying the protocol explicitly.

The endpoint must have been initialized by calling init_asio before listening.

Parameters
portThe port to listen on.
ecSet to indicate what error occurred, if any.

Definition at line 492 of file endpoint.hpp.

492 {
493 listen(lib::asio::ip::tcp::v6(), port, ec);
494 }
Here is the call graph for this function:

◆ poll()

template<typename config >
std::size_t websocketpp::transport::asio::endpoint< config >::poll ( )
inline

Definition at line 630 of file endpoint.hpp.

630 {
631 return m_io_service->poll();
632 }

◆ poll_one()

template<typename config >
std::size_t websocketpp::transport::asio::endpoint< config >::poll_one ( )
inline

Definition at line 635 of file endpoint.hpp.

635 {
636 return m_io_service->poll_one();
637 }

◆ reset()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::reset ( )
inline

Definition at line 640 of file endpoint.hpp.

640 {
641 m_io_service->reset();
642 }

◆ run()

template<typename config >
std::size_t websocketpp::transport::asio::endpoint< config >::run ( )
inline

Definition at line 612 of file endpoint.hpp.

612 {
613 return m_io_service->run();
614 }
Here is the caller graph for this function:

◆ run_one()

template<typename config >
std::size_t websocketpp::transport::asio::endpoint< config >::run_one ( )
inline
Since
0.3.0-alpha4

Definition at line 620 of file endpoint.hpp.

620 {
621 return m_io_service->run_one();
622 }

◆ set_listen_backlog()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::set_listen_backlog ( int backlog)
inline

Sets the maximum length of the queue of pending connections. Increasing this will allow WebSocket++ to queue additional incoming connections. Setting it higher may prevent failed connections at high connection rates but may cause additional latency.

For this value to take effect you may need to adjust operating system settings.

New values affect future calls to listen only.

A value of zero will use the operating system default. This is the default value.

Since
0.3.0
Parameters
backlogThe maximum length of the queue of pending connections

Definition at line 323 of file endpoint.hpp.

323 {
324 m_listen_backlog = backlog;
325 }

◆ set_reuse_addr()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::set_reuse_addr ( bool value)
inline

Specifies whether or not to use the SO_REUSEADDR TCP socket option. What this flag does depends on your operating system. Please consult operating system documentation for more details.

New values affect future calls to listen only.

The default is false.

Since
0.3.0
Parameters
valueWhether or not to use the SO_REUSEADDR option

Definition at line 341 of file endpoint.hpp.

341 {
342 m_reuse_addr = value;
343 }
#define value
Definition pkcs11.h:157

◆ set_tcp_init_handler()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::set_tcp_init_handler ( tcp_init_handler h)
inline

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
hThe handler to call on tcp pre init.

Definition at line 285 of file endpoint.hpp.

285 {
287 }
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
Definition endpoint.hpp:271
Here is the call graph for this function:

◆ set_tcp_post_init_handler()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::set_tcp_post_init_handler ( tcp_init_handler h)
inline

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
hThe handler to call on tcp post init.

Definition at line 300 of file endpoint.hpp.

300 {
301 m_tcp_post_init_handler = h;
302 }

◆ set_tcp_pre_init_handler()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::set_tcp_pre_init_handler ( tcp_init_handler h)
inline

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
hThe handler to call on tcp pre init.

Definition at line 271 of file endpoint.hpp.

271 {
272 m_tcp_pre_init_handler = h;
273 }
Here is the caller graph for this function:

◆ set_timer()

template<typename config >
timer_ptr websocketpp::transport::asio::endpoint< config >::set_timer ( long duration,
timer_handler callback )
inline

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
durationLength of time to wait in milliseconds
callbackThe 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 689 of file endpoint.hpp.

689 {
690 timer_ptr new_timer = lib::make_shared<lib::asio::steady_timer>(
691 *m_io_service,
693 );
694
695 new_timer->async_wait(
696 lib::bind(
698 this,
699 new_timer,
700 callback,
701 lib::placeholders::_1
702 )
703 );
704
705 return new_timer;
706 }
void handle_timer(timer_ptr, timer_handler callback, lib::asio::error_code const &ec)
Timer handler.
Definition endpoint.hpp:717
boost::posix_time::time_duration milliseconds(long duration)
Definition asio.hpp:117
Here is the call graph for this function:

◆ start_perpetual()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::start_perpetual ( )
inline

Marks the endpoint as perpetual. Perpetual endpoints will not automatically exit when they run out of connections to process. To stop a perpetual endpoint call end_perpetual.

An endpoint may be marked perpetual at any time by any thread. It must be called either before the endpoint has run out of work or before it was started

Since
0.3.0

Definition at line 661 of file endpoint.hpp.

661 {
662 m_work = lib::make_shared<lib::asio::io_service::work>(*m_io_service);
663 }

◆ stop()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::stop ( )
inline

Definition at line 625 of file endpoint.hpp.

625 {
626 m_io_service->stop();
627 }

◆ stop_listening() [1/2]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::stop_listening ( )
inline

Stop listening and accepting new connections. This will not end any existing connections.

Since
0.3.0-alpha4

Definition at line 597 of file endpoint.hpp.

597 {
598 lib::error_code ec;
599 stop_listening(ec);
600 if (ec) { throw exception(ec); }
601 }
void stop_listening()
Stop listening.
Definition endpoint.hpp:597
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_listening() [2/2]

template<typename config >
void websocketpp::transport::asio::endpoint< config >::stop_listening ( lib::error_code & ec)
inline

Stop listening and accepting new connections. This will not end any existing connections.

Since
0.3.0-alpha4
Parameters
ecA status code indicating an error, if any.

Definition at line 576 of file endpoint.hpp.

576 {
577 if (m_state != LISTENING) {
578 m_elog->write(log::elevel::library,
579 "asio::listen called from the wrong state");
581 ec = make_error_code(websocketpp::error::invalid_state);
582 return;
583 }
584
585 m_acceptor->close();
586 m_state = READY;
587 ec = lib::error_code();
588 }
Here is the call graph for this function:

◆ stop_perpetual()

template<typename config >
void websocketpp::transport::asio::endpoint< config >::stop_perpetual ( )
inline

Clears the endpoint's perpetual flag. This will cause the endpoint's run method to exit normally when it runs out of connections. If there are currently active connections it will not end until they are complete.

Since
0.3.0

Definition at line 673 of file endpoint.hpp.

673 {
674 m_work.reset();
675 }

◆ stopped()

template<typename config >
bool websocketpp::transport::asio::endpoint< config >::stopped ( ) const
inline

Definition at line 645 of file endpoint.hpp.

645 {
646 return m_io_service->stopped();
647 }

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