NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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 
40 
41 #include <sstream>
42 #include <string>
43 
44 namespace websocketpp {
45 namespace transport {
46 namespace asio {
47 
49 
53 template <typename config>
54 class endpoint : public config::socket_type {
55 public:
58 
62  typedef typename config::socket_type socket_type;
64  typedef typename config::elog_type elog_type;
66  typedef typename config::alog_type alog_type;
67 
72 
75  typedef asio::connection<config> transport_con_type;
78  typedef typename transport_con_type::ptr transport_con_ptr;
79 
81  typedef lib::asio::io_service * io_service_ptr;
83  typedef lib::shared_ptr<lib::asio::ip::tcp::acceptor> acceptor_ptr;
85  typedef lib::shared_ptr<lib::asio::ip::tcp::resolver> resolver_ptr;
87  typedef lib::shared_ptr<lib::asio::steady_timer> timer_ptr;
89  typedef lib::shared_ptr<lib::asio::io_service::work> work_ptr;
90 
92  typedef lib::function<lib::error_code(acceptor_ptr)> tcp_pre_bind_handler;
93 
94  // generate and manage our own io_service
95  explicit endpoint()
96  : m_io_service(NULL)
97  , m_external_io_service(false)
98  , m_listen_backlog(lib::asio::socket_base::max_connections)
99  , m_reuse_addr(false)
100  , m_state(UNINITIALIZED)
101  {
102  //std::cout << "transport::asio::endpoint constructor" << std::endl;
103  }
104 
106  // clean up our io_service if we were initialized with an internal one.
107 
108  // Explicitly destroy local objects
109  m_acceptor.reset();
110  m_resolver.reset();
111  m_work.reset();
112  if (m_state != UNINITIALIZED && !m_external_io_service) {
113  delete m_io_service;
114  }
115  }
116 
120 #ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
121  endpoint(const endpoint & src) = delete;
122  endpoint& operator= (const endpoint & rhs) = delete;
123 #else
124 private:
125  endpoint(const endpoint & src);
126  endpoint & operator= (const endpoint & rhs);
127 public:
128 #endif // _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
129 
130 #ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
131  endpoint (endpoint && src)
133  , m_tcp_pre_init_handler(src.m_tcp_pre_init_handler)
134  , m_tcp_post_init_handler(src.m_tcp_post_init_handler)
135  , m_io_service(src.m_io_service)
136  , m_external_io_service(src.m_external_io_service)
137  , m_acceptor(src.m_acceptor)
138  , m_listen_backlog(lib::asio::socket_base::max_connections)
139  , m_reuse_addr(src.m_reuse_addr)
140  , m_elog(src.m_elog)
141  , m_alog(src.m_alog)
142  , m_state(src.m_state)
143  {
144  src.m_io_service = NULL;
145  src.m_external_io_service = false;
146  src.m_acceptor = NULL;
147  src.m_state = UNINITIALIZED;
148  }
149 
150  /*endpoint & operator= (const endpoint && rhs) {
151  if (this != &rhs) {
152  m_io_service = rhs.m_io_service;
153  m_external_io_service = rhs.m_external_io_service;
154  m_acceptor = rhs.m_acceptor;
155  m_listen_backlog = rhs.m_listen_backlog;
156  m_reuse_addr = rhs.m_reuse_addr;
157  m_state = rhs.m_state;
158 
159  rhs.m_io_service = NULL;
160  rhs.m_external_io_service = false;
161  rhs.m_acceptor = NULL;
162  rhs.m_listen_backlog = lib::asio::socket_base::max_connections;
163  rhs.m_state = UNINITIALIZED;
164 
165  // TODO: this needs to be updated
166  }
167  return *this;
168  }*/
169 #endif // _WEBSOCKETPP_MOVE_SEMANTICS_
170 
172  bool is_secure() const {
173  return socket_type::is_secure();
174  }
175 
177 
185  void init_asio(io_service_ptr ptr, lib::error_code & ec) {
186  if (m_state != UNINITIALIZED) {
187  m_elog->write(log::elevel::library,
188  "asio::init_asio called from the wrong state");
191  return;
192  }
193 
194  m_alog->write(log::alevel::devel,"asio::init_asio");
195 
196  m_io_service = ptr;
197  m_external_io_service = true;
198  m_acceptor = lib::make_shared<lib::asio::ip::tcp::acceptor>(
199  *m_io_service);
200 
201  m_state = READY;
202  ec = lib::error_code();
203  }
204 
206 
213  void init_asio(io_service_ptr ptr) {
214  lib::error_code ec;
215  init_asio(ptr,ec);
216  if (ec) { throw exception(ec); }
217  }
218 
220 
228  void init_asio(lib::error_code & ec) {
229  // Use a smart pointer until the call is successful and ownership has
230  // successfully been taken. Use unique_ptr when available.
231  // TODO: remove the use of auto_ptr when C++98/03 support is no longer
232  // necessary.
233 #ifdef _WEBSOCKETPP_CPP11_MEMORY_
234  lib::unique_ptr<lib::asio::io_service> service(new lib::asio::io_service());
235 #else
236  lib::auto_ptr<lib::asio::io_service> service(new lib::asio::io_service());
237 #endif
238  init_asio(service.get(), ec);
239  if( !ec ) service.release(); // Call was successful, transfer ownership
240  m_external_io_service = false;
241  }
242 
244 
250  void init_asio() {
251  // Use a smart pointer until the call is successful and ownership has
252  // successfully been taken. Use unique_ptr when available.
253  // TODO: remove the use of auto_ptr when C++98/03 support is no longer
254  // necessary.
255 #ifdef _WEBSOCKETPP_CPP11_MEMORY_
256  lib::unique_ptr<lib::asio::io_service> service(new lib::asio::io_service());
257 #else
258  lib::auto_ptr<lib::asio::io_service> service(new lib::asio::io_service());
259 #endif
260  init_asio( service.get() );
261  // If control got this far without an exception, then ownership has successfully been taken
262  service.release();
263  m_external_io_service = false;
264  }
265 
267 
275  void set_tcp_pre_bind_handler(tcp_pre_bind_handler h) {
276  m_tcp_pre_bind_handler = h;
277  }
278 
280 
290  m_tcp_pre_init_handler = h;
291  }
292 
294 
305  }
306 
308 
319  m_tcp_post_init_handler = h;
320  }
321 
323 
343  void set_listen_backlog(int backlog) {
344  m_listen_backlog = backlog;
345  }
346 
348 
364  void set_reuse_addr(bool value) {
365  m_reuse_addr = value;
366  }
367 
369 
379  lib::asio::io_service & get_io_service() {
380  return *m_io_service;
381  }
382 
384 
396  lib::asio::ip::tcp::endpoint get_local_endpoint(lib::asio::error_code & ec) {
397  if (m_acceptor) {
398  return m_acceptor->local_endpoint(ec);
399  } else {
400  ec = lib::asio::error::make_error_code(lib::asio::error::bad_descriptor);
401  return lib::asio::ip::tcp::endpoint();
402  }
403  }
404 
406 
413  void listen(lib::asio::ip::tcp::endpoint const & ep, lib::error_code & ec)
414  {
415  if (m_state != READY) {
416  m_elog->write(log::elevel::library,
417  "asio::listen called from the wrong state");
420  return;
421  }
422 
423  m_alog->write(log::alevel::devel,"asio::listen");
424 
425  lib::asio::error_code bec;
426 
427  m_acceptor->open(ep.protocol(),bec);
428  if (bec) {ec = clean_up_listen_after_error(bec);return;}
429 
430  m_acceptor->set_option(lib::asio::socket_base::reuse_address(m_reuse_addr),bec);
431  if (bec) {ec = clean_up_listen_after_error(bec);return;}
432 
433  // if a TCP pre-bind handler is present, run it
434  if (m_tcp_pre_bind_handler) {
435  ec = m_tcp_pre_bind_handler(m_acceptor);
436  if (ec) {
437  ec = clean_up_listen_after_error(ec);
438  return;
439  }
440  }
441 
442  m_acceptor->bind(ep,bec);
443  if (bec) {ec = clean_up_listen_after_error(bec);return;}
444 
445  m_acceptor->listen(m_listen_backlog,bec);
446  if (bec) {ec = clean_up_listen_after_error(bec);return;}
447 
448  // Success
449  m_state = LISTENING;
450  ec = lib::error_code();
451  }
452 
453 
454 
456 
461  void listen(lib::asio::ip::tcp::endpoint const & ep) {
462  lib::error_code ec;
463  listen(ep,ec);
464  if (ec) { throw exception(ec); }
465  }
466 
468 
481  template <typename InternetProtocol>
482  void listen(InternetProtocol const & internet_protocol, uint16_t port,
483  lib::error_code & ec)
484  {
485  lib::asio::ip::tcp::endpoint ep(internet_protocol, port);
486  listen(ep,ec);
487  }
488 
490 
502  template <typename InternetProtocol>
503  void listen(InternetProtocol const & internet_protocol, uint16_t port)
504  {
505  lib::asio::ip::tcp::endpoint ep(internet_protocol, port);
506  listen(ep);
507  }
508 
510 
521  void listen(uint16_t port, lib::error_code & ec) {
522  listen(lib::asio::ip::tcp::v6(), port, ec);
523  }
524 
526 
537  void listen(uint16_t port) {
538  listen(lib::asio::ip::tcp::v6(), port);
539  }
540 
542 
557  void listen(std::string const & host, std::string const & service,
558  lib::error_code & ec)
559  {
560  using lib::asio::ip::tcp;
561  tcp::resolver r(*m_io_service);
562  tcp::resolver::query query(host, service);
563  tcp::resolver::iterator endpoint_iterator = r.resolve(query);
564  tcp::resolver::iterator end;
565  if (endpoint_iterator == end) {
566  m_elog->write(log::elevel::library,
567  "asio::listen could not resolve the supplied host or service");
569  return;
570  }
571  listen(*endpoint_iterator,ec);
572  }
573 
575 
590  void listen(std::string const & host, std::string const & service)
591  {
592  lib::error_code ec;
593  listen(host,service,ec);
594  if (ec) { throw exception(ec); }
595  }
596 
598 
605  void stop_listening(lib::error_code & ec) {
606  if (m_state != LISTENING) {
607  m_elog->write(log::elevel::library,
608  "asio::listen called from the wrong state");
611  return;
612  }
613 
614  m_acceptor->close();
615  m_state = READY;
616  ec = lib::error_code();
617  }
618 
620 
626  void stop_listening() {
627  lib::error_code ec;
628  stop_listening(ec);
629  if (ec) { throw exception(ec); }
630  }
631 
633 
636  bool is_listening() const {
637  return (m_state == LISTENING);
638  }
639 
642  return m_io_service->run();
643  }
644 
646 
650  return m_io_service->run_one();
651  }
652 
654  void stop() {
655  m_io_service->stop();
656  }
657 
660  return m_io_service->poll();
661  }
662 
665  return m_io_service->poll_one();
666  }
667 
669  void reset() {
670  m_io_service->reset();
671  }
672 
674  bool stopped() const {
675  return m_io_service->stopped();
676  }
677 
679 
691  m_work = lib::make_shared<lib::asio::io_service::work>(
692  *m_io_service
693  );
694  }
695 
697 
704  void stop_perpetual() {
705  m_work.reset();
706  }
707 
709 
720  timer_ptr set_timer(long duration, timer_handler callback) {
721  timer_ptr new_timer = lib::make_shared<lib::asio::steady_timer>(
722  *m_io_service,
723  lib::asio::milliseconds(duration)
724  );
725 
726  new_timer->async_wait(
727  lib::bind(
729  this,
730  new_timer,
731  callback,
732  lib::placeholders::_1
733  )
734  );
735 
736  return new_timer;
737  }
738 
740 
748  void handle_timer(timer_ptr, timer_handler callback,
749  lib::asio::error_code const & ec)
750  {
751  if (ec) {
754  } else {
755  m_elog->write(log::elevel::info,
756  "asio handle_timer error: "+ec.message());
757  log_err(log::elevel::info,"asio handle_timer",ec);
758  callback(socket_con_type::translate_ec(ec));
759  }
760  } else {
761  callback(lib::error_code());
762  }
763  }
764 
766 
771  void async_accept(transport_con_ptr tcon, accept_handler callback,
772  lib::error_code & ec)
773  {
774  if (m_state != LISTENING || !m_acceptor) {
777  return;
778  }
779 
780  m_alog->write(log::alevel::devel, "asio::async_accept");
781 
783  m_acceptor->async_accept(
784  tcon->get_raw_socket(),
785  tcon->get_strand()->wrap(lib::bind(
787  this,
788  callback,
789  lib::placeholders::_1
790  ))
791  );
792  } else {
793  m_acceptor->async_accept(
794  tcon->get_raw_socket(),
795  lib::bind(
797  this,
798  callback,
799  lib::placeholders::_1
800  )
801  );
802  }
803  }
804 
806 
810  void async_accept(transport_con_ptr tcon, accept_handler callback) {
811  lib::error_code ec;
812  async_accept(tcon,callback,ec);
813  if (ec) { throw exception(ec); }
814  }
815 protected:
817 
826  void init_logging(const lib::shared_ptr<alog_type>& a, const lib::shared_ptr<elog_type>& e) {
827  m_alog = a;
828  m_elog = e;
829  }
830 
831  void handle_accept(accept_handler callback, lib::asio::error_code const &
832  asio_ec)
833  {
834  lib::error_code ret_ec;
835 
836  m_alog->write(log::alevel::devel, "asio::handle_accept");
837 
838  if (asio_ec) {
839  if (asio_ec == lib::asio::errc::operation_canceled) {
841  } else {
842  log_err(log::elevel::info,"asio handle_accept",asio_ec);
843  ret_ec = socket_con_type::translate_ec(asio_ec);
844  }
845  }
846 
847  callback(ret_ec);
848  }
849 
851  // TODO: there have to be some more failure conditions here
852  void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb) {
853  using namespace lib::asio::ip;
854 
855  // Create a resolver
856  if (!m_resolver) {
857  m_resolver = lib::make_shared<lib::asio::ip::tcp::resolver>(
858  *m_io_service);
859  }
860 
861  tcon->set_uri(u);
862 
863  std::string proxy = tcon->get_proxy();
864  std::string host;
865  std::string port;
866 
867  if (proxy.empty()) {
868  host = u->get_host();
869  port = u->get_port_str();
870  } else {
871  lib::error_code ec;
872 
873  uri_ptr pu = lib::make_shared<uri>(proxy);
874 
875  if (!pu->get_valid()) {
877  return;
878  }
879 
880  ec = tcon->proxy_init(u->get_authority());
881  if (ec) {
882  cb(ec);
883  return;
884  }
885 
886  host = pu->get_host();
887  port = pu->get_port_str();
888  }
889 
890  tcp::resolver::query query(host,port);
891 
892  if (m_alog->static_test(log::alevel::devel)) {
893  m_alog->write(log::alevel::devel,
894  "starting async DNS resolve for "+host+":"+port);
895  }
896 
897  timer_ptr dns_timer;
898 
899  dns_timer = tcon->set_timer(
901  lib::bind(
903  this,
904  dns_timer,
905  cb,
906  lib::placeholders::_1
907  )
908  );
909 
911  m_resolver->async_resolve(
912  query,
913  tcon->get_strand()->wrap(lib::bind(
915  this,
916  tcon,
917  dns_timer,
918  cb,
919  lib::placeholders::_1,
920  lib::placeholders::_2
921  ))
922  );
923  } else {
924  m_resolver->async_resolve(
925  query,
926  lib::bind(
928  this,
929  tcon,
930  dns_timer,
931  cb,
932  lib::placeholders::_1,
933  lib::placeholders::_2
934  )
935  );
936  }
937  }
938 
940 
948  void handle_resolve_timeout(timer_ptr, connect_handler callback,
949  lib::error_code const & ec)
950  {
951  lib::error_code ret_ec;
952 
953  if (ec) {
955  m_alog->write(log::alevel::devel,
956  "asio handle_resolve_timeout timer cancelled");
957  return;
958  }
959 
960  log_err(log::elevel::devel,"asio handle_resolve_timeout",ec);
961  ret_ec = ec;
962  } else {
964  }
965 
966  m_alog->write(log::alevel::devel,"DNS resolution timed out");
967  m_resolver->cancel();
968  callback(ret_ec);
969  }
970 
971  void handle_resolve(transport_con_ptr tcon, timer_ptr dns_timer,
972  connect_handler callback, lib::asio::error_code const & ec,
973  lib::asio::ip::tcp::resolver::iterator iterator)
974  {
976  lib::asio::is_neg(dns_timer->expires_from_now()))
977  {
978  m_alog->write(log::alevel::devel,"async_resolve cancelled");
979  return;
980  }
981 
982  dns_timer->cancel();
983 
984  if (ec) {
985  log_err(log::elevel::info,"asio async_resolve",ec);
986  callback(socket_con_type::translate_ec(ec));
987  return;
988  }
989 
990  if (m_alog->static_test(log::alevel::devel)) {
991  std::stringstream s;
992  s << "Async DNS resolve successful. Results: ";
993 
994  lib::asio::ip::tcp::resolver::iterator it, end;
995  for (it = iterator; it != end; ++it) {
996  s << (*it).endpoint() << " ";
997  }
998 
999  m_alog->write(log::alevel::devel,s.str());
1000  }
1001 
1002  m_alog->write(log::alevel::devel,"Starting async connect");
1003 
1004  timer_ptr con_timer;
1005 
1006  con_timer = tcon->set_timer(
1008  lib::bind(
1010  this,
1011  tcon,
1012  con_timer,
1013  callback,
1014  lib::placeholders::_1
1015  )
1016  );
1017 
1019  lib::asio::async_connect(
1020  tcon->get_raw_socket(),
1021  iterator,
1022  tcon->get_strand()->wrap(lib::bind(
1024  this,
1025  tcon,
1026  con_timer,
1027  callback,
1028  lib::placeholders::_1
1029  ))
1030  );
1031  } else {
1032  lib::asio::async_connect(
1033  tcon->get_raw_socket(),
1034  iterator,
1035  lib::bind(
1037  this,
1038  tcon,
1039  con_timer,
1040  callback,
1041  lib::placeholders::_1
1042  )
1043  );
1044  }
1045  }
1046 
1048 
1057  void handle_connect_timeout(transport_con_ptr tcon, timer_ptr,
1058  connect_handler callback, lib::error_code const & ec)
1059  {
1060  lib::error_code ret_ec;
1061 
1062  if (ec) {
1064  m_alog->write(log::alevel::devel,
1065  "asio handle_connect_timeout timer cancelled");
1066  return;
1067  }
1068 
1069  log_err(log::elevel::devel,"asio handle_connect_timeout",ec);
1070  ret_ec = ec;
1071  } else {
1073  }
1074 
1075  m_alog->write(log::alevel::devel,"TCP connect timed out");
1076  tcon->cancel_socket_checked();
1077  callback(ret_ec);
1078  }
1079 
1080  void handle_connect(transport_con_ptr tcon, timer_ptr con_timer,
1081  connect_handler callback, lib::asio::error_code const & ec)
1082  {
1084  lib::asio::is_neg(con_timer->expires_from_now()))
1085  {
1086  m_alog->write(log::alevel::devel,"async_connect cancelled");
1087  return;
1088  }
1089 
1090  con_timer->cancel();
1091 
1092  if (ec) {
1093  log_err(log::elevel::info,"asio async_connect",ec);
1094  callback(socket_con_type::translate_ec(ec));
1095  return;
1096  }
1097 
1098  if (m_alog->static_test(log::alevel::devel)) {
1099  m_alog->write(log::alevel::devel,
1100  "Async connect to "+tcon->get_remote_endpoint()+" successful.");
1101  }
1102 
1103  callback(lib::error_code());
1104  }
1105 
1107 
1117  lib::error_code init(transport_con_ptr tcon) {
1118  m_alog->write(log::alevel::devel, "transport::asio::init");
1119 
1120  // Initialize the connection socket component
1121  socket_type::init(lib::static_pointer_cast<socket_con_type,
1122  transport_con_type>(tcon));
1123 
1124  lib::error_code ec;
1125 
1126  ec = tcon->init_asio(m_io_service);
1127  if (ec) {return ec;}
1128 
1129  tcon->set_tcp_pre_init_handler(m_tcp_pre_init_handler);
1130  tcon->set_tcp_post_init_handler(m_tcp_post_init_handler);
1131 
1132  return lib::error_code();
1133  }
1134 private:
1136  template <typename error_type>
1137  void log_err(log::level l, char const * msg, error_type const & ec) {
1138  std::stringstream s;
1139  s << msg << " error: " << ec << " (" << ec.message() << ")";
1140  m_elog->write(l,s.str());
1141  }
1142 
1144  template <typename error_type>
1145  lib::error_code clean_up_listen_after_error(error_type const & ec) {
1146  if (m_acceptor->is_open()) {
1147  m_acceptor->close();
1148  }
1149  log_err(log::elevel::info,"asio listen",ec);
1150  return socket_con_type::translate_ec(ec);
1151  }
1152 
1153  enum state {
1154  UNINITIALIZED = 0,
1155  READY = 1,
1156  LISTENING = 2
1157  };
1158 
1159  // Handlers
1160  tcp_pre_bind_handler m_tcp_pre_bind_handler;
1161  tcp_init_handler m_tcp_pre_init_handler;
1162  tcp_init_handler m_tcp_post_init_handler;
1163 
1164  // Network Resources
1165  io_service_ptr m_io_service;
1166  bool m_external_io_service;
1167  acceptor_ptr m_acceptor;
1168  resolver_ptr m_resolver;
1169  work_ptr m_work;
1170 
1171  // Network constants
1172  int m_listen_backlog;
1173  bool m_reuse_addr;
1174 
1175  lib::shared_ptr<elog_type> m_elog;
1176  lib::shared_ptr<alog_type> m_alog;
1177 
1178  // Transport state
1179  state m_state;
1180 };
1181 
1182 } // namespace asio
1183 } // namespace transport
1184 } // namespace websocketpp
1185 
1186 #endif // WEBSOCKETPP_TRANSPORT_ASIO_HPP
static const bool enable_multithreading
Definition: timers.cpp:98
lib::shared_ptr< lib::asio::ip::tcp::acceptor > acceptor_ptr
Type of a shared pointer to the acceptor being used.
Definition: endpoint.hpp:83
endpoint< config > type
Type of this endpoint transport component.
Definition: endpoint.hpp:57
Asio based endpoint transport component.
Definition: base.hpp:143
lib::shared_ptr< lib::asio::io_service::work > work_ptr
Type of a shared pointer to an io_service work object.
Definition: endpoint.hpp:89
lib::error_code make_error_code(error::value e)
Definition: error.hpp:235
TLS enabled Asio connection socket component.
Definition: tls.hpp:63
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
Definition: endpoint.hpp:1117
static lib::error_code translate_ec(ErrorCodeType ec)
Translate any security policy specific information about an error code.
Definition: tls.hpp:358
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection socket component.
Definition: tls.hpp:68
void set_tcp_post_init_handler(tcp_init_handler h)
Sets the tcp post init handler.
Definition: endpoint.hpp:318
void init_asio()
Initialize asio transport with internal io_service.
Definition: endpoint.hpp:250
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
span_CONFIG_SIZE_TYPE size_t
Definition: span-lite.hpp:565
bool is_neg(T duration)
Definition: asio.hpp:124
void listen(lib::asio::ip::tcp::endpoint const &ep)
Set up endpoint for listening manually.
Definition: endpoint.hpp:461
transport_con_type::ptr transport_con_ptr
Type of a shared pointer to the connection transport component associated with this endpoint transpor...
Definition: endpoint.hpp:78
asio::connection< config > transport_con_type
Type of the connection transport component associated with this endpoint transport component...
Definition: endpoint.hpp:75
bool is_secure() const
Return whether or not the endpoint produces secure connections.
Definition: endpoint.hpp:172
timer_ptr set_timer(long duration, timer_handler callback)
Call back a function after a period of time.
Definition: endpoint.hpp:720
void listen(uint16_t port, lib::error_code &ec)
Set up endpoint for listening on a port (exception free)
Definition: endpoint.hpp:521
void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb)
Initiate a new connection.
Definition: endpoint.hpp:852
bool stopped() const
wraps the stopped method of the internal io_service object
Definition: endpoint.hpp:674
void set_reuse_addr(bool value)
Sets whether to use the SO_REUSEADDR flag when opening listening sockets.
Definition: endpoint.hpp:364
boost::posix_time::time_duration milliseconds(long duration)
Definition: asio.hpp:127
lib::shared_ptr< lib::asio::steady_timer > timer_ptr
Type of timer handle.
Definition: endpoint.hpp:87
websocketpp::transport::asio::tls_socket::endpoint socket_type
Definition: timers.cpp:96
lib::function< lib::error_code(acceptor_ptr)> tcp_pre_bind_handler
Type of socket pre-bind handler.
Definition: endpoint.hpp:92
void init_logging(const lib::shared_ptr< alog_type > &a, const lib::shared_ptr< elog_type > &e)
Initialize logging.
Definition: endpoint.hpp:826
static level const devel
Low level debugging information (warning: very chatty)
Definition: levels.hpp:63
lib::asio::ip::tcp::endpoint get_local_endpoint(lib::asio::error_code &ec)
Get local TCP endpoint.
Definition: endpoint.hpp:396
boost::chrono::duration< Rep, Period > duration
Definition: time.hpp:34
void handle_resolve_timeout(timer_ptr, connect_handler callback, lib::error_code const &ec)
DNS resolution timeout handler.
Definition: endpoint.hpp:948
config::socket_type socket_type
Type of the socket policy.
Definition: endpoint.hpp:62
lib::error_code init(socket_con_ptr scon)
Initialize a connection.
Definition: tls.hpp:459
void listen(uint16_t port)
Set up endpoint for listening on a port.
Definition: endpoint.hpp:537
void set_tcp_init_handler(tcp_init_handler h)
Sets the tcp pre init handler (deprecated)
Definition: endpoint.hpp:303
lib::asio::io_service & get_io_service()
Retrieve a reference to the endpoint&#39;s io_service.
Definition: endpoint.hpp:379
static level const devel
Development messages (warning: very chatty)
Definition: levels.hpp:141
void listen(std::string const &host, std::string const &service)
Set up endpoint for listening on a host and service.
Definition: endpoint.hpp:590
lib::shared_ptr< lib::asio::ip::tcp::resolver > resolver_ptr
Type of a shared pointer to the resolver being used.
Definition: endpoint.hpp:85
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
Definition: endpoint.hpp:185
std::size_t poll()
wraps the poll method of the internal io_service object
Definition: endpoint.hpp:659
void stop_perpetual()
Clears the endpoint&#39;s perpetual flag, allowing it to exit when empty.
Definition: endpoint.hpp:704
static const long timeout_connect
Definition: timers.cpp:104
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:971
void stop_listening()
Stop listening.
Definition: endpoint.hpp:626
config::alog_type alog_type
Type of the access logging policy.
Definition: endpoint.hpp:66
socket_con_type::ptr socket_con_ptr
Type of a shared pointer to the socket connection component.
Definition: endpoint.hpp:71
lib::asio::io_service * io_service_ptr
Type of a pointer to the ASIO io_service being used.
Definition: endpoint.hpp:81
static const long timeout_dns_resolve
Definition: timers.cpp:103
The connection was in the wrong state for this operation.
Definition: error.hpp:74
static level const info
Information about minor configuration problems or additional information about other warnings...
Definition: levels.hpp:69
lib::function< void(lib::error_code const &)> timer_handler
The type and signature of the callback passed to the read method.
Definition: connection.hpp:126
Namespace for the WebSocket++ project.
Definition: base64.hpp:41
std::size_t run_one()
wraps the run_one method of the internal io_service object
Definition: endpoint.hpp:649
The requested operation was canceled.
Definition: error.hpp:127
An async accept operation failed because the underlying transport has been requested to not listen fo...
Definition: error.hpp:124
config::elog_type elog_type
Type of the error logging policy.
Definition: endpoint.hpp:64
Stub concurrency policy that implements the interface using no-ops.
Definition: none.hpp:60
void reset()
wraps the reset method of the internal io_service object
Definition: endpoint.hpp:669
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:557
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:771
bool is_listening() const
Check if the endpoint is listening.
Definition: endpoint.hpp:636
void stop_listening(lib::error_code &ec)
Stop listening (exception free)
Definition: endpoint.hpp:605
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Definition: uri.hpp:352
void init_asio(io_service_ptr ptr)
initialize asio transport with external io_service
Definition: endpoint.hpp:213
void async_accept(transport_con_ptr tcon, accept_handler callback)
Accept the next connection attempt and assign it to con.
Definition: endpoint.hpp:810
std::size_t poll_one()
wraps the poll_one method of the internal io_service object
Definition: endpoint.hpp:664
void set_listen_backlog(int backlog)
Sets the maximum length of the queue of pending connections.
Definition: endpoint.hpp:343
lib::function< void(connection_hdl)> tcp_init_handler
Definition: connection.hpp:58
TLS enabled Asio endpoint socket component.
Definition: tls.hpp:404
void init_asio(lib::error_code &ec)
Initialize asio transport with internal io_service (exception free)
Definition: endpoint.hpp:228
void stop()
wraps the stop method of the internal io_service object
Definition: endpoint.hpp:654
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
Definition: endpoint.hpp:289
bool is_secure() const
Checks whether the endpoint creates secure connections.
Definition: tls.hpp:421
std::size_t run()
wraps the run method of the internal io_service object
Definition: endpoint.hpp:641
void listen(InternetProtocol const &internet_protocol, uint16_t port)
Set up endpoint for listening with protocol and port.
Definition: endpoint.hpp:503
socket_type::socket_con_type socket_con_type
Type of the socket connection component.
Definition: endpoint.hpp:69
void listen(lib::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
Definition: endpoint.hpp:413
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:482
uint32_t level
Type of a channel package.
Definition: levels.hpp:37
void set_tcp_pre_bind_handler(tcp_pre_bind_handler h)
Sets the tcp pre bind handler.
Definition: endpoint.hpp:275
void handle_connect_timeout(transport_con_ptr tcon, timer_ptr, connect_handler callback, lib::error_code const &ec)
Asio connect timeout handler.
Definition: endpoint.hpp:1057
void handle_connect(transport_con_ptr tcon, timer_ptr con_timer, connect_handler callback, lib::asio::error_code const &ec)
Definition: endpoint.hpp:1080
Stub logger that ignores all input.
Definition: stub.hpp:41
void handle_accept(accept_handler callback, lib::asio::error_code const &asio_ec)
Definition: endpoint.hpp:831
config::concurrency_type concurrency_type
Type of the concurrency policy.
Definition: endpoint.hpp:60
static level const library
Information about unusual system states or other minor internal library problems, less chatty than de...
Definition: levels.hpp:66
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
void handle_timer(timer_ptr, timer_handler callback, lib::asio::error_code const &ec)
Timer handler.
Definition: endpoint.hpp:748
void start_perpetual()
Marks the endpoint as perpetual, stopping it from exiting when empty.
Definition: endpoint.hpp:690