NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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 
39 
40 #include <sstream>
41 #include <string>
42 
43 namespace websocketpp {
44 namespace transport {
45 namespace asio {
46 
48 
52 template <typename config>
53 class endpoint : public config::socket_type {
54 public:
57 
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 
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(0)
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
120 private:
121  endpoint(const endpoint & src);
122  endpoint & operator= (const endpoint & rhs);
123 public:
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");
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>(
195  lib::ref(*m_io_service));
196 
197  m_state = READY;
198  ec = lib::error_code();
199  }
200 
202 
209  void init_asio(io_service_ptr ptr) {
210  lib::error_code ec;
211  init_asio(ptr,ec);
212  if (ec) { throw exception(ec); }
213  }
214 
216 
224  void init_asio(lib::error_code & ec) {
225  // Use a smart pointer until the call is successful and ownership has
226  // successfully been taken. Use unique_ptr when available.
227  // TODO: remove the use of auto_ptr when C++98/03 support is no longer
228  // necessary.
229 #ifdef _WEBSOCKETPP_CPP11_MEMORY_
230  lib::unique_ptr<lib::asio::io_service> service(new lib::asio::io_service());
231 #else
232  lib::auto_ptr<lib::asio::io_service> service(new lib::asio::io_service());
233 #endif
234  init_asio(service.get(), ec);
235  if( !ec ) service.release(); // Call was successful, transfer ownership
236  m_external_io_service = false;
237  }
238 
240 
246  void init_asio() {
247  // Use a smart pointer until the call is successful and ownership has
248  // successfully been taken. Use unique_ptr when available.
249  // TODO: remove the use of auto_ptr when C++98/03 support is no longer
250  // necessary.
251 #ifdef _WEBSOCKETPP_CPP11_MEMORY_
252  lib::unique_ptr<lib::asio::io_service> service(new lib::asio::io_service());
253 #else
254  lib::auto_ptr<lib::asio::io_service> service(new lib::asio::io_service());
255 #endif
256  init_asio( service.get() );
257  // If control got this far without an exception, then ownership has successfully been taken
258  service.release();
259  m_external_io_service = false;
260  }
261 
263 
273  m_tcp_pre_init_handler = h;
274  }
275 
277 
288  }
289 
291 
302  m_tcp_post_init_handler = h;
303  }
304 
306 
324  void set_listen_backlog(int backlog) {
325  m_listen_backlog = backlog;
326  }
327 
329 
342  void set_reuse_addr(bool value) {
343  m_reuse_addr = value;
344  }
345 
347 
357  lib::asio::io_service & get_io_service() {
358  return *m_io_service;
359  }
360 
362 
374  lib::asio::ip::tcp::endpoint get_local_endpoint(lib::asio::error_code & ec) {
375  if (m_acceptor) {
376  return m_acceptor->local_endpoint(ec);
377  } else {
378  ec = lib::asio::error::make_error_code(lib::asio::error::bad_descriptor);
379  return lib::asio::ip::tcp::endpoint();
380  }
381  }
382 
384 
391  void listen(lib::asio::ip::tcp::endpoint const & ep, lib::error_code & ec)
392  {
393  if (m_state != READY) {
394  m_elog->write(log::elevel::library,
395  "asio::listen called from the wrong state");
398  return;
399  }
400 
401  m_alog->write(log::alevel::devel,"asio::listen");
402 
403  lib::asio::error_code bec;
404 
405  m_acceptor->open(ep.protocol(),bec);
406  if (!bec) {
407  m_acceptor->set_option(lib::asio::socket_base::reuse_address(m_reuse_addr),bec);
408  }
409  if (!bec) {
410  m_acceptor->bind(ep,bec);
411  }
412  if (!bec) {
413  m_acceptor->listen(m_listen_backlog,bec);
414  }
415  if (bec) {
416  if (m_acceptor->is_open()) {
417  m_acceptor->close();
418  }
419  log_err(log::elevel::info,"asio listen",bec);
421  } else {
422  m_state = LISTENING;
423  ec = lib::error_code();
424  }
425  }
426 
428 
433  void listen(lib::asio::ip::tcp::endpoint const & ep) {
434  lib::error_code ec;
435  listen(ep,ec);
436  if (ec) { throw exception(ec); }
437  }
438 
440 
453  template <typename InternetProtocol>
454  void listen(InternetProtocol const & internet_protocol, uint16_t port,
455  lib::error_code & ec)
456  {
457  lib::asio::ip::tcp::endpoint ep(internet_protocol, port);
458  listen(ep,ec);
459  }
460 
462 
474  template <typename InternetProtocol>
475  void listen(InternetProtocol const & internet_protocol, uint16_t port)
476  {
477  lib::asio::ip::tcp::endpoint ep(internet_protocol, port);
478  listen(ep);
479  }
480 
482 
493  void listen(uint16_t port, lib::error_code & ec) {
494  listen(lib::asio::ip::tcp::v6(), port, ec);
495  }
496 
498 
509  void listen(uint16_t port) {
510  listen(lib::asio::ip::tcp::v6(), port);
511  }
512 
514 
529  void listen(std::string const & host, std::string const & service,
530  lib::error_code & ec)
531  {
532  using lib::asio::ip::tcp;
533  tcp::resolver r(*m_io_service);
534  tcp::resolver::query query(host, service);
535  tcp::resolver::iterator endpoint_iterator = r.resolve(query);
537  if (endpoint_iterator == end) {
538  m_elog->write(log::elevel::library,
539  "asio::listen could not resolve the supplied host or service");
541  return;
542  }
543  listen(*endpoint_iterator,ec);
544  }
545 
547 
562  void listen(std::string const & host, std::string const & service)
563  {
564  lib::error_code ec;
565  listen(host,service,ec);
566  if (ec) { throw exception(ec); }
567  }
568 
570 
577  void stop_listening(lib::error_code & ec) {
578  if (m_state != LISTENING) {
579  m_elog->write(log::elevel::library,
580  "asio::listen called from the wrong state");
583  return;
584  }
585 
586  m_acceptor->close();
587  m_state = READY;
588  ec = lib::error_code();
589  }
590 
592 
598  void stop_listening() {
599  lib::error_code ec;
600  stop_listening(ec);
601  if (ec) { throw exception(ec); }
602  }
603 
605 
608  bool is_listening() const {
609  return (m_state == LISTENING);
610  }
611 
613  std::size_t run() {
614  return m_io_service->run();
615  }
616 
618 
621  std::size_t run_one() {
622  return m_io_service->run_one();
623  }
624 
626  void stop() {
627  m_io_service->stop();
628  }
629 
631  std::size_t poll() {
632  return m_io_service->poll();
633  }
634 
636  std::size_t poll_one() {
637  return m_io_service->poll_one();
638  }
639 
641  void reset() {
642  m_io_service->reset();
643  }
644 
646  bool stopped() const {
647  return m_io_service->stopped();
648  }
649 
651 
663  m_work = lib::make_shared<lib::asio::io_service::work>(
664  lib::ref(*m_io_service)
665  );
666  }
667 
669 
676  void stop_perpetual() {
677  m_work.reset();
678  }
679 
681 
692  timer_ptr set_timer(long duration, timer_handler callback) {
693  timer_ptr new_timer = lib::make_shared<lib::asio::steady_timer>(
694  *m_io_service,
695  lib::asio::milliseconds(duration)
696  );
697 
698  new_timer->async_wait(
699  lib::bind(
701  this,
702  new_timer,
703  callback,
704  lib::placeholders::_1
705  )
706  );
707 
708  return new_timer;
709  }
710 
712 
720  void handle_timer(timer_ptr, timer_handler callback,
721  lib::asio::error_code const & ec)
722  {
723  if (ec) {
726  } else {
727  m_elog->write(log::elevel::info,
728  "asio handle_timer error: "+ec.message());
729  log_err(log::elevel::info,"asio handle_timer",ec);
731  }
732  } else {
733  callback(lib::error_code());
734  }
735  }
736 
738 
743  void async_accept(transport_con_ptr tcon, accept_handler callback,
744  lib::error_code & ec)
745  {
746  if (m_state != LISTENING) {
749  return;
750  }
751 
752  m_alog->write(log::alevel::devel, "asio::async_accept");
753 
755  m_acceptor->async_accept(
756  tcon->get_raw_socket(),
757  tcon->get_strand()->wrap(lib::bind(
759  this,
760  callback,
761  lib::placeholders::_1
762  ))
763  );
764  } else {
765  m_acceptor->async_accept(
766  tcon->get_raw_socket(),
767  lib::bind(
769  this,
770  callback,
771  lib::placeholders::_1
772  )
773  );
774  }
775  }
776 
778 
782  void async_accept(transport_con_ptr tcon, accept_handler callback) {
783  lib::error_code ec;
784  async_accept(tcon,callback,ec);
785  if (ec) { throw exception(ec); }
786  }
787 protected:
789 
798  void init_logging(alog_type* a, elog_type* e) {
799  m_alog = a;
800  m_elog = e;
801  }
802 
803  void handle_accept(accept_handler callback, lib::asio::error_code const &
804  asio_ec)
805  {
806  lib::error_code ret_ec;
807 
808  m_alog->write(log::alevel::devel, "asio::handle_accept");
809 
810  if (asio_ec) {
811  if (asio_ec == lib::asio::errc::operation_canceled) {
813  } else {
814  log_err(log::elevel::info,"asio handle_accept",asio_ec);
816  }
817  }
818 
819  callback(ret_ec);
820  }
821 
823  // TODO: there have to be some more failure conditions here
824  void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb) {
825  using namespace lib::asio::ip;
826 
827  // Create a resolver
828  if (!m_resolver) {
829  m_resolver = lib::make_shared<lib::asio::ip::tcp::resolver>(
830  lib::ref(*m_io_service));
831  }
832 
833  tcon->set_uri(u);
834 
835  std::string proxy = tcon->get_proxy();
836  std::string host;
837  std::string port;
838 
839  if (proxy.empty()) {
840  host = u->get_host();
841  port = u->get_port_str();
842  } else {
843  lib::error_code ec;
844 
845  uri_ptr pu = lib::make_shared<uri>(proxy);
846 
847  if (!pu->get_valid()) {
849  return;
850  }
851 
852  ec = tcon->proxy_init(u->get_authority());
853  if (ec) {
854  cb(ec);
855  return;
856  }
857 
858  host = pu->get_host();
859  port = pu->get_port_str();
860  }
861 
862  tcp::resolver::query query(host,port);
863 
864  if (m_alog->static_test(log::alevel::devel)) {
865  m_alog->write(log::alevel::devel,
866  "starting async DNS resolve for "+host+":"+port);
867  }
868 
869  timer_ptr dns_timer;
870 
871  dns_timer = tcon->set_timer(
873  lib::bind(
875  this,
876  dns_timer,
877  cb,
878  lib::placeholders::_1
879  )
880  );
881 
883  m_resolver->async_resolve(
884  query,
885  tcon->get_strand()->wrap(lib::bind(
887  this,
888  tcon,
889  dns_timer,
890  cb,
891  lib::placeholders::_1,
892  lib::placeholders::_2
893  ))
894  );
895  } else {
896  m_resolver->async_resolve(
897  query,
898  lib::bind(
900  this,
901  tcon,
902  dns_timer,
903  cb,
904  lib::placeholders::_1,
905  lib::placeholders::_2
906  )
907  );
908  }
909  }
910 
912 
920  void handle_resolve_timeout(timer_ptr, connect_handler callback,
921  lib::error_code const & ec)
922  {
923  lib::error_code ret_ec;
924 
925  if (ec) {
927  m_alog->write(log::alevel::devel,
928  "asio handle_resolve_timeout timer cancelled");
929  return;
930  }
931 
932  log_err(log::elevel::devel,"asio handle_resolve_timeout",ec);
933  ret_ec = ec;
934  } else {
936  }
937 
938  m_alog->write(log::alevel::devel,"DNS resolution timed out");
939  m_resolver->cancel();
940  callback(ret_ec);
941  }
942 
943  void handle_resolve(transport_con_ptr tcon, timer_ptr dns_timer,
944  connect_handler callback, lib::asio::error_code const & ec,
946  {
948  lib::asio::is_neg(dns_timer->expires_from_now()))
949  {
950  m_alog->write(log::alevel::devel,"async_resolve cancelled");
951  return;
952  }
953 
954  dns_timer->cancel();
955 
956  if (ec) {
957  log_err(log::elevel::info,"asio async_resolve",ec);
959  return;
960  }
961 
962  if (m_alog->static_test(log::alevel::devel)) {
963  std::stringstream s;
964  s << "Async DNS resolve successful. Results: ";
965 
967  for (it = iterator; it != end; ++it) {
968  s << (*it).endpoint() << " ";
969  }
970 
971  m_alog->write(log::alevel::devel,s.str());
972  }
973 
974  m_alog->write(log::alevel::devel,"Starting async connect");
975 
976  timer_ptr con_timer;
977 
978  con_timer = tcon->set_timer(
980  lib::bind(
982  this,
983  tcon,
984  con_timer,
985  callback,
986  lib::placeholders::_1
987  )
988  );
989 
991  lib::asio::async_connect(
992  tcon->get_raw_socket(),
993  iterator,
994  tcon->get_strand()->wrap(lib::bind(
996  this,
997  tcon,
998  con_timer,
999  callback,
1000  lib::placeholders::_1
1001  ))
1002  );
1003  } else {
1004  lib::asio::async_connect(
1005  tcon->get_raw_socket(),
1006  iterator,
1007  lib::bind(
1009  this,
1010  tcon,
1011  con_timer,
1012  callback,
1013  lib::placeholders::_1
1014  )
1015  );
1016  }
1017  }
1018 
1020 
1029  void handle_connect_timeout(transport_con_ptr tcon, timer_ptr,
1030  connect_handler callback, lib::error_code const & ec)
1031  {
1032  lib::error_code ret_ec;
1033 
1034  if (ec) {
1036  m_alog->write(log::alevel::devel,
1037  "asio handle_connect_timeout timer cancelled");
1038  return;
1039  }
1040 
1041  log_err(log::elevel::devel,"asio handle_connect_timeout",ec);
1042  ret_ec = ec;
1043  } else {
1045  }
1046 
1047  m_alog->write(log::alevel::devel,"TCP connect timed out");
1048  tcon->cancel_socket_checked();
1049  callback(ret_ec);
1050  }
1051 
1052  void handle_connect(transport_con_ptr tcon, timer_ptr con_timer,
1053  connect_handler callback, lib::asio::error_code const & ec)
1054  {
1056  lib::asio::is_neg(con_timer->expires_from_now()))
1057  {
1058  m_alog->write(log::alevel::devel,"async_connect cancelled");
1059  return;
1060  }
1061 
1062  con_timer->cancel();
1063 
1064  if (ec) {
1065  log_err(log::elevel::info,"asio async_connect",ec);
1067  return;
1068  }
1069 
1070  if (m_alog->static_test(log::alevel::devel)) {
1071  m_alog->write(log::alevel::devel,
1072  "Async connect to "+tcon->get_remote_endpoint()+" successful.");
1073  }
1074 
1075  callback(lib::error_code());
1076  }
1077 
1079 
1089  lib::error_code init(transport_con_ptr tcon) {
1090  m_alog->write(log::alevel::devel, "transport::asio::init");
1091 
1092  // Initialize the connection socket component
1093  socket_type::init(lib::static_pointer_cast<socket_con_type,
1094  transport_con_type>(tcon));
1095 
1096  lib::error_code ec;
1097 
1098  ec = tcon->init_asio(m_io_service);
1099  if (ec) {return ec;}
1100 
1101  tcon->set_tcp_pre_init_handler(m_tcp_pre_init_handler);
1102  tcon->set_tcp_post_init_handler(m_tcp_post_init_handler);
1103 
1104  return lib::error_code();
1105  }
1106 private:
1108  template <typename error_type>
1109  void log_err(log::level l, char const * msg, error_type const & ec) {
1110  std::stringstream s;
1111  s << msg << " error: " << ec << " (" << ec.message() << ")";
1112  m_elog->write(l,s.str());
1113  }
1114 
1115  enum state {
1116  UNINITIALIZED = 0,
1117  READY = 1,
1118  LISTENING = 2
1119  };
1120 
1121  // Handlers
1122  tcp_init_handler m_tcp_pre_init_handler;
1123  tcp_init_handler m_tcp_post_init_handler;
1124 
1125  // Network Resources
1126  io_service_ptr m_io_service;
1127  bool m_external_io_service;
1128  acceptor_ptr m_acceptor;
1129  resolver_ptr m_resolver;
1130  work_ptr m_work;
1131 
1132  // Network constants
1133  int m_listen_backlog;
1134  bool m_reuse_addr;
1135 
1136  elog_type* m_elog;
1137  alog_type* m_alog;
1138 
1139  // Transport state
1140  state m_state;
1141 };
1142 
1143 } // namespace asio
1144 } // namespace transport
1145 } // namespace websocketpp
1146 
1147 #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:82
endpoint< config > type
Type of this endpoint transport component.
Definition: endpoint.hpp:56
Asio based endpoint transport component.
Definition: base.hpp:143
void write(level, std::string const &)
Write a string message to the given channel.
Definition: stub.hpp:82
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
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:1089
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:301
bool is_secure() const
Checks whether the endpoint creates secure connections.
Definition: tls.hpp:430
void init_asio()
Initialize asio transport with internal io_service.
Definition: endpoint.hpp:246
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
bool is_neg(T duration)
Definition: asio.hpp:114
void listen(lib::asio::ip::tcp::endpoint const &ep)
Set up endpoint for listening manually.
Definition: endpoint.hpp:433
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:77
asio::connection< config > transport_con_type
Type of the connection transport component associated with this endpoint transport component...
Definition: endpoint.hpp:74
bool stopped() const
wraps the stopped method of the internal io_service object
Definition: endpoint.hpp:646
timer_ptr set_timer(long duration, timer_handler callback)
Call back a function after a period of time.
Definition: endpoint.hpp:692
void listen(uint16_t port, lib::error_code &ec)
Set up endpoint for listening on a port (exception free)
Definition: endpoint.hpp:493
void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb)
Initiate a new connection.
Definition: endpoint.hpp:824
void set_reuse_addr(bool value)
Sets whether to use the SO_REUSEADDR flag when opening listening sockets.
Definition: endpoint.hpp:342
boost::posix_time::time_duration milliseconds(long duration)
Definition: asio.hpp:117
lib::shared_ptr< lib::asio::steady_timer > timer_ptr
Type of timer handle.
Definition: endpoint.hpp:86
websocketpp::transport::asio::tls_socket::endpoint socket_type
Definition: timers.cpp:96
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:374
void handle_resolve_timeout(timer_ptr, connect_handler callback, lib::error_code const &ec)
DNS resolution timeout handler.
Definition: endpoint.hpp:920
config::socket_type socket_type
Type of the socket policy.
Definition: endpoint.hpp:61
lib::error_code init(socket_con_ptr scon)
Initialize a connection.
Definition: tls.hpp:468
void listen(uint16_t port)
Set up endpoint for listening on a port.
Definition: endpoint.hpp:509
void set_tcp_init_handler(tcp_init_handler h)
Sets the tcp pre init handler (deprecated)
Definition: endpoint.hpp:286
lib::asio::io_service & get_io_service()
Retrieve a reference to the endpoint&#39;s io_service.
Definition: endpoint.hpp:357
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:562
bool is_secure() const
Return whether or not the endpoint produces secure connections.
Definition: endpoint.hpp:168
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 init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
Definition: endpoint.hpp:181
Table::const_iterator iterator
Definition: cs-internal.hpp:41
std::size_t poll()
wraps the poll method of the internal io_service object
Definition: endpoint.hpp:631
void stop_perpetual()
Clears the endpoint&#39;s perpetual flag, allowing it to exit when empty.
Definition: endpoint.hpp:676
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:943
void stop_listening()
Stop listening.
Definition: endpoint.hpp:598
bool is_listening() const
Check if the endpoint is listening.
Definition: endpoint.hpp:608
config::alog_type alog_type
Type of the access logging policy.
Definition: endpoint.hpp:65
socket_con_type::ptr socket_con_ptr
Type of a shared pointer to the socket connection component.
Definition: endpoint.hpp:70
lib::asio::io_service * io_service_ptr
Type of a pointer to the ASIO io_service being used.
Definition: endpoint.hpp:80
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
there was an error in the underlying transport library
Definition: base.hpp:171
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:621
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:63
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:641
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:529
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:743
void stop_listening(lib::error_code &ec)
Stop listening (exception free)
Definition: endpoint.hpp:577
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Definition: uri.hpp:351
void init_asio(io_service_ptr ptr)
initialize asio transport with external io_service
Definition: endpoint.hpp:209
void async_accept(transport_con_ptr tcon, accept_handler callback)
Accept the next connection attempt and assign it to con.
Definition: endpoint.hpp:782
std::size_t poll_one()
wraps the poll_one method of the internal io_service object
Definition: endpoint.hpp:636
void set_listen_backlog(int backlog)
Sets the maximum length of the queue of pending connections.
Definition: endpoint.hpp:324
void init_logging(alog_type *a, elog_type *e)
Initialize logging.
Definition: endpoint.hpp:798
lib::function< void(connection_hdl)> tcp_init_handler
Definition: connection.hpp:58
TLS enabled Asio endpoint socket component.
Definition: tls.hpp:413
void init_asio(lib::error_code &ec)
Initialize asio transport with internal io_service (exception free)
Definition: endpoint.hpp:224
void stop()
wraps the stop method of the internal io_service object
Definition: endpoint.hpp:626
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
Definition: endpoint.hpp:272
std::size_t run()
wraps the run method of the internal io_service object
Definition: endpoint.hpp:613
void listen(InternetProtocol const &internet_protocol, uint16_t port)
Set up endpoint for listening with protocol and port.
Definition: endpoint.hpp:475
socket_type::socket_con_type socket_con_type
Type of the socket connection component.
Definition: endpoint.hpp:68
void listen(lib::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
Definition: endpoint.hpp:391
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:454
uint32_t level
Type of a channel package.
Definition: levels.hpp:37
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:1029
void handle_connect(transport_con_ptr tcon, timer_ptr con_timer, connect_handler callback, lib::asio::error_code const &ec)
Definition: endpoint.hpp:1052
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:803
config::concurrency_type concurrency_type
Type of the concurrency policy.
Definition: endpoint.hpp:59
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:720
void start_perpetual()
Marks the endpoint as perpetual, stopping it from exiting when empty.
Definition: endpoint.hpp:662