2 // basic_socket_acceptor.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_HPP
12 #define BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/any_io_executor.hpp>
20 #include <boost/asio/basic_socket.hpp>
21 #include <boost/asio/detail/handler_type_requirements.hpp>
22 #include <boost/asio/detail/io_object_impl.hpp>
23 #include <boost/asio/detail/non_const_lvalue.hpp>
24 #include <boost/asio/detail/throw_error.hpp>
25 #include <boost/asio/detail/type_traits.hpp>
26 #include <boost/asio/error.hpp>
27 #include <boost/asio/execution_context.hpp>
28 #include <boost/asio/socket_base.hpp>
30 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
31 # include <boost/asio/detail/null_socket_service.hpp>
32 #elif defined(BOOST_ASIO_HAS_IOCP)
33 # include <boost/asio/detail/win_iocp_socket_service.hpp>
35 # include <boost/asio/detail/reactive_socket_service.hpp>
38 #if defined(BOOST_ASIO_HAS_MOVE)
40 #endif // defined(BOOST_ASIO_HAS_MOVE)
42 #include <boost/asio/detail/push_options.hpp>
47 #if !defined(BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_FWD_DECL)
48 #define BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_FWD_DECL
50 // Forward declaration with defaulted arguments.
51 template <typename Protocol, typename Executor = any_io_executor>
52 class basic_socket_acceptor;
54 #endif // !defined(BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_FWD_DECL)
56 /// Provides the ability to accept new connections.
58 * The basic_socket_acceptor class template is used for accepting new socket
62 * @e Distinct @e objects: Safe.@n
63 * @e Shared @e objects: Unsafe.
66 * Opening a socket acceptor with the SO_REUSEADDR option enabled:
68 * boost::asio::ip::tcp::acceptor acceptor(my_context);
69 * boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port);
70 * acceptor.open(endpoint.protocol());
71 * acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
72 * acceptor.bind(endpoint);
76 template <typename Protocol, typename Executor>
77 class basic_socket_acceptor
81 /// The type of the executor associated with the object.
82 typedef Executor executor_type;
84 /// Rebinds the acceptor type to another executor.
85 template <typename Executor1>
86 struct rebind_executor
88 /// The socket type when rebound to the specified executor.
89 typedef basic_socket_acceptor<Protocol, Executor1> other;
92 /// The native representation of an acceptor.
93 #if defined(GENERATING_DOCUMENTATION)
94 typedef implementation_defined native_handle_type;
95 #elif defined(BOOST_ASIO_WINDOWS_RUNTIME)
96 typedef typename detail::null_socket_service<
97 Protocol>::native_handle_type native_handle_type;
98 #elif defined(BOOST_ASIO_HAS_IOCP)
99 typedef typename detail::win_iocp_socket_service<
100 Protocol>::native_handle_type native_handle_type;
102 typedef typename detail::reactive_socket_service<
103 Protocol>::native_handle_type native_handle_type;
106 /// The protocol type.
107 typedef Protocol protocol_type;
109 /// The endpoint type.
110 typedef typename Protocol::endpoint endpoint_type;
112 /// Construct an acceptor without opening it.
114 * This constructor creates an acceptor without opening it to listen for new
115 * connections. The open() function must be called before the acceptor can
116 * accept new socket connections.
118 * @param ex The I/O executor that the acceptor will use, by default, to
119 * dispatch handlers for any asynchronous operations performed on the
122 explicit basic_socket_acceptor(const executor_type& ex)
127 /// Construct an acceptor without opening it.
129 * This constructor creates an acceptor without opening it to listen for new
130 * connections. The open() function must be called before the acceptor can
131 * accept new socket connections.
133 * @param context An execution context which provides the I/O executor that
134 * the acceptor will use, by default, to dispatch handlers for any
135 * asynchronous operations performed on the acceptor.
137 template <typename ExecutionContext>
138 explicit basic_socket_acceptor(ExecutionContext& context,
140 is_convertible<ExecutionContext&, execution_context&>::value
146 /// Construct an open acceptor.
148 * This constructor creates an acceptor and automatically opens it.
150 * @param ex The I/O executor that the acceptor will use, by default, to
151 * dispatch handlers for any asynchronous operations performed on the
154 * @param protocol An object specifying protocol parameters to be used.
156 * @throws boost::system::system_error Thrown on failure.
158 basic_socket_acceptor(const executor_type& ex, const protocol_type& protocol)
161 boost::system::error_code ec;
162 impl_.get_service().open(impl_.get_implementation(), protocol, ec);
163 boost::asio::detail::throw_error(ec, "open");
166 /// Construct an open acceptor.
168 * This constructor creates an acceptor and automatically opens it.
170 * @param context An execution context which provides the I/O executor that
171 * the acceptor will use, by default, to dispatch handlers for any
172 * asynchronous operations performed on the acceptor.
174 * @param protocol An object specifying protocol parameters to be used.
176 * @throws boost::system::system_error Thrown on failure.
178 template <typename ExecutionContext>
179 basic_socket_acceptor(ExecutionContext& context,
180 const protocol_type& protocol,
182 is_convertible<ExecutionContext&, execution_context&>::value
186 boost::system::error_code ec;
187 impl_.get_service().open(impl_.get_implementation(), protocol, ec);
188 boost::asio::detail::throw_error(ec, "open");
191 /// Construct an acceptor opened on the given endpoint.
193 * This constructor creates an acceptor and automatically opens it to listen
194 * for new connections on the specified endpoint.
196 * @param ex The I/O executor that the acceptor will use, by default, to
197 * dispatch handlers for any asynchronous operations performed on the
200 * @param endpoint An endpoint on the local machine on which the acceptor
201 * will listen for new connections.
203 * @param reuse_addr Whether the constructor should set the socket option
204 * socket_base::reuse_address.
206 * @throws boost::system::system_error Thrown on failure.
208 * @note This constructor is equivalent to the following code:
210 * basic_socket_acceptor<Protocol> acceptor(my_context);
211 * acceptor.open(endpoint.protocol());
213 * acceptor.set_option(socket_base::reuse_address(true));
214 * acceptor.bind(endpoint);
218 basic_socket_acceptor(const executor_type& ex,
219 const endpoint_type& endpoint, bool reuse_addr = true)
222 boost::system::error_code ec;
223 const protocol_type protocol = endpoint.protocol();
224 impl_.get_service().open(impl_.get_implementation(), protocol, ec);
225 boost::asio::detail::throw_error(ec, "open");
228 impl_.get_service().set_option(impl_.get_implementation(),
229 socket_base::reuse_address(true), ec);
230 boost::asio::detail::throw_error(ec, "set_option");
232 impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
233 boost::asio::detail::throw_error(ec, "bind");
234 impl_.get_service().listen(impl_.get_implementation(),
235 socket_base::max_listen_connections, ec);
236 boost::asio::detail::throw_error(ec, "listen");
239 /// Construct an acceptor opened on the given endpoint.
241 * This constructor creates an acceptor and automatically opens it to listen
242 * for new connections on the specified endpoint.
244 * @param context An execution context which provides the I/O executor that
245 * the acceptor will use, by default, to dispatch handlers for any
246 * asynchronous operations performed on the acceptor.
248 * @param endpoint An endpoint on the local machine on which the acceptor
249 * will listen for new connections.
251 * @param reuse_addr Whether the constructor should set the socket option
252 * socket_base::reuse_address.
254 * @throws boost::system::system_error Thrown on failure.
256 * @note This constructor is equivalent to the following code:
258 * basic_socket_acceptor<Protocol> acceptor(my_context);
259 * acceptor.open(endpoint.protocol());
261 * acceptor.set_option(socket_base::reuse_address(true));
262 * acceptor.bind(endpoint);
266 template <typename ExecutionContext>
267 basic_socket_acceptor(ExecutionContext& context,
268 const endpoint_type& endpoint, bool reuse_addr = true,
270 is_convertible<ExecutionContext&, execution_context&>::value
274 boost::system::error_code ec;
275 const protocol_type protocol = endpoint.protocol();
276 impl_.get_service().open(impl_.get_implementation(), protocol, ec);
277 boost::asio::detail::throw_error(ec, "open");
280 impl_.get_service().set_option(impl_.get_implementation(),
281 socket_base::reuse_address(true), ec);
282 boost::asio::detail::throw_error(ec, "set_option");
284 impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
285 boost::asio::detail::throw_error(ec, "bind");
286 impl_.get_service().listen(impl_.get_implementation(),
287 socket_base::max_listen_connections, ec);
288 boost::asio::detail::throw_error(ec, "listen");
291 /// Construct a basic_socket_acceptor on an existing native acceptor.
293 * This constructor creates an acceptor object to hold an existing native
296 * @param ex The I/O executor that the acceptor will use, by default, to
297 * dispatch handlers for any asynchronous operations performed on the
300 * @param protocol An object specifying protocol parameters to be used.
302 * @param native_acceptor A native acceptor.
304 * @throws boost::system::system_error Thrown on failure.
306 basic_socket_acceptor(const executor_type& ex,
307 const protocol_type& protocol, const native_handle_type& native_acceptor)
310 boost::system::error_code ec;
311 impl_.get_service().assign(impl_.get_implementation(),
312 protocol, native_acceptor, ec);
313 boost::asio::detail::throw_error(ec, "assign");
316 /// Construct a basic_socket_acceptor on an existing native acceptor.
318 * This constructor creates an acceptor object to hold an existing native
321 * @param context An execution context which provides the I/O executor that
322 * the acceptor will use, by default, to dispatch handlers for any
323 * asynchronous operations performed on the acceptor.
325 * @param protocol An object specifying protocol parameters to be used.
327 * @param native_acceptor A native acceptor.
329 * @throws boost::system::system_error Thrown on failure.
331 template <typename ExecutionContext>
332 basic_socket_acceptor(ExecutionContext& context,
333 const protocol_type& protocol, const native_handle_type& native_acceptor,
335 is_convertible<ExecutionContext&, execution_context&>::value
339 boost::system::error_code ec;
340 impl_.get_service().assign(impl_.get_implementation(),
341 protocol, native_acceptor, ec);
342 boost::asio::detail::throw_error(ec, "assign");
345 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
346 /// Move-construct a basic_socket_acceptor from another.
348 * This constructor moves an acceptor from one object to another.
350 * @param other The other basic_socket_acceptor object from which the move
353 * @note Following the move, the moved-from object is in the same state as if
354 * constructed using the @c basic_socket_acceptor(const executor_type&)
357 basic_socket_acceptor(basic_socket_acceptor&& other) BOOST_ASIO_NOEXCEPT
358 : impl_(std::move(other.impl_))
362 /// Move-assign a basic_socket_acceptor from another.
364 * This assignment operator moves an acceptor from one object to another.
366 * @param other The other basic_socket_acceptor object from which the move
369 * @note Following the move, the moved-from object is in the same state as if
370 * constructed using the @c basic_socket_acceptor(const executor_type&)
373 basic_socket_acceptor& operator=(basic_socket_acceptor&& other)
375 impl_ = std::move(other.impl_);
379 // All socket acceptors have access to each other's implementations.
380 template <typename Protocol1, typename Executor1>
381 friend class basic_socket_acceptor;
383 /// Move-construct a basic_socket_acceptor from an acceptor of another
386 * This constructor moves an acceptor from one object to another.
388 * @param other The other basic_socket_acceptor object from which the move
391 * @note Following the move, the moved-from object is in the same state as if
392 * constructed using the @c basic_socket_acceptor(const executor_type&)
395 template <typename Protocol1, typename Executor1>
396 basic_socket_acceptor(basic_socket_acceptor<Protocol1, Executor1>&& other,
398 is_convertible<Protocol1, Protocol>::value
399 && is_convertible<Executor1, Executor>::value
401 : impl_(std::move(other.impl_))
405 /// Move-assign a basic_socket_acceptor from an acceptor of another protocol
408 * This assignment operator moves an acceptor from one object to another.
410 * @param other The other basic_socket_acceptor object from which the move
413 * @note Following the move, the moved-from object is in the same state as if
414 * constructed using the @c basic_socket_acceptor(const executor_type&)
417 template <typename Protocol1, typename Executor1>
419 is_convertible<Protocol1, Protocol>::value
420 && is_convertible<Executor1, Executor>::value,
421 basic_socket_acceptor&
422 >::type operator=(basic_socket_acceptor<Protocol1, Executor1>&& other)
424 basic_socket_acceptor tmp(std::move(other));
425 impl_ = std::move(tmp.impl_);
428 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
430 /// Destroys the acceptor.
432 * This function destroys the acceptor, cancelling any outstanding
433 * asynchronous operations associated with the acceptor as if by calling
436 ~basic_socket_acceptor()
440 /// Get the executor associated with the object.
441 executor_type get_executor() BOOST_ASIO_NOEXCEPT
443 return impl_.get_executor();
446 /// Open the acceptor using the specified protocol.
448 * This function opens the socket acceptor so that it will use the specified
451 * @param protocol An object specifying which protocol is to be used.
453 * @throws boost::system::system_error Thrown on failure.
457 * boost::asio::ip::tcp::acceptor acceptor(my_context);
458 * acceptor.open(boost::asio::ip::tcp::v4());
461 void open(const protocol_type& protocol = protocol_type())
463 boost::system::error_code ec;
464 impl_.get_service().open(impl_.get_implementation(), protocol, ec);
465 boost::asio::detail::throw_error(ec, "open");
468 /// Open the acceptor using the specified protocol.
470 * This function opens the socket acceptor so that it will use the specified
473 * @param protocol An object specifying which protocol is to be used.
475 * @param ec Set to indicate what error occurred, if any.
479 * boost::asio::ip::tcp::acceptor acceptor(my_context);
480 * boost::system::error_code ec;
481 * acceptor.open(boost::asio::ip::tcp::v4(), ec);
484 * // An error occurred.
488 BOOST_ASIO_SYNC_OP_VOID open(const protocol_type& protocol,
489 boost::system::error_code& ec)
491 impl_.get_service().open(impl_.get_implementation(), protocol, ec);
492 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
495 /// Assigns an existing native acceptor to the acceptor.
497 * This function opens the acceptor to hold an existing native acceptor.
499 * @param protocol An object specifying which protocol is to be used.
501 * @param native_acceptor A native acceptor.
503 * @throws boost::system::system_error Thrown on failure.
505 void assign(const protocol_type& protocol,
506 const native_handle_type& native_acceptor)
508 boost::system::error_code ec;
509 impl_.get_service().assign(impl_.get_implementation(),
510 protocol, native_acceptor, ec);
511 boost::asio::detail::throw_error(ec, "assign");
514 /// Assigns an existing native acceptor to the acceptor.
516 * This function opens the acceptor to hold an existing native acceptor.
518 * @param protocol An object specifying which protocol is to be used.
520 * @param native_acceptor A native acceptor.
522 * @param ec Set to indicate what error occurred, if any.
524 BOOST_ASIO_SYNC_OP_VOID assign(const protocol_type& protocol,
525 const native_handle_type& native_acceptor, boost::system::error_code& ec)
527 impl_.get_service().assign(impl_.get_implementation(),
528 protocol, native_acceptor, ec);
529 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
532 /// Determine whether the acceptor is open.
535 return impl_.get_service().is_open(impl_.get_implementation());
538 /// Bind the acceptor to the given local endpoint.
540 * This function binds the socket acceptor to the specified endpoint on the
543 * @param endpoint An endpoint on the local machine to which the socket
544 * acceptor will be bound.
546 * @throws boost::system::system_error Thrown on failure.
550 * boost::asio::ip::tcp::acceptor acceptor(my_context);
551 * boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 12345);
552 * acceptor.open(endpoint.protocol());
553 * acceptor.bind(endpoint);
556 void bind(const endpoint_type& endpoint)
558 boost::system::error_code ec;
559 impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
560 boost::asio::detail::throw_error(ec, "bind");
563 /// Bind the acceptor to the given local endpoint.
565 * This function binds the socket acceptor to the specified endpoint on the
568 * @param endpoint An endpoint on the local machine to which the socket
569 * acceptor will be bound.
571 * @param ec Set to indicate what error occurred, if any.
575 * boost::asio::ip::tcp::acceptor acceptor(my_context);
576 * boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 12345);
577 * acceptor.open(endpoint.protocol());
578 * boost::system::error_code ec;
579 * acceptor.bind(endpoint, ec);
582 * // An error occurred.
586 BOOST_ASIO_SYNC_OP_VOID bind(const endpoint_type& endpoint,
587 boost::system::error_code& ec)
589 impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
590 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
593 /// Place the acceptor into the state where it will listen for new
596 * This function puts the socket acceptor into the state where it may accept
599 * @param backlog The maximum length of the queue of pending connections.
601 * @throws boost::system::system_error Thrown on failure.
603 void listen(int backlog = socket_base::max_listen_connections)
605 boost::system::error_code ec;
606 impl_.get_service().listen(impl_.get_implementation(), backlog, ec);
607 boost::asio::detail::throw_error(ec, "listen");
610 /// Place the acceptor into the state where it will listen for new
613 * This function puts the socket acceptor into the state where it may accept
616 * @param backlog The maximum length of the queue of pending connections.
618 * @param ec Set to indicate what error occurred, if any.
622 * boost::asio::ip::tcp::acceptor acceptor(my_context);
624 * boost::system::error_code ec;
625 * acceptor.listen(boost::asio::socket_base::max_listen_connections, ec);
628 * // An error occurred.
632 BOOST_ASIO_SYNC_OP_VOID listen(int backlog, boost::system::error_code& ec)
634 impl_.get_service().listen(impl_.get_implementation(), backlog, ec);
635 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
638 /// Close the acceptor.
640 * This function is used to close the acceptor. Any asynchronous accept
641 * operations will be cancelled immediately.
643 * A subsequent call to open() is required before the acceptor can again be
644 * used to again perform socket accept operations.
646 * @throws boost::system::system_error Thrown on failure.
650 boost::system::error_code ec;
651 impl_.get_service().close(impl_.get_implementation(), ec);
652 boost::asio::detail::throw_error(ec, "close");
655 /// Close the acceptor.
657 * This function is used to close the acceptor. Any asynchronous accept
658 * operations will be cancelled immediately.
660 * A subsequent call to open() is required before the acceptor can again be
661 * used to again perform socket accept operations.
663 * @param ec Set to indicate what error occurred, if any.
667 * boost::asio::ip::tcp::acceptor acceptor(my_context);
669 * boost::system::error_code ec;
670 * acceptor.close(ec);
673 * // An error occurred.
677 BOOST_ASIO_SYNC_OP_VOID close(boost::system::error_code& ec)
679 impl_.get_service().close(impl_.get_implementation(), ec);
680 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
683 /// Release ownership of the underlying native acceptor.
685 * This function causes all outstanding asynchronous accept operations to
686 * finish immediately, and the handlers for cancelled operations will be
687 * passed the boost::asio::error::operation_aborted error. Ownership of the
688 * native acceptor is then transferred to the caller.
690 * @throws boost::system::system_error Thrown on failure.
692 * @note This function is unsupported on Windows versions prior to Windows
693 * 8.1, and will fail with boost::asio::error::operation_not_supported on
696 #if defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC >= 1400) \
697 && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0603)
698 __declspec(deprecated("This function always fails with "
699 "operation_not_supported when used on Windows versions "
700 "prior to Windows 8.1."))
702 native_handle_type release()
704 boost::system::error_code ec;
705 native_handle_type s = impl_.get_service().release(
706 impl_.get_implementation(), ec);
707 boost::asio::detail::throw_error(ec, "release");
711 /// Release ownership of the underlying native acceptor.
713 * This function causes all outstanding asynchronous accept operations to
714 * finish immediately, and the handlers for cancelled operations will be
715 * passed the boost::asio::error::operation_aborted error. Ownership of the
716 * native acceptor is then transferred to the caller.
718 * @param ec Set to indicate what error occurred, if any.
720 * @note This function is unsupported on Windows versions prior to Windows
721 * 8.1, and will fail with boost::asio::error::operation_not_supported on
724 #if defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC >= 1400) \
725 && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0603)
726 __declspec(deprecated("This function always fails with "
727 "operation_not_supported when used on Windows versions "
728 "prior to Windows 8.1."))
730 native_handle_type release(boost::system::error_code& ec)
732 return impl_.get_service().release(impl_.get_implementation(), ec);
735 /// Get the native acceptor representation.
737 * This function may be used to obtain the underlying representation of the
738 * acceptor. This is intended to allow access to native acceptor functionality
739 * that is not otherwise provided.
741 native_handle_type native_handle()
743 return impl_.get_service().native_handle(impl_.get_implementation());
746 /// Cancel all asynchronous operations associated with the acceptor.
748 * This function causes all outstanding asynchronous connect, send and receive
749 * operations to finish immediately, and the handlers for cancelled operations
750 * will be passed the boost::asio::error::operation_aborted error.
752 * @throws boost::system::system_error Thrown on failure.
756 boost::system::error_code ec;
757 impl_.get_service().cancel(impl_.get_implementation(), ec);
758 boost::asio::detail::throw_error(ec, "cancel");
761 /// Cancel all asynchronous operations associated with the acceptor.
763 * This function causes all outstanding asynchronous connect, send and receive
764 * operations to finish immediately, and the handlers for cancelled operations
765 * will be passed the boost::asio::error::operation_aborted error.
767 * @param ec Set to indicate what error occurred, if any.
769 BOOST_ASIO_SYNC_OP_VOID cancel(boost::system::error_code& ec)
771 impl_.get_service().cancel(impl_.get_implementation(), ec);
772 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
775 /// Set an option on the acceptor.
777 * This function is used to set an option on the acceptor.
779 * @param option The new option value to be set on the acceptor.
781 * @throws boost::system::system_error Thrown on failure.
783 * @sa SettableSocketOption @n
784 * boost::asio::socket_base::reuse_address
785 * boost::asio::socket_base::enable_connection_aborted
788 * Setting the SOL_SOCKET/SO_REUSEADDR option:
790 * boost::asio::ip::tcp::acceptor acceptor(my_context);
792 * boost::asio::ip::tcp::acceptor::reuse_address option(true);
793 * acceptor.set_option(option);
796 template <typename SettableSocketOption>
797 void set_option(const SettableSocketOption& option)
799 boost::system::error_code ec;
800 impl_.get_service().set_option(impl_.get_implementation(), option, ec);
801 boost::asio::detail::throw_error(ec, "set_option");
804 /// Set an option on the acceptor.
806 * This function is used to set an option on the acceptor.
808 * @param option The new option value to be set on the acceptor.
810 * @param ec Set to indicate what error occurred, if any.
812 * @sa SettableSocketOption @n
813 * boost::asio::socket_base::reuse_address
814 * boost::asio::socket_base::enable_connection_aborted
817 * Setting the SOL_SOCKET/SO_REUSEADDR option:
819 * boost::asio::ip::tcp::acceptor acceptor(my_context);
821 * boost::asio::ip::tcp::acceptor::reuse_address option(true);
822 * boost::system::error_code ec;
823 * acceptor.set_option(option, ec);
826 * // An error occurred.
830 template <typename SettableSocketOption>
831 BOOST_ASIO_SYNC_OP_VOID set_option(const SettableSocketOption& option,
832 boost::system::error_code& ec)
834 impl_.get_service().set_option(impl_.get_implementation(), option, ec);
835 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
838 /// Get an option from the acceptor.
840 * This function is used to get the current value of an option on the
843 * @param option The option value to be obtained from the acceptor.
845 * @throws boost::system::system_error Thrown on failure.
847 * @sa GettableSocketOption @n
848 * boost::asio::socket_base::reuse_address
851 * Getting the value of the SOL_SOCKET/SO_REUSEADDR option:
853 * boost::asio::ip::tcp::acceptor acceptor(my_context);
855 * boost::asio::ip::tcp::acceptor::reuse_address option;
856 * acceptor.get_option(option);
857 * bool is_set = option.get();
860 template <typename GettableSocketOption>
861 void get_option(GettableSocketOption& option) const
863 boost::system::error_code ec;
864 impl_.get_service().get_option(impl_.get_implementation(), option, ec);
865 boost::asio::detail::throw_error(ec, "get_option");
868 /// Get an option from the acceptor.
870 * This function is used to get the current value of an option on the
873 * @param option The option value to be obtained from the acceptor.
875 * @param ec Set to indicate what error occurred, if any.
877 * @sa GettableSocketOption @n
878 * boost::asio::socket_base::reuse_address
881 * Getting the value of the SOL_SOCKET/SO_REUSEADDR option:
883 * boost::asio::ip::tcp::acceptor acceptor(my_context);
885 * boost::asio::ip::tcp::acceptor::reuse_address option;
886 * boost::system::error_code ec;
887 * acceptor.get_option(option, ec);
890 * // An error occurred.
892 * bool is_set = option.get();
895 template <typename GettableSocketOption>
896 BOOST_ASIO_SYNC_OP_VOID get_option(GettableSocketOption& option,
897 boost::system::error_code& ec) const
899 impl_.get_service().get_option(impl_.get_implementation(), option, ec);
900 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
903 /// Perform an IO control command on the acceptor.
905 * This function is used to execute an IO control command on the acceptor.
907 * @param command The IO control command to be performed on the acceptor.
909 * @throws boost::system::system_error Thrown on failure.
911 * @sa IoControlCommand @n
912 * boost::asio::socket_base::non_blocking_io
915 * Getting the number of bytes ready to read:
917 * boost::asio::ip::tcp::acceptor acceptor(my_context);
919 * boost::asio::ip::tcp::acceptor::non_blocking_io command(true);
920 * socket.io_control(command);
923 template <typename IoControlCommand>
924 void io_control(IoControlCommand& command)
926 boost::system::error_code ec;
927 impl_.get_service().io_control(impl_.get_implementation(), command, ec);
928 boost::asio::detail::throw_error(ec, "io_control");
931 /// Perform an IO control command on the acceptor.
933 * This function is used to execute an IO control command on the acceptor.
935 * @param command The IO control command to be performed on the acceptor.
937 * @param ec Set to indicate what error occurred, if any.
939 * @sa IoControlCommand @n
940 * boost::asio::socket_base::non_blocking_io
943 * Getting the number of bytes ready to read:
945 * boost::asio::ip::tcp::acceptor acceptor(my_context);
947 * boost::asio::ip::tcp::acceptor::non_blocking_io command(true);
948 * boost::system::error_code ec;
949 * socket.io_control(command, ec);
952 * // An error occurred.
956 template <typename IoControlCommand>
957 BOOST_ASIO_SYNC_OP_VOID io_control(IoControlCommand& command,
958 boost::system::error_code& ec)
960 impl_.get_service().io_control(impl_.get_implementation(), command, ec);
961 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
964 /// Gets the non-blocking mode of the acceptor.
966 * @returns @c true if the acceptor's synchronous operations will fail with
967 * boost::asio::error::would_block if they are unable to perform the requested
968 * operation immediately. If @c false, synchronous operations will block
971 * @note The non-blocking mode has no effect on the behaviour of asynchronous
972 * operations. Asynchronous operations will never fail with the error
973 * boost::asio::error::would_block.
975 bool non_blocking() const
977 return impl_.get_service().non_blocking(impl_.get_implementation());
980 /// Sets the non-blocking mode of the acceptor.
982 * @param mode If @c true, the acceptor's synchronous operations will fail
983 * with boost::asio::error::would_block if they are unable to perform the
984 * requested operation immediately. If @c false, synchronous operations will
985 * block until complete.
987 * @throws boost::system::system_error Thrown on failure.
989 * @note The non-blocking mode has no effect on the behaviour of asynchronous
990 * operations. Asynchronous operations will never fail with the error
991 * boost::asio::error::would_block.
993 void non_blocking(bool mode)
995 boost::system::error_code ec;
996 impl_.get_service().non_blocking(impl_.get_implementation(), mode, ec);
997 boost::asio::detail::throw_error(ec, "non_blocking");
1000 /// Sets the non-blocking mode of the acceptor.
1002 * @param mode If @c true, the acceptor's synchronous operations will fail
1003 * with boost::asio::error::would_block if they are unable to perform the
1004 * requested operation immediately. If @c false, synchronous operations will
1005 * block until complete.
1007 * @param ec Set to indicate what error occurred, if any.
1009 * @note The non-blocking mode has no effect on the behaviour of asynchronous
1010 * operations. Asynchronous operations will never fail with the error
1011 * boost::asio::error::would_block.
1013 BOOST_ASIO_SYNC_OP_VOID non_blocking(
1014 bool mode, boost::system::error_code& ec)
1016 impl_.get_service().non_blocking(impl_.get_implementation(), mode, ec);
1017 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
1020 /// Gets the non-blocking mode of the native acceptor implementation.
1022 * This function is used to retrieve the non-blocking mode of the underlying
1023 * native acceptor. This mode has no effect on the behaviour of the acceptor
1024 * object's synchronous operations.
1026 * @returns @c true if the underlying acceptor is in non-blocking mode and
1027 * direct system calls may fail with boost::asio::error::would_block (or the
1028 * equivalent system error).
1030 * @note The current non-blocking mode is cached by the acceptor object.
1031 * Consequently, the return value may be incorrect if the non-blocking mode
1032 * was set directly on the native acceptor.
1034 bool native_non_blocking() const
1036 return impl_.get_service().native_non_blocking(impl_.get_implementation());
1039 /// Sets the non-blocking mode of the native acceptor implementation.
1041 * This function is used to modify the non-blocking mode of the underlying
1042 * native acceptor. It has no effect on the behaviour of the acceptor object's
1043 * synchronous operations.
1045 * @param mode If @c true, the underlying acceptor is put into non-blocking
1046 * mode and direct system calls may fail with boost::asio::error::would_block
1047 * (or the equivalent system error).
1049 * @throws boost::system::system_error Thrown on failure. If the @c mode is
1050 * @c false, but the current value of @c non_blocking() is @c true, this
1051 * function fails with boost::asio::error::invalid_argument, as the
1052 * combination does not make sense.
1054 void native_non_blocking(bool mode)
1056 boost::system::error_code ec;
1057 impl_.get_service().native_non_blocking(
1058 impl_.get_implementation(), mode, ec);
1059 boost::asio::detail::throw_error(ec, "native_non_blocking");
1062 /// Sets the non-blocking mode of the native acceptor implementation.
1064 * This function is used to modify the non-blocking mode of the underlying
1065 * native acceptor. It has no effect on the behaviour of the acceptor object's
1066 * synchronous operations.
1068 * @param mode If @c true, the underlying acceptor is put into non-blocking
1069 * mode and direct system calls may fail with boost::asio::error::would_block
1070 * (or the equivalent system error).
1072 * @param ec Set to indicate what error occurred, if any. If the @c mode is
1073 * @c false, but the current value of @c non_blocking() is @c true, this
1074 * function fails with boost::asio::error::invalid_argument, as the
1075 * combination does not make sense.
1077 BOOST_ASIO_SYNC_OP_VOID native_non_blocking(
1078 bool mode, boost::system::error_code& ec)
1080 impl_.get_service().native_non_blocking(
1081 impl_.get_implementation(), mode, ec);
1082 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
1085 /// Get the local endpoint of the acceptor.
1087 * This function is used to obtain the locally bound endpoint of the acceptor.
1089 * @returns An object that represents the local endpoint of the acceptor.
1091 * @throws boost::system::system_error Thrown on failure.
1095 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1097 * boost::asio::ip::tcp::endpoint endpoint = acceptor.local_endpoint();
1100 endpoint_type local_endpoint() const
1102 boost::system::error_code ec;
1103 endpoint_type ep = impl_.get_service().local_endpoint(
1104 impl_.get_implementation(), ec);
1105 boost::asio::detail::throw_error(ec, "local_endpoint");
1109 /// Get the local endpoint of the acceptor.
1111 * This function is used to obtain the locally bound endpoint of the acceptor.
1113 * @param ec Set to indicate what error occurred, if any.
1115 * @returns An object that represents the local endpoint of the acceptor.
1116 * Returns a default-constructed endpoint object if an error occurred and the
1117 * error handler did not throw an exception.
1121 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1123 * boost::system::error_code ec;
1124 * boost::asio::ip::tcp::endpoint endpoint = acceptor.local_endpoint(ec);
1127 * // An error occurred.
1131 endpoint_type local_endpoint(boost::system::error_code& ec) const
1133 return impl_.get_service().local_endpoint(impl_.get_implementation(), ec);
1136 /// Wait for the acceptor to become ready to read, ready to write, or to have
1137 /// pending error conditions.
1139 * This function is used to perform a blocking wait for an acceptor to enter
1140 * a ready to read, write or error condition state.
1142 * @param w Specifies the desired acceptor state.
1145 * Waiting for an acceptor to become readable.
1147 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1149 * acceptor.wait(boost::asio::ip::tcp::acceptor::wait_read);
1152 void wait(wait_type w)
1154 boost::system::error_code ec;
1155 impl_.get_service().wait(impl_.get_implementation(), w, ec);
1156 boost::asio::detail::throw_error(ec, "wait");
1159 /// Wait for the acceptor to become ready to read, ready to write, or to have
1160 /// pending error conditions.
1162 * This function is used to perform a blocking wait for an acceptor to enter
1163 * a ready to read, write or error condition state.
1165 * @param w Specifies the desired acceptor state.
1167 * @param ec Set to indicate what error occurred, if any.
1170 * Waiting for an acceptor to become readable.
1172 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1174 * boost::system::error_code ec;
1175 * acceptor.wait(boost::asio::ip::tcp::acceptor::wait_read, ec);
1178 BOOST_ASIO_SYNC_OP_VOID wait(wait_type w, boost::system::error_code& ec)
1180 impl_.get_service().wait(impl_.get_implementation(), w, ec);
1181 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
1184 /// Asynchronously wait for the acceptor to become ready to read, ready to
1185 /// write, or to have pending error conditions.
1187 * This function is used to perform an asynchronous wait for an acceptor to
1188 * enter a ready to read, write or error condition state.
1190 * @param w Specifies the desired acceptor state.
1192 * @param handler The handler to be called when the wait operation completes.
1193 * Copies will be made of the handler as required. The function signature of
1194 * the handler must be:
1195 * @code void handler(
1196 * const boost::system::error_code& error // Result of operation
1198 * Regardless of whether the asynchronous operation completes immediately or
1199 * not, the handler will not be invoked from within this function. On
1200 * immediate completion, invocation of the handler will be performed in a
1201 * manner equivalent to using boost::asio::post().
1205 * void wait_handler(const boost::system::error_code& error)
1209 * // Wait succeeded.
1215 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1217 * acceptor.async_wait(
1218 * boost::asio::ip::tcp::acceptor::wait_read,
1223 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
1224 WaitHandler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1225 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WaitHandler,
1226 void (boost::system::error_code))
1227 async_wait(wait_type w,
1228 BOOST_ASIO_MOVE_ARG(WaitHandler) handler
1229 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
1231 return async_initiate<WaitHandler, void (boost::system::error_code)>(
1232 initiate_async_wait(this), handler, w);
1235 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
1236 /// Accept a new connection.
1238 * This function is used to accept a new connection from a peer into the
1239 * given socket. The function call will block until a new connection has been
1240 * accepted successfully or an error occurs.
1242 * @param peer The socket into which the new connection will be accepted.
1244 * @throws boost::system::system_error Thrown on failure.
1248 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1250 * boost::asio::ip::tcp::socket socket(my_context);
1251 * acceptor.accept(socket);
1254 template <typename Protocol1, typename Executor1>
1255 void accept(basic_socket<Protocol1, Executor1>& peer,
1257 is_convertible<Protocol, Protocol1>::value
1260 boost::system::error_code ec;
1261 impl_.get_service().accept(impl_.get_implementation(),
1262 peer, static_cast<endpoint_type*>(0), ec);
1263 boost::asio::detail::throw_error(ec, "accept");
1266 /// Accept a new connection.
1268 * This function is used to accept a new connection from a peer into the
1269 * given socket. The function call will block until a new connection has been
1270 * accepted successfully or an error occurs.
1272 * @param peer The socket into which the new connection will be accepted.
1274 * @param ec Set to indicate what error occurred, if any.
1278 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1280 * boost::asio::ip::tcp::socket socket(my_context);
1281 * boost::system::error_code ec;
1282 * acceptor.accept(socket, ec);
1285 * // An error occurred.
1289 template <typename Protocol1, typename Executor1>
1290 BOOST_ASIO_SYNC_OP_VOID accept(
1291 basic_socket<Protocol1, Executor1>& peer, boost::system::error_code& ec,
1293 is_convertible<Protocol, Protocol1>::value
1296 impl_.get_service().accept(impl_.get_implementation(),
1297 peer, static_cast<endpoint_type*>(0), ec);
1298 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
1301 /// Start an asynchronous accept.
1303 * This function is used to asynchronously accept a new connection into a
1304 * socket. The function call always returns immediately.
1306 * @param peer The socket into which the new connection will be accepted.
1307 * Ownership of the peer object is retained by the caller, which must
1308 * guarantee that it is valid until the handler is called.
1310 * @param handler The handler to be called when the accept operation
1311 * completes. Copies will be made of the handler as required. The function
1312 * signature of the handler must be:
1313 * @code void handler(
1314 * const boost::system::error_code& error // Result of operation.
1316 * Regardless of whether the asynchronous operation completes immediately or
1317 * not, the handler will not be invoked from within this function. On
1318 * immediate completion, invocation of the handler will be performed in a
1319 * manner equivalent to using boost::asio::post().
1323 * void accept_handler(const boost::system::error_code& error)
1327 * // Accept succeeded.
1333 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1335 * boost::asio::ip::tcp::socket socket(my_context);
1336 * acceptor.async_accept(socket, accept_handler);
1339 template <typename Protocol1, typename Executor1,
1340 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
1341 AcceptHandler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1342 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(AcceptHandler,
1343 void (boost::system::error_code))
1344 async_accept(basic_socket<Protocol1, Executor1>& peer,
1345 BOOST_ASIO_MOVE_ARG(AcceptHandler) handler
1346 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type),
1348 is_convertible<Protocol, Protocol1>::value
1351 return async_initiate<AcceptHandler, void (boost::system::error_code)>(
1352 initiate_async_accept(this), handler,
1353 &peer, static_cast<endpoint_type*>(0));
1356 /// Accept a new connection and obtain the endpoint of the peer
1358 * This function is used to accept a new connection from a peer into the
1359 * given socket, and additionally provide the endpoint of the remote peer.
1360 * The function call will block until a new connection has been accepted
1361 * successfully or an error occurs.
1363 * @param peer The socket into which the new connection will be accepted.
1365 * @param peer_endpoint An endpoint object which will receive the endpoint of
1368 * @throws boost::system::system_error Thrown on failure.
1372 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1374 * boost::asio::ip::tcp::socket socket(my_context);
1375 * boost::asio::ip::tcp::endpoint endpoint;
1376 * acceptor.accept(socket, endpoint);
1379 template <typename Executor1>
1380 void accept(basic_socket<protocol_type, Executor1>& peer,
1381 endpoint_type& peer_endpoint)
1383 boost::system::error_code ec;
1384 impl_.get_service().accept(impl_.get_implementation(),
1385 peer, &peer_endpoint, ec);
1386 boost::asio::detail::throw_error(ec, "accept");
1389 /// Accept a new connection and obtain the endpoint of the peer
1391 * This function is used to accept a new connection from a peer into the
1392 * given socket, and additionally provide the endpoint of the remote peer.
1393 * The function call will block until a new connection has been accepted
1394 * successfully or an error occurs.
1396 * @param peer The socket into which the new connection will be accepted.
1398 * @param peer_endpoint An endpoint object which will receive the endpoint of
1401 * @param ec Set to indicate what error occurred, if any.
1405 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1407 * boost::asio::ip::tcp::socket socket(my_context);
1408 * boost::asio::ip::tcp::endpoint endpoint;
1409 * boost::system::error_code ec;
1410 * acceptor.accept(socket, endpoint, ec);
1413 * // An error occurred.
1417 template <typename Executor1>
1418 BOOST_ASIO_SYNC_OP_VOID accept(basic_socket<protocol_type, Executor1>& peer,
1419 endpoint_type& peer_endpoint, boost::system::error_code& ec)
1421 impl_.get_service().accept(
1422 impl_.get_implementation(), peer, &peer_endpoint, ec);
1423 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
1426 /// Start an asynchronous accept.
1428 * This function is used to asynchronously accept a new connection into a
1429 * socket, and additionally obtain the endpoint of the remote peer. The
1430 * function call always returns immediately.
1432 * @param peer The socket into which the new connection will be accepted.
1433 * Ownership of the peer object is retained by the caller, which must
1434 * guarantee that it is valid until the handler is called.
1436 * @param peer_endpoint An endpoint object into which the endpoint of the
1437 * remote peer will be written. Ownership of the peer_endpoint object is
1438 * retained by the caller, which must guarantee that it is valid until the
1439 * handler is called.
1441 * @param handler The handler to be called when the accept operation
1442 * completes. Copies will be made of the handler as required. The function
1443 * signature of the handler must be:
1444 * @code void handler(
1445 * const boost::system::error_code& error // Result of operation.
1447 * Regardless of whether the asynchronous operation completes immediately or
1448 * not, the handler will not be invoked from within this function. On
1449 * immediate completion, invocation of the handler will be performed in a
1450 * manner equivalent to using boost::asio::post().
1452 template <typename Executor1,
1453 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
1454 AcceptHandler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1455 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(AcceptHandler,
1456 void (boost::system::error_code))
1457 async_accept(basic_socket<protocol_type, Executor1>& peer,
1458 endpoint_type& peer_endpoint,
1459 BOOST_ASIO_MOVE_ARG(AcceptHandler) handler
1460 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
1462 return async_initiate<AcceptHandler, void (boost::system::error_code)>(
1463 initiate_async_accept(this), handler, &peer, &peer_endpoint);
1465 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
1467 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
1468 /// Accept a new connection.
1470 * This function is used to accept a new connection from a peer. The function
1471 * call will block until a new connection has been accepted successfully or
1474 * This overload requires that the Protocol template parameter satisfy the
1475 * AcceptableProtocol type requirements.
1477 * @returns A socket object representing the newly accepted connection.
1479 * @throws boost::system::system_error Thrown on failure.
1483 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1485 * boost::asio::ip::tcp::socket socket(acceptor.accept());
1488 typename Protocol::socket::template rebind_executor<executor_type>::other
1491 boost::system::error_code ec;
1492 typename Protocol::socket::template rebind_executor<
1493 executor_type>::other peer(impl_.get_executor());
1494 impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
1495 boost::asio::detail::throw_error(ec, "accept");
1499 /// Accept a new connection.
1501 * This function is used to accept a new connection from a peer. The function
1502 * call will block until a new connection has been accepted successfully or
1505 * This overload requires that the Protocol template parameter satisfy the
1506 * AcceptableProtocol type requirements.
1508 * @param ec Set to indicate what error occurred, if any.
1510 * @returns On success, a socket object representing the newly accepted
1511 * connection. On error, a socket object where is_open() is false.
1515 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1517 * boost::asio::ip::tcp::socket socket(acceptor.accept(ec));
1520 * // An error occurred.
1524 typename Protocol::socket::template rebind_executor<executor_type>::other
1525 accept(boost::system::error_code& ec)
1527 typename Protocol::socket::template rebind_executor<
1528 executor_type>::other peer(impl_.get_executor());
1529 impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
1533 /// Start an asynchronous accept.
1535 * This function is used to asynchronously accept a new connection. The
1536 * function call always returns immediately.
1538 * This overload requires that the Protocol template parameter satisfy the
1539 * AcceptableProtocol type requirements.
1541 * @param handler The handler to be called when the accept operation
1542 * completes. Copies will be made of the handler as required. The function
1543 * signature of the handler must be:
1544 * @code void handler(
1545 * // Result of operation.
1546 * const boost::system::error_code& error,
1547 * // On success, the newly accepted socket.
1548 * typename Protocol::socket::template
1549 * rebind_executor<executor_type>::other peer
1551 * Regardless of whether the asynchronous operation completes immediately or
1552 * not, the handler will not be invoked from within this function. On
1553 * immediate completion, invocation of the handler will be performed in a
1554 * manner equivalent to using boost::asio::post().
1558 * void accept_handler(const boost::system::error_code& error,
1559 * boost::asio::ip::tcp::socket peer)
1563 * // Accept succeeded.
1569 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1571 * acceptor.async_accept(accept_handler);
1575 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1576 typename Protocol::socket::template rebind_executor<
1577 executor_type>::other)) MoveAcceptHandler
1578 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1579 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(MoveAcceptHandler,
1580 void (boost::system::error_code,
1581 typename Protocol::socket::template
1582 rebind_executor<executor_type>::other))
1584 BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler
1585 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
1587 return async_initiate<MoveAcceptHandler,
1588 void (boost::system::error_code, typename Protocol::socket::template
1589 rebind_executor<executor_type>::other)>(
1590 initiate_async_move_accept(this), handler,
1591 impl_.get_executor(), static_cast<endpoint_type*>(0),
1592 static_cast<typename Protocol::socket::template
1593 rebind_executor<executor_type>::other*>(0));
1596 /// Accept a new connection.
1598 * This function is used to accept a new connection from a peer. The function
1599 * call will block until a new connection has been accepted successfully or
1602 * This overload requires that the Protocol template parameter satisfy the
1603 * AcceptableProtocol type requirements.
1605 * @param ex The I/O executor object to be used for the newly
1608 * @returns A socket object representing the newly accepted connection.
1610 * @throws boost::system::system_error Thrown on failure.
1614 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1616 * boost::asio::ip::tcp::socket socket(acceptor.accept());
1619 template <typename Executor1>
1620 typename Protocol::socket::template rebind_executor<Executor1>::other
1621 accept(const Executor1& ex,
1623 is_executor<Executor1>::value
1624 || execution::is_executor<Executor1>::value
1627 boost::system::error_code ec;
1628 typename Protocol::socket::template
1629 rebind_executor<Executor1>::other peer(ex);
1630 impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
1631 boost::asio::detail::throw_error(ec, "accept");
1635 /// Accept a new connection.
1637 * This function is used to accept a new connection from a peer. The function
1638 * call will block until a new connection has been accepted successfully or
1641 * This overload requires that the Protocol template parameter satisfy the
1642 * AcceptableProtocol type requirements.
1644 * @param context The I/O execution context object to be used for the newly
1647 * @returns A socket object representing the newly accepted connection.
1649 * @throws boost::system::system_error Thrown on failure.
1653 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1655 * boost::asio::ip::tcp::socket socket(acceptor.accept());
1658 template <typename ExecutionContext>
1659 typename Protocol::socket::template rebind_executor<
1660 typename ExecutionContext::executor_type>::other
1661 accept(ExecutionContext& context,
1663 is_convertible<ExecutionContext&, execution_context&>::value
1666 boost::system::error_code ec;
1667 typename Protocol::socket::template rebind_executor<
1668 typename ExecutionContext::executor_type>::other peer(context);
1669 impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
1670 boost::asio::detail::throw_error(ec, "accept");
1674 /// Accept a new connection.
1676 * This function is used to accept a new connection from a peer. The function
1677 * call will block until a new connection has been accepted successfully or
1680 * This overload requires that the Protocol template parameter satisfy the
1681 * AcceptableProtocol type requirements.
1683 * @param ex The I/O executor object to be used for the newly accepted
1686 * @param ec Set to indicate what error occurred, if any.
1688 * @returns On success, a socket object representing the newly accepted
1689 * connection. On error, a socket object where is_open() is false.
1693 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1695 * boost::asio::ip::tcp::socket socket(acceptor.accept(my_context2, ec));
1698 * // An error occurred.
1702 template <typename Executor1>
1703 typename Protocol::socket::template rebind_executor<Executor1>::other
1704 accept(const Executor1& ex, boost::system::error_code& ec,
1706 is_executor<Executor1>::value
1707 || execution::is_executor<Executor1>::value
1710 typename Protocol::socket::template
1711 rebind_executor<Executor1>::other peer(ex);
1712 impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
1716 /// Accept a new connection.
1718 * This function is used to accept a new connection from a peer. The function
1719 * call will block until a new connection has been accepted successfully or
1722 * This overload requires that the Protocol template parameter satisfy the
1723 * AcceptableProtocol type requirements.
1725 * @param context The I/O execution context object to be used for the newly
1728 * @param ec Set to indicate what error occurred, if any.
1730 * @returns On success, a socket object representing the newly accepted
1731 * connection. On error, a socket object where is_open() is false.
1735 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1737 * boost::asio::ip::tcp::socket socket(acceptor.accept(my_context2, ec));
1740 * // An error occurred.
1744 template <typename ExecutionContext>
1745 typename Protocol::socket::template rebind_executor<
1746 typename ExecutionContext::executor_type>::other
1747 accept(ExecutionContext& context, boost::system::error_code& ec,
1749 is_convertible<ExecutionContext&, execution_context&>::value
1752 typename Protocol::socket::template rebind_executor<
1753 typename ExecutionContext::executor_type>::other peer(context);
1754 impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
1758 /// Start an asynchronous accept.
1760 * This function is used to asynchronously accept a new connection. The
1761 * function call always returns immediately.
1763 * This overload requires that the Protocol template parameter satisfy the
1764 * AcceptableProtocol type requirements.
1766 * @param ex The I/O executor object to be used for the newly accepted
1769 * @param handler The handler to be called when the accept operation
1770 * completes. Copies will be made of the handler as required. The function
1771 * signature of the handler must be:
1772 * @code void handler(
1773 * const boost::system::error_code& error, // Result of operation.
1774 * typename Protocol::socket::template rebind_executor<
1775 * Executor1>::other peer // On success, the newly accepted socket.
1777 * Regardless of whether the asynchronous operation completes immediately or
1778 * not, the handler will not be invoked from within this function. On
1779 * immediate completion, invocation of the handler will be performed in a
1780 * manner equivalent to using boost::asio::post().
1784 * void accept_handler(const boost::system::error_code& error,
1785 * boost::asio::ip::tcp::socket peer)
1789 * // Accept succeeded.
1795 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1797 * acceptor.async_accept(my_context2, accept_handler);
1800 template <typename Executor1,
1801 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1802 typename Protocol::socket::template rebind_executor<
1803 Executor1>::other)) MoveAcceptHandler
1804 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1805 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(MoveAcceptHandler,
1806 void (boost::system::error_code,
1807 typename Protocol::socket::template rebind_executor<
1809 async_accept(const Executor1& ex,
1810 BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler
1811 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type),
1813 is_executor<Executor1>::value
1814 || execution::is_executor<Executor1>::value
1817 typedef typename Protocol::socket::template rebind_executor<
1818 Executor1>::other other_socket_type;
1820 return async_initiate<MoveAcceptHandler,
1821 void (boost::system::error_code, other_socket_type)>(
1822 initiate_async_move_accept(this), handler,
1823 ex, static_cast<endpoint_type*>(0),
1824 static_cast<other_socket_type*>(0));
1827 /// Start an asynchronous accept.
1829 * This function is used to asynchronously accept a new connection. The
1830 * function call always returns immediately.
1832 * This overload requires that the Protocol template parameter satisfy the
1833 * AcceptableProtocol type requirements.
1835 * @param context The I/O execution context object to be used for the newly
1838 * @param handler The handler to be called when the accept operation
1839 * completes. Copies will be made of the handler as required. The function
1840 * signature of the handler must be:
1841 * @code void handler(
1842 * const boost::system::error_code& error, // Result of operation.
1843 * typename Protocol::socket::template rebind_executor<
1844 * typename ExecutionContext::executor_type>::other peer
1845 * // On success, the newly accepted socket.
1847 * Regardless of whether the asynchronous operation completes immediately or
1848 * not, the handler will not be invoked from within this function. On
1849 * immediate completion, invocation of the handler will be performed in a
1850 * manner equivalent to using boost::asio::post().
1854 * void accept_handler(const boost::system::error_code& error,
1855 * boost::asio::ip::tcp::socket peer)
1859 * // Accept succeeded.
1865 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1867 * acceptor.async_accept(my_context2, accept_handler);
1870 template <typename ExecutionContext,
1871 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
1872 typename Protocol::socket::template rebind_executor<
1873 typename ExecutionContext::executor_type>::other)) MoveAcceptHandler
1874 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
1875 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(MoveAcceptHandler,
1876 void (boost::system::error_code,
1877 typename Protocol::socket::template rebind_executor<
1878 typename ExecutionContext::executor_type>::other))
1879 async_accept(ExecutionContext& context,
1880 BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler
1881 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type),
1883 is_convertible<ExecutionContext&, execution_context&>::value
1886 typedef typename Protocol::socket::template rebind_executor<
1887 typename ExecutionContext::executor_type>::other other_socket_type;
1889 return async_initiate<MoveAcceptHandler,
1890 void (boost::system::error_code, other_socket_type)>(
1891 initiate_async_move_accept(this), handler,
1892 context.get_executor(), static_cast<endpoint_type*>(0),
1893 static_cast<other_socket_type*>(0));
1896 /// Accept a new connection.
1898 * This function is used to accept a new connection from a peer. The function
1899 * call will block until a new connection has been accepted successfully or
1902 * This overload requires that the Protocol template parameter satisfy the
1903 * AcceptableProtocol type requirements.
1905 * @param peer_endpoint An endpoint object into which the endpoint of the
1906 * remote peer will be written.
1908 * @returns A socket object representing the newly accepted connection.
1910 * @throws boost::system::system_error Thrown on failure.
1914 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1916 * boost::asio::ip::tcp::endpoint endpoint;
1917 * boost::asio::ip::tcp::socket socket(acceptor.accept(endpoint));
1920 typename Protocol::socket::template rebind_executor<executor_type>::other
1921 accept(endpoint_type& peer_endpoint)
1923 boost::system::error_code ec;
1924 typename Protocol::socket::template rebind_executor<
1925 executor_type>::other peer(impl_.get_executor());
1926 impl_.get_service().accept(impl_.get_implementation(),
1927 peer, &peer_endpoint, ec);
1928 boost::asio::detail::throw_error(ec, "accept");
1932 /// Accept a new connection.
1934 * This function is used to accept a new connection from a peer. The function
1935 * call will block until a new connection has been accepted successfully or
1938 * This overload requires that the Protocol template parameter satisfy the
1939 * AcceptableProtocol type requirements.
1941 * @param peer_endpoint An endpoint object into which the endpoint of the
1942 * remote peer will be written.
1944 * @param ec Set to indicate what error occurred, if any.
1946 * @returns On success, a socket object representing the newly accepted
1947 * connection. On error, a socket object where is_open() is false.
1951 * boost::asio::ip::tcp::acceptor acceptor(my_context);
1953 * boost::asio::ip::tcp::endpoint endpoint;
1954 * boost::asio::ip::tcp::socket socket(acceptor.accept(endpoint, ec));
1957 * // An error occurred.
1961 typename Protocol::socket::template rebind_executor<executor_type>::other
1962 accept(endpoint_type& peer_endpoint, boost::system::error_code& ec)
1964 typename Protocol::socket::template rebind_executor<
1965 executor_type>::other peer(impl_.get_executor());
1966 impl_.get_service().accept(impl_.get_implementation(),
1967 peer, &peer_endpoint, ec);
1971 /// Start an asynchronous accept.
1973 * This function is used to asynchronously accept a new connection. The
1974 * function call always returns immediately.
1976 * This overload requires that the Protocol template parameter satisfy the
1977 * AcceptableProtocol type requirements.
1979 * @param peer_endpoint An endpoint object into which the endpoint of the
1980 * remote peer will be written. Ownership of the peer_endpoint object is
1981 * retained by the caller, which must guarantee that it is valid until the
1982 * handler is called.
1984 * @param handler The handler to be called when the accept operation
1985 * completes. Copies will be made of the handler as required. The function
1986 * signature of the handler must be:
1987 * @code void handler(
1988 * // Result of operation.
1989 * const boost::system::error_code& error,
1990 * // On success, the newly accepted socket.
1991 * typename Protocol::socket::template
1992 * rebind_executor<executor_type>::other peer
1994 * Regardless of whether the asynchronous operation completes immediately or
1995 * not, the handler will not be invoked from within this function. On
1996 * immediate completion, invocation of the handler will be performed in a
1997 * manner equivalent to using boost::asio::post().
2001 * void accept_handler(const boost::system::error_code& error,
2002 * boost::asio::ip::tcp::socket peer)
2006 * // Accept succeeded.
2012 * boost::asio::ip::tcp::acceptor acceptor(my_context);
2014 * boost::asio::ip::tcp::endpoint endpoint;
2015 * acceptor.async_accept(endpoint, accept_handler);
2019 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
2020 typename Protocol::socket::template rebind_executor<
2021 executor_type>::other)) MoveAcceptHandler
2022 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
2023 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(MoveAcceptHandler,
2024 void (boost::system::error_code,
2025 typename Protocol::socket::template
2026 rebind_executor<executor_type>::other))
2027 async_accept(endpoint_type& peer_endpoint,
2028 BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler
2029 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
2031 return async_initiate<MoveAcceptHandler,
2032 void (boost::system::error_code, typename Protocol::socket::template
2033 rebind_executor<executor_type>::other)>(
2034 initiate_async_move_accept(this), handler,
2035 impl_.get_executor(), &peer_endpoint,
2036 static_cast<typename Protocol::socket::template
2037 rebind_executor<executor_type>::other*>(0));
2040 /// Accept a new connection.
2042 * This function is used to accept a new connection from a peer. The function
2043 * call will block until a new connection has been accepted successfully or
2046 * This overload requires that the Protocol template parameter satisfy the
2047 * AcceptableProtocol type requirements.
2049 * @param ex The I/O executor object to be used for the newly accepted
2052 * @param peer_endpoint An endpoint object into which the endpoint of the
2053 * remote peer will be written.
2055 * @returns A socket object representing the newly accepted connection.
2057 * @throws boost::system::system_error Thrown on failure.
2061 * boost::asio::ip::tcp::acceptor acceptor(my_context);
2063 * boost::asio::ip::tcp::endpoint endpoint;
2064 * boost::asio::ip::tcp::socket socket(
2065 * acceptor.accept(my_context2, endpoint));
2068 template <typename Executor1>
2069 typename Protocol::socket::template rebind_executor<Executor1>::other
2070 accept(const Executor1& ex, endpoint_type& peer_endpoint,
2072 is_executor<Executor1>::value
2073 || execution::is_executor<Executor1>::value
2076 boost::system::error_code ec;
2077 typename Protocol::socket::template
2078 rebind_executor<Executor1>::other peer(ex);
2079 impl_.get_service().accept(impl_.get_implementation(),
2080 peer, &peer_endpoint, ec);
2081 boost::asio::detail::throw_error(ec, "accept");
2085 /// Accept a new connection.
2087 * This function is used to accept a new connection from a peer. The function
2088 * call will block until a new connection has been accepted successfully or
2091 * This overload requires that the Protocol template parameter satisfy the
2092 * AcceptableProtocol type requirements.
2094 * @param context The I/O execution context object to be used for the newly
2097 * @param peer_endpoint An endpoint object into which the endpoint of the
2098 * remote peer will be written.
2100 * @returns A socket object representing the newly accepted connection.
2102 * @throws boost::system::system_error Thrown on failure.
2106 * boost::asio::ip::tcp::acceptor acceptor(my_context);
2108 * boost::asio::ip::tcp::endpoint endpoint;
2109 * boost::asio::ip::tcp::socket socket(
2110 * acceptor.accept(my_context2, endpoint));
2113 template <typename ExecutionContext>
2114 typename Protocol::socket::template rebind_executor<
2115 typename ExecutionContext::executor_type>::other
2116 accept(ExecutionContext& context, endpoint_type& peer_endpoint,
2118 is_convertible<ExecutionContext&, execution_context&>::value
2121 boost::system::error_code ec;
2122 typename Protocol::socket::template rebind_executor<
2123 typename ExecutionContext::executor_type>::other peer(context);
2124 impl_.get_service().accept(impl_.get_implementation(),
2125 peer, &peer_endpoint, ec);
2126 boost::asio::detail::throw_error(ec, "accept");
2130 /// Accept a new connection.
2132 * This function is used to accept a new connection from a peer. The function
2133 * call will block until a new connection has been accepted successfully or
2136 * This overload requires that the Protocol template parameter satisfy the
2137 * AcceptableProtocol type requirements.
2139 * @param ex The I/O executor object to be used for the newly accepted
2142 * @param peer_endpoint An endpoint object into which the endpoint of the
2143 * remote peer will be written.
2145 * @param ec Set to indicate what error occurred, if any.
2147 * @returns On success, a socket object representing the newly accepted
2148 * connection. On error, a socket object where is_open() is false.
2152 * boost::asio::ip::tcp::acceptor acceptor(my_context);
2154 * boost::asio::ip::tcp::endpoint endpoint;
2155 * boost::asio::ip::tcp::socket socket(
2156 * acceptor.accept(my_context2, endpoint, ec));
2159 * // An error occurred.
2163 template <typename Executor1>
2164 typename Protocol::socket::template rebind_executor<Executor1>::other
2165 accept(const executor_type& ex,
2166 endpoint_type& peer_endpoint, boost::system::error_code& ec,
2168 is_executor<Executor1>::value
2169 || execution::is_executor<Executor1>::value
2172 typename Protocol::socket::template
2173 rebind_executor<Executor1>::other peer(ex);
2174 impl_.get_service().accept(impl_.get_implementation(),
2175 peer, &peer_endpoint, ec);
2179 /// Accept a new connection.
2181 * This function is used to accept a new connection from a peer. The function
2182 * call will block until a new connection has been accepted successfully or
2185 * This overload requires that the Protocol template parameter satisfy the
2186 * AcceptableProtocol type requirements.
2188 * @param context The I/O execution context object to be used for the newly
2191 * @param peer_endpoint An endpoint object into which the endpoint of the
2192 * remote peer will be written.
2194 * @param ec Set to indicate what error occurred, if any.
2196 * @returns On success, a socket object representing the newly accepted
2197 * connection. On error, a socket object where is_open() is false.
2201 * boost::asio::ip::tcp::acceptor acceptor(my_context);
2203 * boost::asio::ip::tcp::endpoint endpoint;
2204 * boost::asio::ip::tcp::socket socket(
2205 * acceptor.accept(my_context2, endpoint, ec));
2208 * // An error occurred.
2212 template <typename ExecutionContext>
2213 typename Protocol::socket::template rebind_executor<
2214 typename ExecutionContext::executor_type>::other
2215 accept(ExecutionContext& context,
2216 endpoint_type& peer_endpoint, boost::system::error_code& ec,
2218 is_convertible<ExecutionContext&, execution_context&>::value
2221 typename Protocol::socket::template rebind_executor<
2222 typename ExecutionContext::executor_type>::other peer(context);
2223 impl_.get_service().accept(impl_.get_implementation(),
2224 peer, &peer_endpoint, ec);
2228 /// Start an asynchronous accept.
2230 * This function is used to asynchronously accept a new connection. The
2231 * function call always returns immediately.
2233 * This overload requires that the Protocol template parameter satisfy the
2234 * AcceptableProtocol type requirements.
2236 * @param ex The I/O executor object to be used for the newly accepted
2239 * @param peer_endpoint An endpoint object into which the endpoint of the
2240 * remote peer will be written. Ownership of the peer_endpoint object is
2241 * retained by the caller, which must guarantee that it is valid until the
2242 * handler is called.
2244 * @param handler The handler to be called when the accept operation
2245 * completes. Copies will be made of the handler as required. The function
2246 * signature of the handler must be:
2247 * @code void handler(
2248 * const boost::system::error_code& error, // Result of operation.
2249 * typename Protocol::socket::template rebind_executor<
2250 * Executor1>::other peer // On success, the newly accepted socket.
2252 * Regardless of whether the asynchronous operation completes immediately or
2253 * not, the handler will not be invoked from within this function. On
2254 * immediate completion, invocation of the handler will be performed in a
2255 * manner equivalent to using boost::asio::post().
2259 * void accept_handler(const boost::system::error_code& error,
2260 * boost::asio::ip::tcp::socket peer)
2264 * // Accept succeeded.
2270 * boost::asio::ip::tcp::acceptor acceptor(my_context);
2272 * boost::asio::ip::tcp::endpoint endpoint;
2273 * acceptor.async_accept(my_context2, endpoint, accept_handler);
2276 template <typename Executor1,
2277 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
2278 typename Protocol::socket::template rebind_executor<
2279 Executor1>::other)) MoveAcceptHandler
2280 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
2281 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(MoveAcceptHandler,
2282 void (boost::system::error_code,
2283 typename Protocol::socket::template rebind_executor<
2285 async_accept(const Executor1& ex, endpoint_type& peer_endpoint,
2286 BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler
2287 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type),
2289 is_executor<Executor1>::value
2290 || execution::is_executor<Executor1>::value
2293 typedef typename Protocol::socket::template rebind_executor<
2294 Executor1>::other other_socket_type;
2296 return async_initiate<MoveAcceptHandler,
2297 void (boost::system::error_code, other_socket_type)>(
2298 initiate_async_move_accept(this), handler,
2300 static_cast<other_socket_type*>(0));
2303 /// Start an asynchronous accept.
2305 * This function is used to asynchronously accept a new connection. The
2306 * function call always returns immediately.
2308 * This overload requires that the Protocol template parameter satisfy the
2309 * AcceptableProtocol type requirements.
2311 * @param context The I/O execution context object to be used for the newly
2314 * @param peer_endpoint An endpoint object into which the endpoint of the
2315 * remote peer will be written. Ownership of the peer_endpoint object is
2316 * retained by the caller, which must guarantee that it is valid until the
2317 * handler is called.
2319 * @param handler The handler to be called when the accept operation
2320 * completes. Copies will be made of the handler as required. The function
2321 * signature of the handler must be:
2322 * @code void handler(
2323 * const boost::system::error_code& error, // Result of operation.
2324 * typename Protocol::socket::template rebind_executor<
2325 * typename ExecutionContext::executor_type>::other peer
2326 * // On success, the newly accepted socket.
2328 * Regardless of whether the asynchronous operation completes immediately or
2329 * not, the handler will not be invoked from within this function. On
2330 * immediate completion, invocation of the handler will be performed in a
2331 * manner equivalent to using boost::asio::post().
2335 * void accept_handler(const boost::system::error_code& error,
2336 * boost::asio::ip::tcp::socket peer)
2340 * // Accept succeeded.
2346 * boost::asio::ip::tcp::acceptor acceptor(my_context);
2348 * boost::asio::ip::tcp::endpoint endpoint;
2349 * acceptor.async_accept(my_context2, endpoint, accept_handler);
2352 template <typename ExecutionContext,
2353 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
2354 typename Protocol::socket::template rebind_executor<
2355 typename ExecutionContext::executor_type>::other)) MoveAcceptHandler
2356 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
2357 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(MoveAcceptHandler,
2358 void (boost::system::error_code,
2359 typename Protocol::socket::template rebind_executor<
2360 typename ExecutionContext::executor_type>::other))
2361 async_accept(ExecutionContext& context,
2362 endpoint_type& peer_endpoint,
2363 BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler
2364 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type),
2366 is_convertible<ExecutionContext&, execution_context&>::value
2369 typedef typename Protocol::socket::template rebind_executor<
2370 typename ExecutionContext::executor_type>::other other_socket_type;
2372 return async_initiate<MoveAcceptHandler,
2373 void (boost::system::error_code, other_socket_type)>(
2374 initiate_async_move_accept(this), handler,
2375 context.get_executor(), &peer_endpoint,
2376 static_cast<other_socket_type*>(0));
2378 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
2381 // Disallow copying and assignment.
2382 basic_socket_acceptor(const basic_socket_acceptor&) BOOST_ASIO_DELETED;
2383 basic_socket_acceptor& operator=(
2384 const basic_socket_acceptor&) BOOST_ASIO_DELETED;
2386 class initiate_async_wait
2389 typedef Executor executor_type;
2391 explicit initiate_async_wait(basic_socket_acceptor* self)
2396 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
2398 return self_->get_executor();
2401 template <typename WaitHandler>
2402 void operator()(BOOST_ASIO_MOVE_ARG(WaitHandler) handler, wait_type w) const
2404 // If you get an error on the following line it means that your handler
2405 // does not meet the documented type requirements for a WaitHandler.
2406 BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
2408 detail::non_const_lvalue<WaitHandler> handler2(handler);
2409 self_->impl_.get_service().async_wait(
2410 self_->impl_.get_implementation(), w,
2411 handler2.value, self_->impl_.get_executor());
2415 basic_socket_acceptor* self_;
2418 class initiate_async_accept
2421 typedef Executor executor_type;
2423 explicit initiate_async_accept(basic_socket_acceptor* self)
2428 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
2430 return self_->get_executor();
2433 template <typename AcceptHandler, typename Protocol1, typename Executor1>
2434 void operator()(BOOST_ASIO_MOVE_ARG(AcceptHandler) handler,
2435 basic_socket<Protocol1, Executor1>* peer,
2436 endpoint_type* peer_endpoint) const
2438 // If you get an error on the following line it means that your handler
2439 // does not meet the documented type requirements for a AcceptHandler.
2440 BOOST_ASIO_ACCEPT_HANDLER_CHECK(AcceptHandler, handler) type_check;
2442 detail::non_const_lvalue<AcceptHandler> handler2(handler);
2443 self_->impl_.get_service().async_accept(
2444 self_->impl_.get_implementation(), *peer, peer_endpoint,
2445 handler2.value, self_->impl_.get_executor());
2449 basic_socket_acceptor* self_;
2452 class initiate_async_move_accept
2455 typedef Executor executor_type;
2457 explicit initiate_async_move_accept(basic_socket_acceptor* self)
2462 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
2464 return self_->get_executor();
2467 template <typename MoveAcceptHandler, typename Executor1, typename Socket>
2468 void operator()(BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler,
2469 const Executor1& peer_ex, endpoint_type* peer_endpoint, Socket*) const
2471 // If you get an error on the following line it means that your handler
2472 // does not meet the documented type requirements for a MoveAcceptHandler.
2473 BOOST_ASIO_MOVE_ACCEPT_HANDLER_CHECK(
2474 MoveAcceptHandler, handler, Socket) type_check;
2476 detail::non_const_lvalue<MoveAcceptHandler> handler2(handler);
2477 self_->impl_.get_service().async_move_accept(
2478 self_->impl_.get_implementation(), peer_ex, peer_endpoint,
2479 handler2.value, self_->impl_.get_executor());
2483 basic_socket_acceptor* self_;
2486 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
2487 detail::io_object_impl<
2488 detail::null_socket_service<Protocol>, Executor> impl_;
2489 #elif defined(BOOST_ASIO_HAS_IOCP)
2490 detail::io_object_impl<
2491 detail::win_iocp_socket_service<Protocol>, Executor> impl_;
2493 detail::io_object_impl<
2494 detail::reactive_socket_service<Protocol>, Executor> impl_;
2499 } // namespace boost
2501 #include <boost/asio/detail/pop_options.hpp>
2503 #endif // BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_HPP