websocketpp  0.4.0
C++/Boost Asio based websocket client/server library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
endpoint.hpp
1 /*
2  * Copyright (c) 2014, 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 
31 #include <websocketpp/common/functional.hpp>
32 #include <websocketpp/logger/levels.hpp>
33 #include <websocketpp/transport/base/endpoint.hpp>
34 #include <websocketpp/transport/asio/connection.hpp>
35 #include <websocketpp/transport/asio/security/none.hpp>
36 
37 #include <boost/asio.hpp>
38 #include <boost/bind.hpp>
39 #include <boost/system/error_code.hpp>
40 
41 namespace websocketpp {
42 namespace transport {
43 namespace asio {
44 
46 
50 template <typename config>
51 class endpoint : public config::socket_type {
52 public:
55 
57  typedef typename config::concurrency_type concurrency_type;
59  typedef typename config::socket_type socket_type;
61  typedef typename config::elog_type elog_type;
63  typedef typename config::alog_type alog_type;
64 
66  typedef typename socket_type::socket_con_type socket_con_type;
68  typedef typename socket_con_type::ptr socket_con_ptr;
69 
76 
78  typedef boost::asio::io_service* io_service_ptr;
80  typedef lib::shared_ptr<boost::asio::ip::tcp::acceptor> acceptor_ptr;
82  typedef lib::shared_ptr<boost::asio::ip::tcp::resolver> resolver_ptr;
84  typedef lib::shared_ptr<boost::asio::deadline_timer> timer_ptr;
86  typedef lib::shared_ptr<boost::asio::io_service::work> work_ptr;
87 
88  // generate and manage our own io_service
89  explicit endpoint()
90  : m_external_io_service(false)
91  , m_listen_backlog(0)
92  , m_reuse_addr(false)
93  , m_state(UNINITIALIZED)
94  {
95  //std::cout << "transport::asio::endpoint constructor" << std::endl;
96  }
97 
98  ~endpoint() {
99  // clean up our io_service if we were initialized with an internal one.
100  m_acceptor.reset();
101  if (m_state != UNINITIALIZED && !m_external_io_service) {
102  delete m_io_service;
103  }
104  }
105 
109 #ifdef _WEBSOCKETPP_DELETED_FUNCTIONS_
110  endpoint(const endpoint& src) = delete;
111  endpoint& operator= (const endpoint & rhs) = delete;
112 #else
113 private:
114  endpoint(const endpoint& src);
115  endpoint& operator= (const endpoint & rhs);
116 public:
117 #endif
118 
119 #ifdef _WEBSOCKETPP_RVALUE_REFERENCES_
120  endpoint (endpoint&& src)
121  : m_io_service(src.m_io_service)
122  , m_external_io_service(src.m_external_io_service)
123  , m_acceptor(src.m_acceptor)
124  , m_listen_backlog(boost::asio::socket_base::max_connections)
125  , m_reuse_addr(src.m_reuse_addr)
126  , m_state(src.m_state)
127  {
128  src.m_io_service = NULL;
129  src.m_external_io_service = false;
130  src.m_acceptor = NULL;
131  src.m_state = UNINITIALIZED;
132  }
133 
134  endpoint& operator= (const endpoint && rhs) {
135  if (this != &rhs) {
136  m_io_service = rhs.m_io_service;
137  m_external_io_service = rhs.m_external_io_service;
138  m_acceptor = rhs.m_acceptor;
139  m_listen_backlog = rhs.m_listen_backlog;
140  m_reuse_addr = rhs.m_reuse_addr;
141  m_state = rhs.m_state;
142 
143  rhs.m_io_service = NULL;
144  rhs.m_external_io_service = false;
145  rhs.m_acceptor = NULL;
146  rhs.m_listen_backlog = boost::asio::socket_base::max_connections;
147  rhs.m_state = UNINITIALIZED;
148  }
149  return *this;
150  }
151 #endif
152  bool is_secure() const {
154  return socket_type::is_secure();
155  }
156 
158 
166  void init_asio(io_service_ptr ptr, lib::error_code & ec) {
167  if (m_state != UNINITIALIZED) {
168  m_elog->write(log::elevel::library,
169  "asio::init_asio called from the wrong state");
170  using websocketpp::error::make_error_code;
171  ec = make_error_code(websocketpp::error::invalid_state);
172  return;
173  }
174 
175  m_alog->write(log::alevel::devel,"asio::init_asio");
176 
177  m_io_service = ptr;
178  m_external_io_service = true;
179  m_acceptor = lib::make_shared<boost::asio::ip::tcp::acceptor>(
180  lib::ref(*m_io_service));
181 
182  m_state = READY;
183  ec = lib::error_code();
184  }
185 
187 
194  void init_asio(io_service_ptr ptr) {
195  lib::error_code ec;
196  init_asio(ptr,ec);
197  if (ec) { throw exception(ec); }
198  }
199 
201 
209  void init_asio(lib::error_code & ec) {
210  init_asio(new boost::asio::io_service(), ec);
211  m_external_io_service = false;
212  }
213 
215 
221  void init_asio() {
222  init_asio(new boost::asio::io_service());
223  m_external_io_service = false;
224  }
225 
227 
236  void set_tcp_pre_init_handler(tcp_init_handler h) {
237  m_tcp_pre_init_handler = h;
238  }
239 
241 
250  void set_tcp_init_handler(tcp_init_handler h) {
252  }
253 
255 
265  void set_tcp_post_init_handler(tcp_init_handler h) {
266  m_tcp_post_init_handler = h;
267  }
268 
270 
288  void set_listen_backlog(int backlog) {
289  m_listen_backlog = backlog;
290  }
291 
293 
306  void set_reuse_addr(bool value) {
307  m_reuse_addr = value;
308  }
309 
311 
321  boost::asio::io_service & get_io_service() {
322  return *m_io_service;
323  }
324 
326 
333  void listen(boost::asio::ip::tcp::endpoint const & ep, lib::error_code & ec)
334  {
335  if (m_state != READY) {
336  m_elog->write(log::elevel::library,
337  "asio::listen called from the wrong state");
338  using websocketpp::error::make_error_code;
339  ec = make_error_code(websocketpp::error::invalid_state);
340  return;
341  }
342 
343  m_alog->write(log::alevel::devel,"asio::listen");
344 
345  boost::system::error_code bec;
346 
347  m_acceptor->open(ep.protocol(),bec);
348  if (!bec) {
349  m_acceptor->set_option(boost::asio::socket_base::reuse_address(m_reuse_addr),bec);
350  }
351  if (!bec) {
352  m_acceptor->bind(ep,bec);
353  }
354  if (!bec) {
355  m_acceptor->listen(m_listen_backlog,bec);
356  }
357  if (bec) {
358  log_err(log::elevel::info,"asio listen",bec);
359  ec = make_error_code(error::pass_through);
360  } else {
361  m_state = LISTENING;
362  ec = lib::error_code();
363  }
364  }
365 
367 
372  void listen(boost::asio::ip::tcp::endpoint const & ep) {
373  lib::error_code ec;
374  listen(ep,ec);
375  if (ec) { throw exception(ec); }
376  }
377 
379 
392  template <typename InternetProtocol>
393  void listen(InternetProtocol const & internet_protocol, uint16_t port,
394  lib::error_code & ec)
395  {
396  boost::asio::ip::tcp::endpoint ep(internet_protocol, port);
397  listen(ep,ec);
398  }
399 
401 
413  template <typename InternetProtocol>
414  void listen(InternetProtocol const & internet_protocol, uint16_t port)
415  {
416  boost::asio::ip::tcp::endpoint ep(internet_protocol, port);
417  listen(ep);
418  }
419 
421 
432  void listen(uint16_t port, lib::error_code & ec) {
433  listen(boost::asio::ip::tcp::v6(), port, ec);
434  }
435 
437 
448  void listen(uint16_t port) {
449  listen(boost::asio::ip::tcp::v6(), port);
450  }
451 
453 
468  void listen(std::string const & host, std::string const & service,
469  lib::error_code & ec)
470  {
471  using boost::asio::ip::tcp;
472  tcp::resolver r(*m_io_service);
473  tcp::resolver::query query(host, service);
474  tcp::resolver::iterator endpoint_iterator = r.resolve(query);
475  tcp::resolver::iterator end;
476  if (endpoint_iterator == end) {
477  m_elog->write(log::elevel::library,
478  "asio::listen could not resolve the supplied host or service");
479  ec = make_error_code(error::invalid_host_service);
480  return;
481  }
482  listen(*endpoint_iterator,ec);
483  }
484 
486 
501  void listen(std::string const & host, std::string const & service)
502  {
503  lib::error_code ec;
504  listen(host,service,ec);
505  if (ec) { throw exception(ec); }
506  }
507 
509 
516  void stop_listening(lib::error_code & ec) {
517  if (m_state != LISTENING) {
518  m_elog->write(log::elevel::library,
519  "asio::listen called from the wrong state");
520  using websocketpp::error::make_error_code;
521  ec = make_error_code(websocketpp::error::invalid_state);
522  return;
523  }
524 
525  m_acceptor->close();
526  m_state = READY;
527  ec = lib::error_code();
528  }
529 
531 
537  void stop_listening() {
538  lib::error_code ec;
539  stop_listening(ec);
540  if (ec) { throw exception(ec); }
541  }
542 
544 
547  bool is_listening() const {
548  return (m_state == LISTENING);
549  }
550 
552  std::size_t run() {
553  return m_io_service->run();
554  }
555 
557 
560  std::size_t run_one() {
561  return m_io_service->run_one();
562  }
563 
565  void stop() {
566  m_io_service->stop();
567  }
568 
570  std::size_t poll() {
571  return m_io_service->poll();
572  }
573 
575  std::size_t poll_one() {
576  return m_io_service->poll_one();
577  }
578 
580  void reset() {
581  m_io_service->reset();
582  }
583 
585  bool stopped() const {
586  return m_io_service->stopped();
587  }
588 
590 
602  m_work = lib::make_shared<boost::asio::io_service::work>(
603  lib::ref(*m_io_service)
604  );
605  }
606 
608 
615  void stop_perpetual() {
616  m_work.reset();
617  }
618 
620 
631  timer_ptr set_timer(long duration, timer_handler callback) {
632  timer_ptr new_timer = lib::make_shared<boost::asio::deadline_timer>(
633  *m_io_service,
634  boost::posix_time::milliseconds(duration)
635  );
636 
637  new_timer->async_wait(
638  lib::bind(
640  this,
641  new_timer,
642  callback,
643  lib::placeholders::_1
644  )
645  );
646 
647  return new_timer;
648  }
649 
651 
659  void handle_timer(timer_ptr, timer_handler callback,
660  boost::system::error_code const & ec)
661  {
662  if (ec) {
663  if (ec == boost::asio::error::operation_aborted) {
664  callback(make_error_code(transport::error::operation_aborted));
665  } else {
666  m_elog->write(log::elevel::info,
667  "asio handle_timer error: "+ec.message());
668  log_err(log::elevel::info,"asio handle_timer",ec);
669  callback(make_error_code(error::pass_through));
670  }
671  } else {
672  callback(lib::error_code());
673  }
674  }
675 
677 
682  void async_accept(transport_con_ptr tcon, accept_handler callback,
683  lib::error_code & ec)
684  {
685  if (m_state != LISTENING) {
686  using websocketpp::error::make_error_code;
688  return;
689  }
690 
691  m_alog->write(log::alevel::devel, "asio::async_accept");
692 
693  if (config::enable_multithreading) {
694  m_acceptor->async_accept(
695  tcon->get_raw_socket(),
696  tcon->get_strand()->wrap(lib::bind(
697  &type::handle_accept,
698  this,
699  callback,
700  lib::placeholders::_1
701  ))
702  );
703  } else {
704  m_acceptor->async_accept(
705  tcon->get_raw_socket(),
706  lib::bind(
707  &type::handle_accept,
708  this,
709  callback,
710  lib::placeholders::_1
711  )
712  );
713  }
714  }
715 
717 
721  void async_accept(transport_con_ptr tcon, accept_handler callback) {
722  lib::error_code ec;
723  async_accept(tcon,callback,ec);
724  if (ec) { throw exception(ec); }
725  }
726 protected:
728 
737  void init_logging(alog_type* a, elog_type* e) {
738  m_alog = a;
739  m_elog = e;
740  }
741 
742  void handle_accept(accept_handler callback, boost::system::error_code const
743  & boost_ec)
744  {
745  lib::error_code ret_ec;
746 
747  m_alog->write(log::alevel::devel, "asio::handle_accept");
748 
749  if (boost_ec) {
750  if (boost_ec == boost::system::errc::operation_canceled) {
751  ret_ec = make_error_code(websocketpp::error::operation_canceled);
752  } else {
753  log_err(log::elevel::info,"asio handle_accept",boost_ec);
754  ret_ec = make_error_code(error::pass_through);
755  }
756  }
757 
758  callback(ret_ec);
759  }
760 
762  // TODO: there have to be some more failure conditions here
763  void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb) {
764  using namespace boost::asio::ip;
765 
766  // Create a resolver
767  if (!m_resolver) {
768  m_resolver = lib::make_shared<boost::asio::ip::tcp::resolver>(
769  lib::ref(*m_io_service));
770  }
771 
772  std::string proxy = tcon->get_proxy();
773  std::string host;
774  std::string port;
775 
776  if (proxy.empty()) {
777  host = u->get_host();
778  port = u->get_port_str();
779  } else {
780  lib::error_code ec;
781 
782  uri_ptr pu = lib::make_shared<uri>(proxy);
783 
784  if (!pu->get_valid()) {
785  cb(make_error_code(error::proxy_invalid));
786  return;
787  }
788 
789  ec = tcon->proxy_init(u->get_authority());
790  if (ec) {
791  cb(ec);
792  return;
793  }
794 
795  host = pu->get_host();
796  port = pu->get_port_str();
797  }
798 
799  tcp::resolver::query query(host,port);
800 
801  if (m_alog->static_test(log::alevel::devel)) {
802  m_alog->write(log::alevel::devel,
803  "starting async DNS resolve for "+host+":"+port);
804  }
805 
806  timer_ptr dns_timer;
807 
808  dns_timer = tcon->set_timer(
809  config::timeout_dns_resolve,
810  lib::bind(
812  this,
813  dns_timer,
814  cb,
815  lib::placeholders::_1
816  )
817  );
818 
819  if (config::enable_multithreading) {
820  m_resolver->async_resolve(
821  query,
822  tcon->get_strand()->wrap(lib::bind(
823  &type::handle_resolve,
824  this,
825  tcon,
826  dns_timer,
827  cb,
828  lib::placeholders::_1,
829  lib::placeholders::_2
830  ))
831  );
832  } else {
833  m_resolver->async_resolve(
834  query,
835  lib::bind(
836  &type::handle_resolve,
837  this,
838  tcon,
839  dns_timer,
840  cb,
841  lib::placeholders::_1,
842  lib::placeholders::_2
843  )
844  );
845  }
846  }
847 
849 
857  void handle_resolve_timeout(timer_ptr, connect_handler callback,
858  lib::error_code const & ec)
859  {
860  lib::error_code ret_ec;
861 
862  if (ec) {
864  m_alog->write(log::alevel::devel,
865  "asio handle_resolve_timeout timer cancelled");
866  return;
867  }
868 
869  log_err(log::elevel::devel,"asio handle_resolve_timeout",ec);
870  ret_ec = ec;
871  } else {
872  ret_ec = make_error_code(transport::error::timeout);
873  }
874 
875  m_alog->write(log::alevel::devel,"DNS resolution timed out");
876  m_resolver->cancel();
877  callback(ret_ec);
878  }
879 
880  void handle_resolve(transport_con_ptr tcon, timer_ptr dns_timer,
881  connect_handler callback, boost::system::error_code const & ec,
882  boost::asio::ip::tcp::resolver::iterator iterator)
883  {
884  if (ec == boost::asio::error::operation_aborted ||
885  dns_timer->expires_from_now().is_negative())
886  {
887  m_alog->write(log::alevel::devel,"async_resolve cancelled");
888  return;
889  }
890 
891  dns_timer->cancel();
892 
893  if (ec) {
894  log_err(log::elevel::info,"asio async_resolve",ec);
895  callback(make_error_code(error::pass_through));
896  return;
897  }
898 
899  if (m_alog->static_test(log::alevel::devel)) {
900  std::stringstream s;
901  s << "Async DNS resolve successful. Results: ";
902 
903  boost::asio::ip::tcp::resolver::iterator it, end;
904  for (it = iterator; it != end; ++it) {
905  s << (*it).endpoint() << " ";
906  }
907 
908  m_alog->write(log::alevel::devel,s.str());
909  }
910 
911  m_alog->write(log::alevel::devel,"Starting async connect");
912 
913  timer_ptr con_timer;
914 
915  con_timer = tcon->set_timer(
916  config::timeout_connect,
917  lib::bind(
919  this,
920  tcon,
921  con_timer,
922  callback,
923  lib::placeholders::_1
924  )
925  );
926 
927  if (config::enable_multithreading) {
928  boost::asio::async_connect(
929  tcon->get_raw_socket(),
930  iterator,
931  tcon->get_strand()->wrap(lib::bind(
932  &type::handle_connect,
933  this,
934  tcon,
935  con_timer,
936  callback,
937  lib::placeholders::_1
938  ))
939  );
940  } else {
941  boost::asio::async_connect(
942  tcon->get_raw_socket(),
943  iterator,
944  lib::bind(
945  &type::handle_connect,
946  this,
947  tcon,
948  con_timer,
949  callback,
950  lib::placeholders::_1
951  )
952  );
953  }
954  }
955 
957 
966  void handle_connect_timeout(transport_con_ptr tcon, timer_ptr,
967  connect_handler callback, lib::error_code const & ec)
968  {
969  lib::error_code ret_ec;
970 
971  if (ec) {
973  m_alog->write(log::alevel::devel,
974  "asio handle_connect_timeout timer cancelled");
975  return;
976  }
977 
978  log_err(log::elevel::devel,"asio handle_connect_timeout",ec);
979  ret_ec = ec;
980  } else {
981  ret_ec = make_error_code(transport::error::timeout);
982  }
983 
984  m_alog->write(log::alevel::devel,"TCP connect timed out");
985  tcon->cancel_socket();
986  callback(ret_ec);
987  }
988 
989  void handle_connect(transport_con_ptr tcon, timer_ptr con_timer,
990  connect_handler callback, boost::system::error_code const & ec)
991  {
992  if (ec == boost::asio::error::operation_aborted ||
993  con_timer->expires_from_now().is_negative())
994  {
995  m_alog->write(log::alevel::devel,"async_connect cancelled");
996  return;
997  }
998 
999  con_timer->cancel();
1000 
1001  if (ec) {
1002  log_err(log::elevel::info,"asio async_connect",ec);
1003  callback(make_error_code(error::pass_through));
1004  return;
1005  }
1006 
1007  if (m_alog->static_test(log::alevel::devel)) {
1008  m_alog->write(log::alevel::devel,
1009  "Async connect to "+tcon->get_remote_endpoint()+" successful.");
1010  }
1011 
1012  callback(lib::error_code());
1013  }
1014 
1016 
1026  lib::error_code init(transport_con_ptr tcon) {
1027  m_alog->write(log::alevel::devel, "transport::asio::init");
1028 
1029  // Initialize the connection socket component
1030  socket_type::init(lib::static_pointer_cast<socket_con_type,
1031  transport_con_type>(tcon));
1032 
1033  lib::error_code ec;
1034 
1035  ec = tcon->init_asio(m_io_service);
1036  if (ec) {return ec;}
1037 
1038  tcon->set_tcp_pre_init_handler(m_tcp_pre_init_handler);
1039  tcon->set_tcp_post_init_handler(m_tcp_post_init_handler);
1040 
1041  return lib::error_code();
1042  }
1043 private:
1045  template <typename error_type>
1046  void log_err(log::level l, char const * msg, error_type const & ec) {
1047  std::stringstream s;
1048  s << msg << " error: " << ec << " (" << ec.message() << ")";
1049  m_elog->write(l,s.str());
1050  }
1051 
1052  enum state {
1053  UNINITIALIZED = 0,
1054  READY = 1,
1055  LISTENING = 2
1056  };
1057 
1058  // Handlers
1059  tcp_init_handler m_tcp_pre_init_handler;
1060  tcp_init_handler m_tcp_post_init_handler;
1061 
1062  // Network Resources
1063  io_service_ptr m_io_service;
1064  bool m_external_io_service;
1065  acceptor_ptr m_acceptor;
1066  resolver_ptr m_resolver;
1067  work_ptr m_work;
1068 
1069  // Network constants
1070  int m_listen_backlog;
1071  bool m_reuse_addr;
1072 
1073  elog_type* m_elog;
1074  alog_type* m_alog;
1075 
1076  // Transport state
1077  state m_state;
1078 };
1079 
1080 } // namespace asio
1081 } // namespace transport
1082 } // namespace websocketpp
1083 
1084 #endif // WEBSOCKETPP_TRANSPORT_ASIO_HPP
void stop_listening(lib::error_code &ec)
Stop listening (exception free)
Definition: endpoint.hpp:516
lib::shared_ptr< boost::asio::ip::tcp::acceptor > acceptor_ptr
Type of a shared pointer to the acceptor being used.
Definition: endpoint.hpp:80
void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb)
Initiate a new connection.
Definition: endpoint.hpp:763
transport_con_type::ptr transport_con_ptr
Definition: endpoint.hpp:75
boost::asio::io_service * io_service_ptr
Type of a pointer to the ASIO io_service being used.
Definition: endpoint.hpp:78
lib::shared_ptr< boost::asio::deadline_timer > timer_ptr
Type of timer handle.
Definition: endpoint.hpp:84
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:966
uint16_t value
The type of a close code value.
Definition: close.hpp:49
lib::shared_ptr< boost::asio::ip::tcp::resolver > resolver_ptr
Type of a shared pointer to the resolver being used.
Definition: endpoint.hpp:82
config::alog_type alog_type
Type of the access logging policy.
Definition: endpoint.hpp:63
void listen(boost::asio::ip::tcp::endpoint const &ep)
Set up endpoint for listening manually.
Definition: endpoint.hpp:372
void listen(InternetProtocol const &internet_protocol, uint16_t port)
Set up endpoint for listening with protocol and port.
Definition: endpoint.hpp:414
void set_listen_backlog(int backlog)
Sets the maximum length of the queue of pending connections.
Definition: endpoint.hpp:288
void listen(uint16_t port)
Set up endpoint for listening on a port.
Definition: endpoint.hpp:448
void stop_listening()
Stop listening.
Definition: endpoint.hpp:537
void init_asio(lib::error_code &ec)
Initialize asio transport with internal io_service (exception free)
Definition: endpoint.hpp:209
void set_tcp_init_handler(tcp_init_handler h)
Sets the tcp pre init handler (deprecated)
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:74
void start_perpetual()
Marks the endpoint as perpetual, stopping it from exiting when empty.
Definition: endpoint.hpp:601
bool is_secure() const
Return whether or not the endpoint produces secure connections.
Definition: endpoint.hpp:153
void init_asio()
Initialize asio transport with internal io_service.
Definition: endpoint.hpp:221
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:468
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
Definition: endpoint.hpp:166
void set_reuse_addr(bool value)
Sets whether to use the SO_REUSEADDR flag when opening listening sockets.
Definition: endpoint.hpp:306
std::size_t run_one()
wraps the run_one method of the internal io_service object
Definition: endpoint.hpp:560
static level const devel
Low level debugging information (warning: very chatty)
Definition: levels.hpp:63
void listen(uint16_t port, lib::error_code &ec)
Set up endpoint for listening on a port (exception free)
Definition: endpoint.hpp:432
bool is_listening() const
Check if the endpoint is listening.
Definition: endpoint.hpp:547
boost::asio::io_service & get_io_service()
Retrieve a reference to the endpoint's io_service.
Definition: endpoint.hpp:321
config::elog_type elog_type
Type of the error logging policy.
Definition: endpoint.hpp:61
asio::connection< config > transport_con_type
Definition: endpoint.hpp:72
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.
Definition: connection.hpp:67
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
Definition: endpoint.hpp:1026
static level const devel
Development messages (warning: very chatty)
Definition: levels.hpp:141
void reset()
wraps the reset method of the internal io_service object
Definition: endpoint.hpp:580
socket_con_type::ptr socket_con_ptr
Type of a shared pointer to the socket connection component.
Definition: endpoint.hpp:68
void handle_timer(timer_ptr, timer_handler callback, boost::system::error_code const &ec)
Timer handler.
Definition: endpoint.hpp:659
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:393
lib::shared_ptr< boost::asio::io_service::work > work_ptr
Type of a shared pointer to an io_service work object.
Definition: endpoint.hpp:86
void stop_perpetual()
Clears the endpoint's perpetual flag, allowing it to exit when empty.
Definition: endpoint.hpp:615
void listen(boost::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
Definition: endpoint.hpp:333
The connection was in the wrong state for this operation.
Definition: error.hpp:72
static level const info
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:125
there was an error in the underlying transport library
Definition: base.hpp:190
Namespace for the WebSocket++ project.
Definition: base64.hpp:41
std::size_t poll()
wraps the poll method of the internal io_service object
Definition: endpoint.hpp:570
void set_tcp_post_init_handler(tcp_init_handler h)
Sets the tcp post init handler.
Definition: endpoint.hpp:265
The requested operation was canceled.
Definition: error.hpp:125
void stop()
wraps the stop method of the internal io_service object
Definition: endpoint.hpp:565
Creates and manages connections associated with a WebSocket endpoint.
Definition: endpoint.hpp:41
Boost Asio based connection transport component.
Definition: connection.hpp:62
Boost Asio based endpoint transport component.
Definition: base.hpp:159
timer_ptr set_timer(long duration, timer_handler callback)
Call back a function after a period of time.
Definition: endpoint.hpp:631
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Definition: uri.hpp:350
std::size_t run()
wraps the run method of the internal io_service object
Definition: endpoint.hpp:552
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:682
void listen(std::string const &host, std::string const &service)
Set up endpoint for listening on a host and service.
Definition: endpoint.hpp:501
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
Definition: endpoint.hpp:236
config::socket_type socket_type
Type of the socket policy.
Definition: endpoint.hpp:59
bool stopped() const
wraps the stopped method of the internal io_service object
Definition: endpoint.hpp:585
config::concurrency_type concurrency_type
Type of the concurrency policy.
Definition: endpoint.hpp:57
void async_accept(transport_con_ptr tcon, accept_handler callback)
Accept the next connection attempt and assign it to con.
Definition: endpoint.hpp:721
void init_asio(io_service_ptr ptr)
initialize asio transport with external io_service
Definition: endpoint.hpp:194
std::size_t poll_one()
wraps the poll_one method of the internal io_service object
Definition: endpoint.hpp:575
void handle_resolve_timeout(timer_ptr, connect_handler callback, lib::error_code const &ec)
DNS resolution timeout handler.
Definition: endpoint.hpp:857
endpoint< config > type
Type of this endpoint transport component.
Definition: endpoint.hpp:54
static level const library
Definition: levels.hpp:66
socket_type::socket_con_type socket_con_type
Type of the socket connection component.
Definition: endpoint.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:77
void init_logging(alog_type *a, elog_type *e)
Initialize logging.
Definition: endpoint.hpp:737