websocketpp  0.5.1
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/transport/base/endpoint.hpp>
32 #include <websocketpp/transport/asio/connection.hpp>
33 #include <websocketpp/transport/asio/security/none.hpp>
34 
35 #include <websocketpp/uri.hpp>
36 #include <websocketpp/logger/levels.hpp>
37 
38 #include <websocketpp/common/functional.hpp>
39 
40 #include <boost/asio.hpp>
41 #include <boost/bind.hpp>
42 #include <boost/system/error_code.hpp>
43 
44 #include <sstream>
45 #include <string>
46 
47 namespace websocketpp {
48 namespace transport {
49 namespace asio {
50 
52 
56 template <typename config>
57 class endpoint : public config::socket_type {
58 public:
61 
63  typedef typename config::concurrency_type concurrency_type;
65  typedef typename config::socket_type socket_type;
67  typedef typename config::elog_type elog_type;
69  typedef typename config::alog_type alog_type;
70 
72  typedef typename socket_type::socket_con_type socket_con_type;
74  typedef typename socket_con_type::ptr socket_con_ptr;
75 
82 
84  typedef boost::asio::io_service* io_service_ptr;
86  typedef lib::shared_ptr<boost::asio::ip::tcp::acceptor> acceptor_ptr;
88  typedef lib::shared_ptr<boost::asio::ip::tcp::resolver> resolver_ptr;
90  typedef lib::shared_ptr<boost::asio::deadline_timer> timer_ptr;
92  typedef lib::shared_ptr<boost::asio::io_service::work> work_ptr;
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(0)
99  , m_reuse_addr(false)
100  , m_state(UNINITIALIZED)
101  {
102  //std::cout << "transport::asio::endpoint constructor" << std::endl;
103  }
104 
105  ~endpoint() {
106  // clean up our io_service if we were initialized with an internal one.
107  m_acceptor.reset();
108  if (m_state != UNINITIALIZED && !m_external_io_service) {
109  delete m_io_service;
110  }
111  }
112 
116 #ifdef _WEBSOCKETPP_DELETED_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
125 
126 #ifdef _WEBSOCKETPP_RVALUE_REFERENCES_
127  endpoint (endpoint&& src)
128  : m_io_service(src.m_io_service)
129  , m_external_io_service(src.m_external_io_service)
130  , m_acceptor(src.m_acceptor)
131  , m_listen_backlog(boost::asio::socket_base::max_connections)
132  , m_reuse_addr(src.m_reuse_addr)
133  , m_state(src.m_state)
134  {
135  src.m_io_service = NULL;
136  src.m_external_io_service = false;
137  src.m_acceptor = NULL;
138  src.m_state = UNINITIALIZED;
139  }
140 
141  endpoint& operator= (const endpoint && rhs) {
142  if (this != &rhs) {
143  m_io_service = rhs.m_io_service;
144  m_external_io_service = rhs.m_external_io_service;
145  m_acceptor = rhs.m_acceptor;
146  m_listen_backlog = rhs.m_listen_backlog;
147  m_reuse_addr = rhs.m_reuse_addr;
148  m_state = rhs.m_state;
149 
150  rhs.m_io_service = NULL;
151  rhs.m_external_io_service = false;
152  rhs.m_acceptor = NULL;
153  rhs.m_listen_backlog = boost::asio::socket_base::max_connections;
154  rhs.m_state = UNINITIALIZED;
155  }
156  return *this;
157  }
158 #endif
159  bool is_secure() const {
161  return socket_type::is_secure();
162  }
163 
165 
173  void init_asio(io_service_ptr ptr, lib::error_code & ec) {
174  if (m_state != UNINITIALIZED) {
175  m_elog->write(log::elevel::library,
176  "asio::init_asio called from the wrong state");
177  using websocketpp::error::make_error_code;
178  ec = make_error_code(websocketpp::error::invalid_state);
179  return;
180  }
181 
182  m_alog->write(log::alevel::devel,"asio::init_asio");
183 
184  m_io_service = ptr;
185  m_external_io_service = true;
186  m_acceptor = lib::make_shared<boost::asio::ip::tcp::acceptor>(
187  lib::ref(*m_io_service));
188 
189  m_state = READY;
190  ec = lib::error_code();
191  }
192 
194 
201  void init_asio(io_service_ptr ptr) {
202  lib::error_code ec;
203  init_asio(ptr,ec);
204  if (ec) { throw exception(ec); }
205  }
206 
208 
216  void init_asio(lib::error_code & ec) {
217  init_asio(new boost::asio::io_service(), ec);
218  m_external_io_service = false;
219  }
220 
222 
228  void init_asio() {
229  init_asio(new boost::asio::io_service());
230  m_external_io_service = false;
231  }
232 
234 
243  void set_tcp_pre_init_handler(tcp_init_handler h) {
244  m_tcp_pre_init_handler = h;
245  }
246 
248 
257  void set_tcp_init_handler(tcp_init_handler h) {
259  }
260 
262 
272  void set_tcp_post_init_handler(tcp_init_handler h) {
273  m_tcp_post_init_handler = h;
274  }
275 
277 
295  void set_listen_backlog(int backlog) {
296  m_listen_backlog = backlog;
297  }
298 
300 
313  void set_reuse_addr(bool value) {
314  m_reuse_addr = value;
315  }
316 
318 
328  boost::asio::io_service & get_io_service() {
329  return *m_io_service;
330  }
331 
333 
340  void listen(boost::asio::ip::tcp::endpoint const & ep, lib::error_code & ec)
341  {
342  if (m_state != READY) {
343  m_elog->write(log::elevel::library,
344  "asio::listen called from the wrong state");
345  using websocketpp::error::make_error_code;
346  ec = make_error_code(websocketpp::error::invalid_state);
347  return;
348  }
349 
350  m_alog->write(log::alevel::devel,"asio::listen");
351 
352  boost::system::error_code bec;
353 
354  m_acceptor->open(ep.protocol(),bec);
355  if (!bec) {
356  m_acceptor->set_option(boost::asio::socket_base::reuse_address(m_reuse_addr),bec);
357  }
358  if (!bec) {
359  m_acceptor->bind(ep,bec);
360  }
361  if (!bec) {
362  m_acceptor->listen(m_listen_backlog,bec);
363  }
364  if (bec) {
365  if (m_acceptor->is_open()) {
366  m_acceptor->close();
367  }
368  log_err(log::elevel::info,"asio listen",bec);
369  ec = make_error_code(error::pass_through);
370  } else {
371  m_state = LISTENING;
372  ec = lib::error_code();
373  }
374  }
375 
377 
382  void listen(boost::asio::ip::tcp::endpoint const & ep) {
383  lib::error_code ec;
384  listen(ep,ec);
385  if (ec) { throw exception(ec); }
386  }
387 
389 
402  template <typename InternetProtocol>
403  void listen(InternetProtocol const & internet_protocol, uint16_t port,
404  lib::error_code & ec)
405  {
406  boost::asio::ip::tcp::endpoint ep(internet_protocol, port);
407  listen(ep,ec);
408  }
409 
411 
423  template <typename InternetProtocol>
424  void listen(InternetProtocol const & internet_protocol, uint16_t port)
425  {
426  boost::asio::ip::tcp::endpoint ep(internet_protocol, port);
427  listen(ep);
428  }
429 
431 
442  void listen(uint16_t port, lib::error_code & ec) {
443  listen(boost::asio::ip::tcp::v6(), port, ec);
444  }
445 
447 
458  void listen(uint16_t port) {
459  listen(boost::asio::ip::tcp::v6(), port);
460  }
461 
463 
478  void listen(std::string const & host, std::string const & service,
479  lib::error_code & ec)
480  {
481  using boost::asio::ip::tcp;
482  tcp::resolver r(*m_io_service);
483  tcp::resolver::query query(host, service);
484  tcp::resolver::iterator endpoint_iterator = r.resolve(query);
485  tcp::resolver::iterator end;
486  if (endpoint_iterator == end) {
487  m_elog->write(log::elevel::library,
488  "asio::listen could not resolve the supplied host or service");
489  ec = make_error_code(error::invalid_host_service);
490  return;
491  }
492  listen(*endpoint_iterator,ec);
493  }
494 
496 
511  void listen(std::string const & host, std::string const & service)
512  {
513  lib::error_code ec;
514  listen(host,service,ec);
515  if (ec) { throw exception(ec); }
516  }
517 
519 
526  void stop_listening(lib::error_code & ec) {
527  if (m_state != LISTENING) {
528  m_elog->write(log::elevel::library,
529  "asio::listen called from the wrong state");
530  using websocketpp::error::make_error_code;
531  ec = make_error_code(websocketpp::error::invalid_state);
532  return;
533  }
534 
535  m_acceptor->close();
536  m_state = READY;
537  ec = lib::error_code();
538  }
539 
541 
547  void stop_listening() {
548  lib::error_code ec;
549  stop_listening(ec);
550  if (ec) { throw exception(ec); }
551  }
552 
554 
557  bool is_listening() const {
558  return (m_state == LISTENING);
559  }
560 
562  std::size_t run() {
563  return m_io_service->run();
564  }
565 
567 
570  std::size_t run_one() {
571  return m_io_service->run_one();
572  }
573 
575  void stop() {
576  m_io_service->stop();
577  }
578 
580  std::size_t poll() {
581  return m_io_service->poll();
582  }
583 
585  std::size_t poll_one() {
586  return m_io_service->poll_one();
587  }
588 
590  void reset() {
591  m_io_service->reset();
592  }
593 
595  bool stopped() const {
596  return m_io_service->stopped();
597  }
598 
600 
612  m_work = lib::make_shared<boost::asio::io_service::work>(
613  lib::ref(*m_io_service)
614  );
615  }
616 
618 
625  void stop_perpetual() {
626  m_work.reset();
627  }
628 
630 
641  timer_ptr set_timer(long duration, timer_handler callback) {
642  timer_ptr new_timer = lib::make_shared<boost::asio::deadline_timer>(
643  *m_io_service,
644  boost::posix_time::milliseconds(duration)
645  );
646 
647  new_timer->async_wait(
648  lib::bind(
650  this,
651  new_timer,
652  callback,
653  lib::placeholders::_1
654  )
655  );
656 
657  return new_timer;
658  }
659 
661 
669  void handle_timer(timer_ptr, timer_handler callback,
670  boost::system::error_code const & ec)
671  {
672  if (ec) {
673  if (ec == boost::asio::error::operation_aborted) {
674  callback(make_error_code(transport::error::operation_aborted));
675  } else {
676  m_elog->write(log::elevel::info,
677  "asio handle_timer error: "+ec.message());
678  log_err(log::elevel::info,"asio handle_timer",ec);
679  callback(make_error_code(error::pass_through));
680  }
681  } else {
682  callback(lib::error_code());
683  }
684  }
685 
687 
692  void async_accept(transport_con_ptr tcon, accept_handler callback,
693  lib::error_code & ec)
694  {
695  if (m_state != LISTENING) {
696  using websocketpp::error::make_error_code;
698  return;
699  }
700 
701  m_alog->write(log::alevel::devel, "asio::async_accept");
702 
703  if (config::enable_multithreading) {
704  m_acceptor->async_accept(
705  tcon->get_raw_socket(),
706  tcon->get_strand()->wrap(lib::bind(
707  &type::handle_accept,
708  this,
709  callback,
710  lib::placeholders::_1
711  ))
712  );
713  } else {
714  m_acceptor->async_accept(
715  tcon->get_raw_socket(),
716  lib::bind(
717  &type::handle_accept,
718  this,
719  callback,
720  lib::placeholders::_1
721  )
722  );
723  }
724  }
725 
727 
731  void async_accept(transport_con_ptr tcon, accept_handler callback) {
732  lib::error_code ec;
733  async_accept(tcon,callback,ec);
734  if (ec) { throw exception(ec); }
735  }
736 protected:
738 
747  void init_logging(alog_type* a, elog_type* e) {
748  m_alog = a;
749  m_elog = e;
750  }
751 
752  void handle_accept(accept_handler callback, boost::system::error_code const
753  & boost_ec)
754  {
755  lib::error_code ret_ec;
756 
757  m_alog->write(log::alevel::devel, "asio::handle_accept");
758 
759  if (boost_ec) {
760  if (boost_ec == boost::system::errc::operation_canceled) {
761  ret_ec = make_error_code(websocketpp::error::operation_canceled);
762  } else {
763  log_err(log::elevel::info,"asio handle_accept",boost_ec);
764  ret_ec = make_error_code(error::pass_through);
765  }
766  }
767 
768  callback(ret_ec);
769  }
770 
772  // TODO: there have to be some more failure conditions here
773  void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb) {
774  using namespace boost::asio::ip;
775 
776  // Create a resolver
777  if (!m_resolver) {
778  m_resolver = lib::make_shared<boost::asio::ip::tcp::resolver>(
779  lib::ref(*m_io_service));
780  }
781 
782  std::string proxy = tcon->get_proxy();
783  std::string host;
784  std::string port;
785 
786  if (proxy.empty()) {
787  host = u->get_host();
788  port = u->get_port_str();
789  } else {
790  lib::error_code ec;
791 
792  uri_ptr pu = lib::make_shared<uri>(proxy);
793 
794  if (!pu->get_valid()) {
795  cb(make_error_code(error::proxy_invalid));
796  return;
797  }
798 
799  ec = tcon->proxy_init(u->get_authority());
800  if (ec) {
801  cb(ec);
802  return;
803  }
804 
805  host = pu->get_host();
806  port = pu->get_port_str();
807  }
808 
809  tcp::resolver::query query(host,port);
810 
811  if (m_alog->static_test(log::alevel::devel)) {
812  m_alog->write(log::alevel::devel,
813  "starting async DNS resolve for "+host+":"+port);
814  }
815 
816  timer_ptr dns_timer;
817 
818  dns_timer = tcon->set_timer(
819  config::timeout_dns_resolve,
820  lib::bind(
822  this,
823  dns_timer,
824  cb,
825  lib::placeholders::_1
826  )
827  );
828 
829  if (config::enable_multithreading) {
830  m_resolver->async_resolve(
831  query,
832  tcon->get_strand()->wrap(lib::bind(
833  &type::handle_resolve,
834  this,
835  tcon,
836  dns_timer,
837  cb,
838  lib::placeholders::_1,
839  lib::placeholders::_2
840  ))
841  );
842  } else {
843  m_resolver->async_resolve(
844  query,
845  lib::bind(
846  &type::handle_resolve,
847  this,
848  tcon,
849  dns_timer,
850  cb,
851  lib::placeholders::_1,
852  lib::placeholders::_2
853  )
854  );
855  }
856  }
857 
859 
867  void handle_resolve_timeout(timer_ptr, connect_handler callback,
868  lib::error_code const & ec)
869  {
870  lib::error_code ret_ec;
871 
872  if (ec) {
874  m_alog->write(log::alevel::devel,
875  "asio handle_resolve_timeout timer cancelled");
876  return;
877  }
878 
879  log_err(log::elevel::devel,"asio handle_resolve_timeout",ec);
880  ret_ec = ec;
881  } else {
882  ret_ec = make_error_code(transport::error::timeout);
883  }
884 
885  m_alog->write(log::alevel::devel,"DNS resolution timed out");
886  m_resolver->cancel();
887  callback(ret_ec);
888  }
889 
890  void handle_resolve(transport_con_ptr tcon, timer_ptr dns_timer,
891  connect_handler callback, boost::system::error_code const & ec,
892  boost::asio::ip::tcp::resolver::iterator iterator)
893  {
894  if (ec == boost::asio::error::operation_aborted ||
895  dns_timer->expires_from_now().is_negative())
896  {
897  m_alog->write(log::alevel::devel,"async_resolve cancelled");
898  return;
899  }
900 
901  dns_timer->cancel();
902 
903  if (ec) {
904  log_err(log::elevel::info,"asio async_resolve",ec);
905  callback(make_error_code(error::pass_through));
906  return;
907  }
908 
909  if (m_alog->static_test(log::alevel::devel)) {
910  std::stringstream s;
911  s << "Async DNS resolve successful. Results: ";
912 
913  boost::asio::ip::tcp::resolver::iterator it, end;
914  for (it = iterator; it != end; ++it) {
915  s << (*it).endpoint() << " ";
916  }
917 
918  m_alog->write(log::alevel::devel,s.str());
919  }
920 
921  m_alog->write(log::alevel::devel,"Starting async connect");
922 
923  timer_ptr con_timer;
924 
925  con_timer = tcon->set_timer(
926  config::timeout_connect,
927  lib::bind(
929  this,
930  tcon,
931  con_timer,
932  callback,
933  lib::placeholders::_1
934  )
935  );
936 
937  if (config::enable_multithreading) {
938  boost::asio::async_connect(
939  tcon->get_raw_socket(),
940  iterator,
941  tcon->get_strand()->wrap(lib::bind(
942  &type::handle_connect,
943  this,
944  tcon,
945  con_timer,
946  callback,
947  lib::placeholders::_1
948  ))
949  );
950  } else {
951  boost::asio::async_connect(
952  tcon->get_raw_socket(),
953  iterator,
954  lib::bind(
955  &type::handle_connect,
956  this,
957  tcon,
958  con_timer,
959  callback,
960  lib::placeholders::_1
961  )
962  );
963  }
964  }
965 
967 
976  void handle_connect_timeout(transport_con_ptr tcon, timer_ptr,
977  connect_handler callback, lib::error_code const & ec)
978  {
979  lib::error_code ret_ec;
980 
981  if (ec) {
983  m_alog->write(log::alevel::devel,
984  "asio handle_connect_timeout timer cancelled");
985  return;
986  }
987 
988  log_err(log::elevel::devel,"asio handle_connect_timeout",ec);
989  ret_ec = ec;
990  } else {
991  ret_ec = make_error_code(transport::error::timeout);
992  }
993 
994  m_alog->write(log::alevel::devel,"TCP connect timed out");
995  tcon->cancel_socket();
996  callback(ret_ec);
997  }
998 
999  void handle_connect(transport_con_ptr tcon, timer_ptr con_timer,
1000  connect_handler callback, boost::system::error_code const & ec)
1001  {
1002  if (ec == boost::asio::error::operation_aborted ||
1003  con_timer->expires_from_now().is_negative())
1004  {
1005  m_alog->write(log::alevel::devel,"async_connect cancelled");
1006  return;
1007  }
1008 
1009  con_timer->cancel();
1010 
1011  if (ec) {
1012  log_err(log::elevel::info,"asio async_connect",ec);
1013  callback(make_error_code(error::pass_through));
1014  return;
1015  }
1016 
1017  if (m_alog->static_test(log::alevel::devel)) {
1018  m_alog->write(log::alevel::devel,
1019  "Async connect to "+tcon->get_remote_endpoint()+" successful.");
1020  }
1021 
1022  callback(lib::error_code());
1023  }
1024 
1026 
1036  lib::error_code init(transport_con_ptr tcon) {
1037  m_alog->write(log::alevel::devel, "transport::asio::init");
1038 
1039  // Initialize the connection socket component
1040  socket_type::init(lib::static_pointer_cast<socket_con_type,
1041  transport_con_type>(tcon));
1042 
1043  lib::error_code ec;
1044 
1045  ec = tcon->init_asio(m_io_service);
1046  if (ec) {return ec;}
1047 
1048  tcon->set_tcp_pre_init_handler(m_tcp_pre_init_handler);
1049  tcon->set_tcp_post_init_handler(m_tcp_post_init_handler);
1050 
1051  return lib::error_code();
1052  }
1053 private:
1055  template <typename error_type>
1056  void log_err(log::level l, char const * msg, error_type const & ec) {
1057  std::stringstream s;
1058  s << msg << " error: " << ec << " (" << ec.message() << ")";
1059  m_elog->write(l,s.str());
1060  }
1061 
1062  enum state {
1063  UNINITIALIZED = 0,
1064  READY = 1,
1065  LISTENING = 2
1066  };
1067 
1068  // Handlers
1069  tcp_init_handler m_tcp_pre_init_handler;
1070  tcp_init_handler m_tcp_post_init_handler;
1071 
1072  // Network Resources
1073  io_service_ptr m_io_service;
1074  bool m_external_io_service;
1075  acceptor_ptr m_acceptor;
1076  resolver_ptr m_resolver;
1077  work_ptr m_work;
1078 
1079  // Network constants
1080  int m_listen_backlog;
1081  bool m_reuse_addr;
1082 
1083  elog_type* m_elog;
1084  alog_type* m_alog;
1085 
1086  // Transport state
1087  state m_state;
1088 };
1089 
1090 } // namespace asio
1091 } // namespace transport
1092 } // namespace websocketpp
1093 
1094 #endif // WEBSOCKETPP_TRANSPORT_ASIO_HPP
void stop_listening(lib::error_code &ec)
Stop listening (exception free)
Definition: endpoint.hpp:526
lib::shared_ptr< boost::asio::ip::tcp::acceptor > acceptor_ptr
Type of a shared pointer to the acceptor being used.
Definition: endpoint.hpp:86
void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb)
Initiate a new connection.
Definition: endpoint.hpp:773
transport_con_type::ptr transport_con_ptr
Definition: endpoint.hpp:81
boost::asio::io_service * io_service_ptr
Type of a pointer to the ASIO io_service being used.
Definition: endpoint.hpp:84
lib::shared_ptr< boost::asio::deadline_timer > timer_ptr
Type of timer handle.
Definition: endpoint.hpp:90
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:976
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:88
config::alog_type alog_type
Type of the access logging policy.
Definition: endpoint.hpp:69
void listen(boost::asio::ip::tcp::endpoint const &ep)
Set up endpoint for listening manually.
Definition: endpoint.hpp:382
void listen(InternetProtocol const &internet_protocol, uint16_t port)
Set up endpoint for listening with protocol and port.
Definition: endpoint.hpp:424
void set_listen_backlog(int backlog)
Sets the maximum length of the queue of pending connections.
Definition: endpoint.hpp:295
void listen(uint16_t port)
Set up endpoint for listening on a port.
Definition: endpoint.hpp:458
void stop_listening()
Stop listening.
Definition: endpoint.hpp:547
void init_asio(lib::error_code &ec)
Initialize asio transport with internal io_service (exception free)
Definition: endpoint.hpp:216
void set_tcp_init_handler(tcp_init_handler h)
Sets the tcp pre init handler (deprecated)
Definition: endpoint.hpp:257
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
void start_perpetual()
Marks the endpoint as perpetual, stopping it from exiting when empty.
Definition: endpoint.hpp:611
bool is_secure() const
Return whether or not the endpoint produces secure connections.
Definition: endpoint.hpp:160
void init_asio()
Initialize asio transport with internal io_service.
Definition: endpoint.hpp:228
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:478
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
Definition: endpoint.hpp:173
void set_reuse_addr(bool value)
Sets whether to use the SO_REUSEADDR flag when opening listening sockets.
Definition: endpoint.hpp:313
std::size_t run_one()
wraps the run_one method of the internal io_service object
Definition: endpoint.hpp:570
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:442
bool is_listening() const
Check if the endpoint is listening.
Definition: endpoint.hpp:557
boost::asio::io_service & get_io_service()
Retrieve a reference to the endpoint's io_service.
Definition: endpoint.hpp:328
config::elog_type elog_type
Type of the error logging policy.
Definition: endpoint.hpp:67
asio::connection< config > transport_con_type
Definition: endpoint.hpp:78
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.
Definition: connection.hpp:72
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
Definition: endpoint.hpp:1036
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:590
socket_con_type::ptr socket_con_ptr
Type of a shared pointer to the socket connection component.
Definition: endpoint.hpp:74
void handle_timer(timer_ptr, timer_handler callback, boost::system::error_code const &ec)
Timer handler.
Definition: endpoint.hpp:669
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:403
lib::shared_ptr< boost::asio::io_service::work > work_ptr
Type of a shared pointer to an io_service work object.
Definition: endpoint.hpp:92
void stop_perpetual()
Clears the endpoint's perpetual flag, allowing it to exit when empty.
Definition: endpoint.hpp:625
void listen(boost::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
Definition: endpoint.hpp:340
The connection was in the wrong state for this operation.
Definition: error.hpp:74
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:126
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:580
void set_tcp_post_init_handler(tcp_init_handler h)
Sets the tcp post init handler.
Definition: endpoint.hpp:272
The requested operation was canceled.
Definition: error.hpp:127
void stop()
wraps the stop method of the internal io_service object
Definition: endpoint.hpp:575
Creates and manages connections associated with a WebSocket endpoint.
Definition: endpoint.hpp:42
Boost Asio based connection transport component.
Definition: connection.hpp:67
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:641
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:562
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:692
void listen(std::string const &host, std::string const &service)
Set up endpoint for listening on a host and service.
Definition: endpoint.hpp:511
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
Definition: endpoint.hpp:243
config::socket_type socket_type
Type of the socket policy.
Definition: endpoint.hpp:65
bool stopped() const
wraps the stopped method of the internal io_service object
Definition: endpoint.hpp:595
config::concurrency_type concurrency_type
Type of the concurrency policy.
Definition: endpoint.hpp:63
void async_accept(transport_con_ptr tcon, accept_handler callback)
Accept the next connection attempt and assign it to con.
Definition: endpoint.hpp:731
void init_asio(io_service_ptr ptr)
initialize asio transport with external io_service
Definition: endpoint.hpp:201
std::size_t poll_one()
wraps the poll_one method of the internal io_service object
Definition: endpoint.hpp:585
void handle_resolve_timeout(timer_ptr, connect_handler callback, lib::error_code const &ec)
DNS resolution timeout handler.
Definition: endpoint.hpp:867
endpoint< config > type
Type of this endpoint transport component.
Definition: endpoint.hpp:60
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:72
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 init_logging(alog_type *a, elog_type *e)
Initialize logging.
Definition: endpoint.hpp:747