Clementine
basic_socket.hpp
1 //
2 // basic_socket.hpp
3 // ~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_BASIC_SOCKET_HPP
12 #define ASIO_BASIC_SOCKET_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/any_io_executor.hpp"
19 #include "asio/detail/config.hpp"
20 #include "asio/async_result.hpp"
21 #include "asio/detail/handler_type_requirements.hpp"
22 #include "asio/detail/io_object_impl.hpp"
23 #include "asio/detail/non_const_lvalue.hpp"
24 #include "asio/detail/throw_error.hpp"
25 #include "asio/detail/type_traits.hpp"
26 #include "asio/error.hpp"
27 #include "asio/execution_context.hpp"
28 #include "asio/post.hpp"
29 #include "asio/socket_base.hpp"
30 
31 #if defined(ASIO_WINDOWS_RUNTIME)
32 # include "asio/detail/null_socket_service.hpp"
33 #elif defined(ASIO_HAS_IOCP)
34 # include "asio/detail/win_iocp_socket_service.hpp"
35 #else
36 # include "asio/detail/reactive_socket_service.hpp"
37 #endif
38 
39 #if defined(ASIO_HAS_MOVE)
40 # include <utility>
41 #endif // defined(ASIO_HAS_MOVE)
42 
43 #include "asio/detail/push_options.hpp"
44 
45 namespace asio {
46 
47 #if !defined(ASIO_BASIC_SOCKET_FWD_DECL)
48 #define ASIO_BASIC_SOCKET_FWD_DECL
49 
50 // Forward declaration with defaulted arguments.
51 template <typename Protocol, typename Executor = any_io_executor>
53 
54 #endif // !defined(ASIO_BASIC_SOCKET_FWD_DECL)
55 
57 
65 template <typename Protocol, typename Executor>
66 class basic_socket
67  : public socket_base
68 {
69 public:
71  typedef Executor executor_type;
72 
74  template <typename Executor1>
76  {
79  };
80 
82 #if defined(GENERATING_DOCUMENTATION)
83  typedef implementation_defined native_handle_type;
84 #elif defined(ASIO_WINDOWS_RUNTIME)
85  typedef typename detail::null_socket_service<
87 #elif defined(ASIO_HAS_IOCP)
88  typedef typename detail::win_iocp_socket_service<
90 #else
91  typedef typename detail::reactive_socket_service<
93 #endif
94 
96  typedef Protocol protocol_type;
97 
99  typedef typename Protocol::endpoint endpoint_type;
100 
101 #if !defined(ASIO_NO_EXTENSIONS)
104 #endif // !defined(ASIO_NO_EXTENSIONS)
105 
107 
113  explicit basic_socket(const executor_type& ex)
114  : impl_(ex)
115  {
116  }
117 
119 
126  template <typename ExecutionContext>
127  explicit basic_socket(ExecutionContext& context,
128  typename enable_if<
129  is_convertible<ExecutionContext&, execution_context&>::value
130  >::type* = 0)
131  : impl_(context)
132  {
133  }
134 
136 
146  basic_socket(const executor_type& ex, const protocol_type& protocol)
147  : impl_(ex)
148  {
149  asio::error_code ec;
150  impl_.get_service().open(impl_.get_implementation(), protocol, ec);
151  asio::detail::throw_error(ec, "open");
152  }
153 
155 
166  template <typename ExecutionContext>
167  basic_socket(ExecutionContext& context, const protocol_type& protocol,
168  typename enable_if<
169  is_convertible<ExecutionContext&, execution_context&>::value
170  >::type* = 0)
171  : impl_(context)
172  {
173  asio::error_code ec;
174  impl_.get_service().open(impl_.get_implementation(), protocol, ec);
175  asio::detail::throw_error(ec, "open");
176  }
177 
180 
193  basic_socket(const executor_type& ex, const endpoint_type& endpoint)
194  : impl_(ex)
195  {
196  asio::error_code ec;
197  const protocol_type protocol = endpoint.protocol();
198  impl_.get_service().open(impl_.get_implementation(), protocol, ec);
199  asio::detail::throw_error(ec, "open");
200  impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
201  asio::detail::throw_error(ec, "bind");
202  }
203 
206 
220  template <typename ExecutionContext>
221  basic_socket(ExecutionContext& context, const endpoint_type& endpoint,
222  typename enable_if<
223  is_convertible<ExecutionContext&, execution_context&>::value
224  >::type* = 0)
225  : impl_(context)
226  {
227  asio::error_code ec;
228  const protocol_type protocol = endpoint.protocol();
229  impl_.get_service().open(impl_.get_implementation(), protocol, ec);
230  asio::detail::throw_error(ec, "open");
231  impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
232  asio::detail::throw_error(ec, "bind");
233  }
234 
236 
248  basic_socket(const executor_type& ex, const protocol_type& protocol,
249  const native_handle_type& native_socket)
250  : impl_(ex)
251  {
252  asio::error_code ec;
253  impl_.get_service().assign(impl_.get_implementation(),
254  protocol, native_socket, ec);
255  asio::detail::throw_error(ec, "assign");
256  }
257 
259 
272  template <typename ExecutionContext>
273  basic_socket(ExecutionContext& context, const protocol_type& protocol,
274  const native_handle_type& native_socket,
275  typename enable_if<
276  is_convertible<ExecutionContext&, execution_context&>::value
277  >::type* = 0)
278  : impl_(context)
279  {
280  asio::error_code ec;
281  impl_.get_service().assign(impl_.get_implementation(),
282  protocol, native_socket, ec);
283  asio::detail::throw_error(ec, "assign");
284  }
285 
286 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
287 
297  basic_socket(basic_socket&& other) ASIO_NOEXCEPT
298  : impl_(std::move(other.impl_))
299  {
300  }
301 
303 
312  basic_socket& operator=(basic_socket&& other)
313  {
314  impl_ = std::move(other.impl_);
315  return *this;
316  }
317 
318  // All sockets have access to each other's implementations.
319  template <typename Protocol1, typename Executor1>
320  friend class basic_socket;
321 
323 
332  template <typename Protocol1, typename Executor1>
334  typename enable_if<
335  is_convertible<Protocol1, Protocol>::value
336  && is_convertible<Executor1, Executor>::value
337  >::type* = 0)
338  : impl_(std::move(other.impl_))
339  {
340  }
341 
343 
352  template <typename Protocol1, typename Executor1>
353  typename enable_if<
354  is_convertible<Protocol1, Protocol>::value
355  && is_convertible<Executor1, Executor>::value,
356  basic_socket&
357  >::type operator=(basic_socket<Protocol1, Executor1> && other)
358  {
359  basic_socket tmp(std::move(other));
360  impl_ = std::move(tmp.impl_);
361  return *this;
362  }
363 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
364 
366  executor_type get_executor() ASIO_NOEXCEPT
367  {
368  return impl_.get_executor();
369  }
370 
371 #if !defined(ASIO_NO_EXTENSIONS)
372 
381  lowest_layer_type& lowest_layer()
382  {
383  return *this;
384  }
385 
387 
395  const lowest_layer_type& lowest_layer() const
396  {
397  return *this;
398  }
399 #endif // !defined(ASIO_NO_EXTENSIONS)
400 
402 
415  void open(const protocol_type& protocol = protocol_type())
416  {
417  asio::error_code ec;
418  impl_.get_service().open(impl_.get_implementation(), protocol, ec);
419  asio::detail::throw_error(ec, "open");
420  }
421 
423 
441  ASIO_SYNC_OP_VOID open(const protocol_type& protocol,
442  asio::error_code& ec)
443  {
444  impl_.get_service().open(impl_.get_implementation(), protocol, ec);
445  ASIO_SYNC_OP_VOID_RETURN(ec);
446  }
447 
449  /*
450  * This function opens the socket to hold an existing native socket.
451  *
452  * @param protocol An object specifying which protocol is to be used.
453  *
454  * @param native_socket A native socket.
455  *
456  * @throws asio::system_error Thrown on failure.
457  */
458  void assign(const protocol_type& protocol,
459  const native_handle_type& native_socket)
460  {
461  asio::error_code ec;
462  impl_.get_service().assign(impl_.get_implementation(),
463  protocol, native_socket, ec);
464  asio::detail::throw_error(ec, "assign");
465  }
466 
468  /*
469  * This function opens the socket to hold an existing native socket.
470  *
471  * @param protocol An object specifying which protocol is to be used.
472  *
473  * @param native_socket A native socket.
474  *
475  * @param ec Set to indicate what error occurred, if any.
476  */
477  ASIO_SYNC_OP_VOID assign(const protocol_type& protocol,
478  const native_handle_type& native_socket, asio::error_code& ec)
479  {
480  impl_.get_service().assign(impl_.get_implementation(),
481  protocol, native_socket, ec);
482  ASIO_SYNC_OP_VOID_RETURN(ec);
483  }
484 
486  bool is_open() const
487  {
488  return impl_.get_service().is_open(impl_.get_implementation());
489  }
490 
492 
503  void close()
504  {
505  asio::error_code ec;
506  impl_.get_service().close(impl_.get_implementation(), ec);
507  asio::detail::throw_error(ec, "close");
508  }
509 
511 
534  ASIO_SYNC_OP_VOID close(asio::error_code& ec)
535  {
536  impl_.get_service().close(impl_.get_implementation(), ec);
537  ASIO_SYNC_OP_VOID_RETURN(ec);
538  }
539 
541 
553 #if defined(ASIO_MSVC) && (ASIO_MSVC >= 1400) \
554  && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0603)
555  __declspec(deprecated("This function always fails with "
556  "operation_not_supported when used on Windows versions "
557  "prior to Windows 8.1."))
558 #endif
559  native_handle_type release()
560  {
561  asio::error_code ec;
562  native_handle_type s = impl_.get_service().release(
563  impl_.get_implementation(), ec);
564  asio::detail::throw_error(ec, "release");
565  return s;
566  }
567 
569 
581 #if defined(ASIO_MSVC) && (ASIO_MSVC >= 1400) \
582  && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0603)
583  __declspec(deprecated("This function always fails with "
584  "operation_not_supported when used on Windows versions "
585  "prior to Windows 8.1."))
586 #endif
587  native_handle_type release(asio::error_code& ec)
588  {
589  return impl_.get_service().release(impl_.get_implementation(), ec);
590  }
591 
593 
598  native_handle_type native_handle()
599  {
600  return impl_.get_service().native_handle(impl_.get_implementation());
601  }
602 
604 
637 #if defined(ASIO_MSVC) && (ASIO_MSVC >= 1400) \
638  && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600) \
639  && !defined(ASIO_ENABLE_CANCELIO)
640  __declspec(deprecated("By default, this function always fails with "
641  "operation_not_supported when used on Windows XP, Windows Server 2003, "
642  "or earlier. Consult documentation for details."))
643 #endif
644  void cancel()
645  {
646  asio::error_code ec;
647  impl_.get_service().cancel(impl_.get_implementation(), ec);
648  asio::detail::throw_error(ec, "cancel");
649  }
650 
652 
685 #if defined(ASIO_MSVC) && (ASIO_MSVC >= 1400) \
686  && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600) \
687  && !defined(ASIO_ENABLE_CANCELIO)
688  __declspec(deprecated("By default, this function always fails with "
689  "operation_not_supported when used on Windows XP, Windows Server 2003, "
690  "or earlier. Consult documentation for details."))
691 #endif
692  ASIO_SYNC_OP_VOID cancel(asio::error_code& ec)
693  {
694  impl_.get_service().cancel(impl_.get_implementation(), ec);
695  ASIO_SYNC_OP_VOID_RETURN(ec);
696  }
697 
699 
708  bool at_mark() const
709  {
710  asio::error_code ec;
711  bool b = impl_.get_service().at_mark(impl_.get_implementation(), ec);
712  asio::detail::throw_error(ec, "at_mark");
713  return b;
714  }
715 
717 
726  bool at_mark(asio::error_code& ec) const
727  {
728  return impl_.get_service().at_mark(impl_.get_implementation(), ec);
729  }
730 
732 
741  std::size_t available() const
742  {
743  asio::error_code ec;
744  std::size_t s = impl_.get_service().available(
745  impl_.get_implementation(), ec);
746  asio::detail::throw_error(ec, "available");
747  return s;
748  }
749 
751 
760  std::size_t available(asio::error_code& ec) const
761  {
762  return impl_.get_service().available(impl_.get_implementation(), ec);
763  }
764 
766 
783  void bind(const endpoint_type& endpoint)
784  {
785  asio::error_code ec;
786  impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
787  asio::detail::throw_error(ec, "bind");
788  }
789 
791 
813  ASIO_SYNC_OP_VOID bind(const endpoint_type& endpoint,
814  asio::error_code& ec)
815  {
816  impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
817  ASIO_SYNC_OP_VOID_RETURN(ec);
818  }
819 
821 
843  void connect(const endpoint_type& peer_endpoint)
844  {
845  asio::error_code ec;
846  if (!is_open())
847  {
848  impl_.get_service().open(impl_.get_implementation(),
849  peer_endpoint.protocol(), ec);
850  asio::detail::throw_error(ec, "connect");
851  }
852  impl_.get_service().connect(impl_.get_implementation(), peer_endpoint, ec);
853  asio::detail::throw_error(ec, "connect");
854  }
855 
857 
884  ASIO_SYNC_OP_VOID connect(const endpoint_type& peer_endpoint,
885  asio::error_code& ec)
886  {
887  if (!is_open())
888  {
889  impl_.get_service().open(impl_.get_implementation(),
890  peer_endpoint.protocol(), ec);
891  if (ec)
892  {
893  ASIO_SYNC_OP_VOID_RETURN(ec);
894  }
895  }
896 
897  impl_.get_service().connect(impl_.get_implementation(), peer_endpoint, ec);
898  ASIO_SYNC_OP_VOID_RETURN(ec);
899  }
900 
902 
942  template <
943  ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code))
944  ConnectHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
945  ASIO_INITFN_AUTO_RESULT_TYPE(ConnectHandler,
946  void (asio::error_code))
947  async_connect(const endpoint_type& peer_endpoint,
948  ASIO_MOVE_ARG(ConnectHandler) handler
949  ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
950  {
951  asio::error_code open_ec;
952  if (!is_open())
953  {
954  const protocol_type protocol = peer_endpoint.protocol();
955  impl_.get_service().open(impl_.get_implementation(), protocol, open_ec);
956  }
957 
958  return async_initiate<ConnectHandler, void (asio::error_code)>(
959  initiate_async_connect(this), handler, peer_endpoint, open_ec);
960  }
961 
963 
996  template <typename SettableSocketOption>
997  void set_option(const SettableSocketOption& option)
998  {
999  asio::error_code ec;
1000  impl_.get_service().set_option(impl_.get_implementation(), option, ec);
1001  asio::detail::throw_error(ec, "set_option");
1002  }
1003 
1005 
1043  template <typename SettableSocketOption>
1044  ASIO_SYNC_OP_VOID set_option(const SettableSocketOption& option,
1045  asio::error_code& ec)
1046  {
1047  impl_.get_service().set_option(impl_.get_implementation(), option, ec);
1048  ASIO_SYNC_OP_VOID_RETURN(ec);
1049  }
1050 
1052 
1086  template <typename GettableSocketOption>
1087  void get_option(GettableSocketOption& option) const
1088  {
1089  asio::error_code ec;
1090  impl_.get_service().get_option(impl_.get_implementation(), option, ec);
1091  asio::detail::throw_error(ec, "get_option");
1092  }
1093 
1095 
1134  template <typename GettableSocketOption>
1135  ASIO_SYNC_OP_VOID get_option(GettableSocketOption& option,
1136  asio::error_code& ec) const
1137  {
1138  impl_.get_service().get_option(impl_.get_implementation(), option, ec);
1139  ASIO_SYNC_OP_VOID_RETURN(ec);
1140  }
1141 
1143 
1164  template <typename IoControlCommand>
1165  void io_control(IoControlCommand& command)
1166  {
1167  asio::error_code ec;
1168  impl_.get_service().io_control(impl_.get_implementation(), command, ec);
1169  asio::detail::throw_error(ec, "io_control");
1170  }
1171 
1173 
1199  template <typename IoControlCommand>
1200  ASIO_SYNC_OP_VOID io_control(IoControlCommand& command,
1201  asio::error_code& ec)
1202  {
1203  impl_.get_service().io_control(impl_.get_implementation(), command, ec);
1204  ASIO_SYNC_OP_VOID_RETURN(ec);
1205  }
1206 
1208 
1218  bool non_blocking() const
1219  {
1220  return impl_.get_service().non_blocking(impl_.get_implementation());
1221  }
1222 
1224 
1236  void non_blocking(bool mode)
1237  {
1238  asio::error_code ec;
1239  impl_.get_service().non_blocking(impl_.get_implementation(), mode, ec);
1240  asio::detail::throw_error(ec, "non_blocking");
1241  }
1242 
1244 
1256  ASIO_SYNC_OP_VOID non_blocking(
1257  bool mode, asio::error_code& ec)
1258  {
1259  impl_.get_service().non_blocking(impl_.get_implementation(), mode, ec);
1260  ASIO_SYNC_OP_VOID_RETURN(ec);
1261  }
1262 
1264 
1347  bool native_non_blocking() const
1348  {
1349  return impl_.get_service().native_non_blocking(impl_.get_implementation());
1350  }
1351 
1353 
1437  void native_non_blocking(bool mode)
1438  {
1439  asio::error_code ec;
1440  impl_.get_service().native_non_blocking(
1441  impl_.get_implementation(), mode, ec);
1442  asio::detail::throw_error(ec, "native_non_blocking");
1443  }
1444 
1446 
1530  ASIO_SYNC_OP_VOID native_non_blocking(
1531  bool mode, asio::error_code& ec)
1532  {
1533  impl_.get_service().native_non_blocking(
1534  impl_.get_implementation(), mode, ec);
1535  ASIO_SYNC_OP_VOID_RETURN(ec);
1536  }
1537 
1539 
1553  endpoint_type local_endpoint() const
1554  {
1555  asio::error_code ec;
1556  endpoint_type ep = impl_.get_service().local_endpoint(
1557  impl_.get_implementation(), ec);
1558  asio::detail::throw_error(ec, "local_endpoint");
1559  return ep;
1560  }
1561 
1563 
1583  endpoint_type local_endpoint(asio::error_code& ec) const
1584  {
1585  return impl_.get_service().local_endpoint(impl_.get_implementation(), ec);
1586  }
1587 
1589 
1603  endpoint_type remote_endpoint() const
1604  {
1605  asio::error_code ec;
1606  endpoint_type ep = impl_.get_service().remote_endpoint(
1607  impl_.get_implementation(), ec);
1608  asio::detail::throw_error(ec, "remote_endpoint");
1609  return ep;
1610  }
1611 
1613 
1633  endpoint_type remote_endpoint(asio::error_code& ec) const
1634  {
1635  return impl_.get_service().remote_endpoint(impl_.get_implementation(), ec);
1636  }
1637 
1639 
1656  {
1657  asio::error_code ec;
1658  impl_.get_service().shutdown(impl_.get_implementation(), what, ec);
1659  asio::detail::throw_error(ec, "shutdown");
1660  }
1661 
1663 
1684  ASIO_SYNC_OP_VOID shutdown(shutdown_type what,
1685  asio::error_code& ec)
1686  {
1687  impl_.get_service().shutdown(impl_.get_implementation(), what, ec);
1688  ASIO_SYNC_OP_VOID_RETURN(ec);
1689  }
1690 
1693 
1707  void wait(wait_type w)
1708  {
1709  asio::error_code ec;
1710  impl_.get_service().wait(impl_.get_implementation(), w, ec);
1711  asio::detail::throw_error(ec, "wait");
1712  }
1713 
1716 
1733  ASIO_SYNC_OP_VOID wait(wait_type w, asio::error_code& ec)
1734  {
1735  impl_.get_service().wait(impl_.get_implementation(), w, ec);
1736  ASIO_SYNC_OP_VOID_RETURN(ec);
1737  }
1738 
1741 
1775  template <
1776  ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code))
1777  WaitHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1778  ASIO_INITFN_AUTO_RESULT_TYPE(WaitHandler,
1779  void (asio::error_code))
1780  async_wait(wait_type w,
1781  ASIO_MOVE_ARG(WaitHandler) handler
1782  ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
1783  {
1784  return async_initiate<WaitHandler, void (asio::error_code)>(
1785  initiate_async_wait(this), handler, w);
1786  }
1787 
1788 protected:
1790 
1795  {
1796  }
1797 
1798 #if defined(ASIO_WINDOWS_RUNTIME)
1800  detail::null_socket_service<Protocol>, Executor> impl_;
1801 #elif defined(ASIO_HAS_IOCP)
1803  detail::win_iocp_socket_service<Protocol>, Executor> impl_;
1804 #else
1807 #endif
1808 
1809 private:
1810  // Disallow copying and assignment.
1811  basic_socket(const basic_socket&) ASIO_DELETED;
1812  basic_socket& operator=(const basic_socket&) ASIO_DELETED;
1813 
1814  class initiate_async_connect
1815  {
1816  public:
1817  typedef Executor executor_type;
1818 
1819  explicit initiate_async_connect(basic_socket* self)
1820  : self_(self)
1821  {
1822  }
1823 
1824  executor_type get_executor() const ASIO_NOEXCEPT
1825  {
1826  return self_->get_executor();
1827  }
1828 
1829  template <typename ConnectHandler>
1830  void operator()(ASIO_MOVE_ARG(ConnectHandler) handler,
1831  const endpoint_type& peer_endpoint,
1832  const asio::error_code& open_ec) const
1833  {
1834  // If you get an error on the following line it means that your handler
1835  // does not meet the documented type requirements for a ConnectHandler.
1836  ASIO_CONNECT_HANDLER_CHECK(ConnectHandler, handler) type_check;
1837 
1838  if (open_ec)
1839  {
1840  asio::post(self_->impl_.get_executor(),
1841  asio::detail::bind_handler(
1842  ASIO_MOVE_CAST(ConnectHandler)(handler), open_ec));
1843  }
1844  else
1845  {
1846  detail::non_const_lvalue<ConnectHandler> handler2(handler);
1847  self_->impl_.get_service().async_connect(
1848  self_->impl_.get_implementation(), peer_endpoint,
1849  handler2.value, self_->impl_.get_executor());
1850  }
1851  }
1852 
1853  private:
1854  basic_socket* self_;
1855  };
1856 
1857  class initiate_async_wait
1858  {
1859  public:
1860  typedef Executor executor_type;
1861 
1862  explicit initiate_async_wait(basic_socket* self)
1863  : self_(self)
1864  {
1865  }
1866 
1867  executor_type get_executor() const ASIO_NOEXCEPT
1868  {
1869  return self_->get_executor();
1870  }
1871 
1872  template <typename WaitHandler>
1873  void operator()(ASIO_MOVE_ARG(WaitHandler) handler, wait_type w) const
1874  {
1875  // If you get an error on the following line it means that your handler
1876  // does not meet the documented type requirements for a WaitHandler.
1877  ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
1878 
1879  detail::non_const_lvalue<WaitHandler> handler2(handler);
1880  self_->impl_.get_service().async_wait(
1881  self_->impl_.get_implementation(), w,
1882  handler2.value, self_->impl_.get_executor());
1883  }
1884 
1885  private:
1886  basic_socket* self_;
1887  };
1888 };
1889 
1890 } // namespace asio
1891 
1892 #include "asio/detail/pop_options.hpp"
1893 
1894 #endif // ASIO_BASIC_SOCKET_HPP
Protocol protocol_type
The protocol type.
Definition: basic_socket.hpp:96
ASIO_SYNC_OP_VOID shutdown(shutdown_type what, asio::error_code &ec)
Disable sends or receives on the socket.
Definition: basic_socket.hpp:1684
bool at_mark() const
Determine whether the socket is at the out-of-band data mark.
Definition: basic_socket.hpp:708
The socket_base class is used as a base for the basic_stream_socket and basic_datagram_socket class t...
Definition: socket_base.hpp:30
ASIO_SYNC_OP_VOID close(asio::error_code &ec)
Close the socket.
Definition: basic_socket.hpp:534
endpoint_type local_endpoint() const
Get the local endpoint of the socket.
Definition: basic_socket.hpp:1553
Definition: blocking.hpp:208
wait_type
Wait types.
Definition: socket_base.hpp:82
ASIO_SYNC_OP_VOID set_option(const SettableSocketOption &option, asio::error_code &ec)
Set an option on the socket.
Definition: basic_socket.hpp:1044
Executor executor_type
The type of the executor associated with the object.
Definition: basic_socket.hpp:71
void non_blocking(bool mode)
Sets the non-blocking mode of the socket.
Definition: basic_socket.hpp:1236
basic_socket(const executor_type &ex, const protocol_type &protocol, const native_handle_type &native_socket)
Construct a basic_socket on an existing native socket.
Definition: basic_socket.hpp:248
executor_type get_executor() ASIO_NOEXCEPT
Get the executor associated with the object.
Definition: basic_socket.hpp:366
void open(const protocol_type &protocol=protocol_type())
Open the socket using the specified protocol.
Definition: basic_socket.hpp:415
ASIO_SYNC_OP_VOID connect(const endpoint_type &peer_endpoint, asio::error_code &ec)
Connect the socket to the specified endpoint.
Definition: basic_socket.hpp:884
basic_socket< Protocol, Executor > lowest_layer_type
A basic_socket is always the lowest layer.
Definition: basic_socket.hpp:103
lowest_layer_type & lowest_layer()
Get a reference to the lowest layer.
Definition: basic_socket.hpp:381
basic_socket(const executor_type &ex)
Construct a basic_socket without opening it.
Definition: basic_socket.hpp:113
ASIO_SYNC_OP_VOID io_control(IoControlCommand &command, asio::error_code &ec)
Perform an IO control command on the socket.
Definition: basic_socket.hpp:1200
basic_socket(ExecutionContext &context, const protocol_type &protocol, const native_handle_type &native_socket, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
Construct a basic_socket on an existing native socket.
Definition: basic_socket.hpp:273
basic_socket< Protocol, Executor1 > other
The socket type when rebound to the specified executor.
Definition: basic_socket.hpp:78
basic_socket(ExecutionContext &context, const protocol_type &protocol, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
Construct and open a basic_socket.
Definition: basic_socket.hpp:167
basic_socket(ExecutionContext &context, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
Construct a basic_socket without opening it.
Definition: basic_socket.hpp:127
void shutdown(shutdown_type what)
Disable sends or receives on the socket.
Definition: basic_socket.hpp:1655
ASIO_SYNC_OP_VOID open(const protocol_type &protocol, asio::error_code &ec)
Open the socket using the specified protocol.
Definition: basic_socket.hpp:441
Definition: getopt.h:41
bool at_mark(asio::error_code &ec) const
Determine whether the socket is at the out-of-band data mark.
Definition: basic_socket.hpp:726
void wait(wait_type w)
Wait for the socket to become ready to read, ready to write, or to have pending error conditions...
Definition: basic_socket.hpp:1707
endpoint_type remote_endpoint() const
Get the remote endpoint of the socket.
Definition: basic_socket.hpp:1603
const lowest_layer_type & lowest_layer() const
Get a const reference to the lowest layer.
Definition: basic_socket.hpp:395
bool is_open() const
Determine whether the socket is open.
Definition: basic_socket.hpp:486
void assign(const protocol_type &protocol, const native_handle_type &native_socket)
Assign an existing native socket to the socket.
Definition: basic_socket.hpp:458
Definition: type_traits.hpp:97
Definition: non_const_lvalue.hpp:27
native_handle_type release()
Release ownership of the underlying native socket.
Definition: basic_socket.hpp:559
basic_socket(ExecutionContext &context, const endpoint_type &endpoint, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
Construct a basic_socket, opening it and binding it to the given local endpoint.
Definition: basic_socket.hpp:221
detail::reactive_socket_service< Protocol >::native_handle_type native_handle_type
The native representation of a socket.
Definition: basic_socket.hpp:92
ASIO_SYNC_OP_VOID wait(wait_type w, asio::error_code &ec)
Wait for the socket to become ready to read, ready to write, or to have pending error conditions...
Definition: basic_socket.hpp:1733
void set_option(const SettableSocketOption &option)
Set an option on the socket.
Definition: basic_socket.hpp:997
ASIO_SYNC_OP_VOID bind(const endpoint_type &endpoint, asio::error_code &ec)
Bind the socket to the given local endpoint.
Definition: basic_socket.hpp:813
shutdown_type
Different ways a socket may be shutdown.
Definition: socket_base.hpp:34
~basic_socket()
Protected destructor to prevent deletion through this type.
Definition: basic_socket.hpp:1794
void native_non_blocking(bool mode)
Sets the non-blocking mode of the native socket implementation.
Definition: basic_socket.hpp:1437
void close()
Close the socket.
Definition: basic_socket.hpp:503
Class to represent an error code value.
Definition: error_code.hpp:80
Definition: io_object_impl.hpp:33
native_handle_type release(asio::error_code &ec)
Release ownership of the underlying native socket.
Definition: basic_socket.hpp:587
void bind(const endpoint_type &endpoint)
Bind the socket to the given local endpoint.
Definition: basic_socket.hpp:783
bool non_blocking() const
Gets the non-blocking mode of the socket.
Definition: basic_socket.hpp:1218
Definition: reactive_socket_service.hpp:47
void io_control(IoControlCommand &command)
Perform an IO control command on the socket.
Definition: basic_socket.hpp:1165
Protocol::endpoint endpoint_type
The endpoint type.
Definition: basic_socket.hpp:99
ASIO_SYNC_OP_VOID assign(const protocol_type &protocol, const native_handle_type &native_socket, asio::error_code &ec)
Assign an existing native socket to the socket.
Definition: basic_socket.hpp:477
basic_socket(const executor_type &ex, const protocol_type &protocol)
Construct and open a basic_socket.
Definition: basic_socket.hpp:146
Provides socket functionality.
Definition: basic_socket.hpp:52
std::size_t available() const
Determine the number of bytes available for reading.
Definition: basic_socket.hpp:741
endpoint_type local_endpoint(asio::error_code &ec) const
Get the local endpoint of the socket.
Definition: basic_socket.hpp:1583
ASIO_SYNC_OP_VOID get_option(GettableSocketOption &option, asio::error_code &ec) const
Get an option from the socket.
Definition: basic_socket.hpp:1135
basic_socket(const executor_type &ex, const endpoint_type &endpoint)
Construct a basic_socket, opening it and binding it to the given local endpoint.
Definition: basic_socket.hpp:193
endpoint_type remote_endpoint(asio::error_code &ec) const
Get the remote endpoint of the socket.
Definition: basic_socket.hpp:1633
void get_option(GettableSocketOption &option) const
Get an option from the socket.
Definition: basic_socket.hpp:1087
bool native_non_blocking() const
Gets the non-blocking mode of the native socket implementation.
Definition: basic_socket.hpp:1347
Rebinds the socket type to another executor.
Definition: basic_socket.hpp:75
ASIO_SYNC_OP_VOID cancel(asio::error_code &ec)
Cancel all asynchronous operations associated with the socket.
Definition: basic_socket.hpp:692
ASIO_SYNC_OP_VOID native_non_blocking(bool mode, asio::error_code &ec)
Sets the non-blocking mode of the native socket implementation.
Definition: basic_socket.hpp:1530
ASIO_SYNC_OP_VOID non_blocking(bool mode, asio::error_code &ec)
Sets the non-blocking mode of the socket.
Definition: basic_socket.hpp:1256
Definition: any_io_executor.hpp:28
std::size_t available(asio::error_code &ec) const
Determine the number of bytes available for reading.
Definition: basic_socket.hpp:760
native_handle_type native_handle()
Get the native socket representation.
Definition: basic_socket.hpp:598
void assign(int v, const error_category &c)
Assign a new error value.
Definition: error_code.hpp:112
ASIO_INITFN_AUTO_RESULT_TYPE(ConnectHandler, void(asio::error_code)) async_connect(const endpoint_type &peer_endpoint
Start an asynchronous connect.
void connect(const endpoint_type &peer_endpoint)
Connect the socket to the specified endpoint.
Definition: basic_socket.hpp:843
void cancel()
Cancel all asynchronous operations associated with the socket.
Definition: basic_socket.hpp:644