Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
endpoint.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, Peter Thorson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the WebSocket++ Project nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28#ifndef WEBSOCKETPP_TRANSPORT_ASIO_HPP
29#define WEBSOCKETPP_TRANSPORT_ASIO_HPP
30
34
35#include <websocketpp/uri.hpp>
37
39
40#include <sstream>
41#include <string>
42
43namespace websocketpp {
44namespace transport {
45namespace asio {
46
48
52template <typename config>
53class endpoint : public config::socket_type {
54public:
57
59 typedef typename config::concurrency_type concurrency_type;
61 typedef typename config::socket_type socket_type;
63 typedef typename config::elog_type elog_type;
65 typedef typename config::alog_type alog_type;
66
68 typedef typename socket_type::socket_con_type socket_con_type;
70 typedef typename socket_con_type::ptr socket_con_ptr;
71
74 typedef asio::connection<config> transport_con_type;
77 typedef typename transport_con_type::ptr transport_con_ptr;
78
80 typedef lib::asio::io_service * io_service_ptr;
82 typedef lib::shared_ptr<lib::asio::ip::tcp::acceptor> acceptor_ptr;
84 typedef lib::shared_ptr<lib::asio::ip::tcp::resolver> resolver_ptr;
86 typedef lib::shared_ptr<lib::asio::steady_timer> timer_ptr;
88 typedef lib::shared_ptr<lib::asio::io_service::work> work_ptr;
89
90 // generate and manage our own io_service
91 explicit endpoint()
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 }
100
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 }
112
116#ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
117 endpoint(const endpoint & src) = delete;
118 endpoint& operator= (const endpoint & rhs) = delete;
119#else
120private:
121 endpoint(const endpoint & src);
122 endpoint & operator= (const endpoint & rhs);
123public:
124#endif // _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
125
126#ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
127 endpoint (endpoint && src)
128 : config::socket_type(std::move(src))
129 , m_tcp_pre_init_handler(src.m_tcp_pre_init_handler)
130 , m_tcp_post_init_handler(src.m_tcp_post_init_handler)
131 , m_io_service(src.m_io_service)
132 , m_external_io_service(src.m_external_io_service)
133 , m_acceptor(src.m_acceptor)
134 , m_listen_backlog(lib::asio::socket_base::max_connections)
135 , m_reuse_addr(src.m_reuse_addr)
136 , m_elog(src.m_elog)
137 , m_alog(src.m_alog)
138 , m_state(src.m_state)
139 {
140 src.m_io_service = NULL;
141 src.m_external_io_service = false;
142 src.m_acceptor = NULL;
143 src.m_state = UNINITIALIZED;
144 }
145
146 /*endpoint & operator= (const endpoint && rhs) {
147 if (this != &rhs) {
148 m_io_service = rhs.m_io_service;
149 m_external_io_service = rhs.m_external_io_service;
150 m_acceptor = rhs.m_acceptor;
151 m_listen_backlog = rhs.m_listen_backlog;
152 m_reuse_addr = rhs.m_reuse_addr;
153 m_state = rhs.m_state;
154
155 rhs.m_io_service = NULL;
156 rhs.m_external_io_service = false;
157 rhs.m_acceptor = NULL;
158 rhs.m_listen_backlog = lib::asio::socket_base::max_connections;
159 rhs.m_state = UNINITIALIZED;
160
161 // TODO: this needs to be updated
162 }
163 return *this;
164 }*/
165#endif // _WEBSOCKETPP_MOVE_SEMANTICS_
166
168 bool is_secure() const {
169 return socket_type::is_secure();
170 }
171
173
181 void init_asio(io_service_ptr ptr, lib::error_code & ec) {
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 }
199
201
209 lib::error_code ec;
210 init_asio(ptr,ec);
211 if (ec) { throw exception(ec); }
212 }
213
215
223 void init_asio(lib::error_code & ec) {
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 }
237
239
245 void init_asio() {
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 }
260
262
272 m_tcp_pre_init_handler = h;
273 }
274
276
288
290
301 m_tcp_post_init_handler = h;
302 }
303
305
323 void set_listen_backlog(int backlog) {
324 m_listen_backlog = backlog;
325 }
326
328
342 m_reuse_addr = value;
343 }
344
346
356 lib::asio::io_service & get_io_service() {
357 return *m_io_service;
358 }
359
361
373 lib::asio::ip::tcp::endpoint get_local_endpoint(lib::asio::error_code & ec) {
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 }
381
383
390 void listen(lib::asio::ip::tcp::endpoint const & ep, lib::error_code & ec)
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 }
425
427
432 void listen(lib::asio::ip::tcp::endpoint const & ep) {
433 lib::error_code ec;
434 listen(ep,ec);
435 if (ec) { throw exception(ec); }
436 }
437
439
452 template <typename InternetProtocol>
453 void listen(InternetProtocol const & internet_protocol, uint16_t port,
454 lib::error_code & ec)
455 {
456 lib::asio::ip::tcp::endpoint ep(internet_protocol, port);
457 listen(ep,ec);
458 }
459
461
473 template <typename InternetProtocol>
474 void listen(InternetProtocol const & internet_protocol, uint16_t port)
475 {
476 lib::asio::ip::tcp::endpoint ep(internet_protocol, port);
477 listen(ep);
478 }
479
481
492 void listen(uint16_t port, lib::error_code & ec) {
493 listen(lib::asio::ip::tcp::v6(), port, ec);
494 }
495
497
508 void listen(uint16_t port) {
509 listen(lib::asio::ip::tcp::v6(), port);
510 }
511
513
528 void listen(std::string const & host, std::string const & service,
529 lib::error_code & ec)
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 }
544
546
561 void listen(std::string const & host, std::string const & service)
562 {
563 lib::error_code ec;
564 listen(host,service,ec);
565 if (ec) { throw exception(ec); }
566 }
567
569
576 void stop_listening(lib::error_code & ec) {
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 }
589
591
598 lib::error_code ec;
599 stop_listening(ec);
600 if (ec) { throw exception(ec); }
601 }
602
604
607 bool is_listening() const {
608 return (m_state == LISTENING);
609 }
610
612 std::size_t run() {
613 return m_io_service->run();
614 }
615
617
620 std::size_t run_one() {
621 return m_io_service->run_one();
622 }
623
625 void stop() {
626 m_io_service->stop();
627 }
628
630 std::size_t poll() {
631 return m_io_service->poll();
632 }
633
635 std::size_t poll_one() {
636 return m_io_service->poll_one();
637 }
638
640 void reset() {
641 m_io_service->reset();
642 }
643
645 bool stopped() const {
646 return m_io_service->stopped();
647 }
648
650
662 m_work = lib::make_shared<lib::asio::io_service::work>(*m_io_service);
663 }
664
666
674 m_work.reset();
675 }
676
678
689 timer_ptr set_timer(long duration, timer_handler callback) {
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 }
707
709
718 lib::asio::error_code const & ec)
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 }
733
735
741 lib::error_code & ec)
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 }
773
775
780 lib::error_code ec;
781 async_accept(tcon,callback,ec);
782 if (ec) { throw exception(ec); }
783 }
784protected:
786
796 m_alog = a;
797 m_elog = e;
798 }
799
800 void handle_accept(accept_handler callback, lib::asio::error_code const &
801 asio_ec)
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 }
818
820 // TODO: there have to be some more failure conditions here
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 }
906
908
917 lib::error_code const & ec)
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 }
938
940 connect_handler callback, lib::asio::error_code const & ec,
941 lib::asio::ip::tcp::resolver::iterator iterator)
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 }
1014
1016
1026 connect_handler callback, lib::error_code const & ec)
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 }
1047
1049 connect_handler callback, lib::asio::error_code const & ec)
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 }
1073
1075
1085 lib::error_code init(transport_con_ptr tcon) {
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 }
1102private:
1104 template <typename error_type>
1105 void log_err(log::level l, char const * msg, error_type const & ec) {
1106 std::stringstream s;
1107 s << msg << " error: " << ec << " (" << ec.message() << ")";
1108 m_elog->write(l,s.str());
1109 }
1110
1111 enum state {
1112 UNINITIALIZED = 0,
1113 READY = 1,
1114 LISTENING = 2
1115 };
1116
1117 // Handlers
1118 tcp_init_handler m_tcp_pre_init_handler;
1119 tcp_init_handler m_tcp_post_init_handler;
1120
1121 // Network Resources
1122 io_service_ptr m_io_service;
1123 bool m_external_io_service;
1124 acceptor_ptr m_acceptor;
1125 resolver_ptr m_resolver;
1126 work_ptr m_work;
1127
1128 // Network constants
1129 int m_listen_backlog;
1130 bool m_reuse_addr;
1131
1132 elog_type* m_elog;
1133 alog_type* m_alog;
1134
1135 // Transport state
1136 state m_state;
1137};
1138
1139} // namespace asio
1140} // namespace transport
1141} // namespace websocketpp
1142
1143#endif // WEBSOCKETPP_TRANSPORT_ASIO_HPP
const mie::Vuint & r
Definition bn.cpp:28
Asio based endpoint transport component.
Definition endpoint.hpp:53
std::size_t run_one()
wraps the run_one method of the internal io_service object
Definition endpoint.hpp:620
void stop_listening(lib::error_code &ec)
Stop listening (exception free)
Definition endpoint.hpp:576
config::concurrency_type concurrency_type
Type of the concurrency policy.
Definition endpoint.hpp:59
asio::connection< config > transport_con_type
Definition endpoint.hpp:74
void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb)
Initiate a new connection.
Definition endpoint.hpp:821
void handle_connect(transport_con_ptr tcon, timer_ptr con_timer, connect_handler callback, lib::asio::error_code const &ec)
void init_asio()
Initialize asio transport with internal io_service.
Definition endpoint.hpp:245
void init_logging(alog_type *a, elog_type *e)
Initialize logging.
Definition endpoint.hpp:795
bool is_secure() const
Return whether or not the endpoint produces secure connections.
Definition endpoint.hpp:168
void init_asio(io_service_ptr ptr)
initialize asio transport with external io_service
Definition endpoint.hpp:208
lib::asio::ip::tcp::endpoint get_local_endpoint(lib::asio::error_code &ec)
Get local TCP endpoint.
Definition endpoint.hpp:373
socket_type::socket_con_type socket_con_type
Type of the socket connection component.
Definition endpoint.hpp:68
void set_reuse_addr(bool value)
Sets whether to use the SO_REUSEADDR flag when opening listening sockets.
Definition endpoint.hpp:341
void set_tcp_init_handler(tcp_init_handler h)
Sets the tcp pre init handler (deprecated)
Definition endpoint.hpp:285
void handle_timer(timer_ptr, timer_handler callback, lib::asio::error_code const &ec)
Timer handler.
Definition endpoint.hpp:717
void start_perpetual()
Marks the endpoint as perpetual, stopping it from exiting when empty.
Definition endpoint.hpp:661
void stop()
wraps the stop method of the internal io_service object
Definition endpoint.hpp:625
std::size_t run()
wraps the run method of the internal io_service object
Definition endpoint.hpp:612
config::socket_type socket_type
Type of the socket policy.
Definition endpoint.hpp:61
socket_con_type::ptr socket_con_ptr
Type of a shared pointer to the socket connection component.
Definition endpoint.hpp:70
config::elog_type elog_type
Type of the error logging policy.
Definition endpoint.hpp:63
transport_con_type::ptr transport_con_ptr
Definition endpoint.hpp:77
void set_tcp_post_init_handler(tcp_init_handler h)
Sets the tcp post init handler.
Definition endpoint.hpp:300
void set_listen_backlog(int backlog)
Sets the maximum length of the queue of pending connections.
Definition endpoint.hpp:323
bool stopped() const
wraps the stopped method of the internal io_service object
Definition endpoint.hpp:645
timer_ptr set_timer(long duration, timer_handler callback)
Call back a function after a period of time.
Definition endpoint.hpp:689
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
Definition endpoint.hpp:181
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
void init_asio(lib::error_code &ec)
Initialize asio transport with internal io_service (exception free)
Definition endpoint.hpp:223
void async_accept(transport_con_ptr tcon, accept_handler callback)
Accept the next connection attempt and assign it to con.
Definition endpoint.hpp:779
void listen(uint16_t port)
Set up endpoint for listening on a port.
Definition endpoint.hpp:508
void handle_accept(accept_handler callback, lib::asio::error_code const &asio_ec)
Definition endpoint.hpp:800
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)
Definition endpoint.hpp:528
lib::shared_ptr< lib::asio::steady_timer > timer_ptr
Type of timer handle.
Definition endpoint.hpp:86
lib::asio::io_service & get_io_service()
Retrieve a reference to the endpoint's io_service.
Definition endpoint.hpp:356
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
std::size_t poll()
wraps the poll method of the internal io_service object
Definition endpoint.hpp:630
void stop_perpetual()
Clears the endpoint's perpetual flag, allowing it to exit when empty.
Definition endpoint.hpp:673
endpoint< config > type
Type of this endpoint transport component.
Definition endpoint.hpp:56
lib::shared_ptr< lib::asio::ip::tcp::resolver > resolver_ptr
Type of a shared pointer to the resolver being used.
Definition endpoint.hpp:84
void listen(lib::asio::ip::tcp::endpoint const &ep)
Set up endpoint for listening manually.
Definition endpoint.hpp:432
void handle_resolve_timeout(timer_ptr, connect_handler callback, lib::error_code const &ec)
DNS resolution timeout handler.
Definition endpoint.hpp:916
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
lib::shared_ptr< lib::asio::io_service::work > work_ptr
Type of a shared pointer to an io_service work object.
Definition endpoint.hpp:88
void reset()
wraps the reset method of the internal io_service object
Definition endpoint.hpp:640
void listen(InternetProtocol const &internet_protocol, uint16_t port)
Set up endpoint for listening with protocol and port.
Definition endpoint.hpp:474
lib::asio::io_service * io_service_ptr
Type of a pointer to the ASIO io_service being used.
Definition endpoint.hpp:80
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
Definition endpoint.hpp:271
lib::shared_ptr< lib::asio::ip::tcp::acceptor > acceptor_ptr
Type of a shared pointer to the acceptor being used.
Definition endpoint.hpp:82
void listen(std::string const &host, std::string const &service)
Set up endpoint for listening on a host and service.
Definition endpoint.hpp:561
void handle_connect_timeout(transport_con_ptr tcon, timer_ptr, connect_handler callback, lib::error_code const &ec)
Asio connect timeout 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)
Definition endpoint.hpp:740
std::size_t poll_one()
wraps the poll_one method of the internal io_service object
Definition endpoint.hpp:635
void listen(InternetProtocol const &internet_protocol, uint16_t port, lib::error_code &ec)
Set up endpoint for listening with protocol and port (exception free)
Definition endpoint.hpp:453
void listen(uint16_t port, lib::error_code &ec)
Set up endpoint for listening on a port (exception free)
Definition endpoint.hpp:492
config::alog_type alog_type
Type of the access logging policy.
Definition endpoint.hpp:65
bool is_listening() const
Check if the endpoint is listening.
Definition endpoint.hpp:607
void stop_listening()
Stop listening.
Definition endpoint.hpp:597
Definition name.hpp:106
@ operation_canceled
The requested operation was canceled.
Definition error.hpp:127
@ invalid_state
The connection was in the wrong state for this operation.
Definition error.hpp:74
lib::error_code make_error_code(error::value e)
Definition error.hpp:235
bool is_neg(T duration)
Definition asio.hpp:114
boost::posix_time::time_duration milliseconds(long duration)
Definition asio.hpp:117
uint32_t level
Type of a channel package.
Definition levels.hpp:37
@ proxy_invalid
Invalid Proxy URI.
Definition base.hpp:177
@ invalid_host_service
Invalid host or service.
Definition base.hpp:180
lib::function< void(connection_hdl)> tcp_init_handler
@ operation_aborted
Operation aborted.
lib::function< void(lib::error_code const &)> accept_handler
The type and signature of the callback passed to the accept method.
Definition endpoint.hpp:69
lib::function< void(lib::error_code const &)> timer_handler
The type and signature of the callback passed to the read method.
lib::function< void(lib::error_code const &)> connect_handler
The type and signature of the callback passed to the connect method.
Definition endpoint.hpp:72
Namespace for the WebSocket++ project.
Definition base64.hpp:41
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Definition uri.hpp:351
#define value
Definition pkcs11.h:157
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
schedule config_dir_name data_dir_name p2p_port http_port file_size name host(p2p_endpoint)) FC_REFLECT(tn_node_def
unsigned short uint16_t
Definition stdint.h:125
static level const devel
Development messages (warning: very chatty)
Definition levels.hpp:141
static level const devel
Low level debugging information (warning: very chatty)
Definition levels.hpp:63
static level const library
Definition levels.hpp:66
static level const info
Definition levels.hpp:69
char * s
int l