From 31c7b406bd40b58b23c98c7cd960b69ef797e643 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Tue, 8 Feb 2011 20:37:31 +1100 Subject: [PATCH] Add io_control() member function to acceptor. --- asio/include/asio/basic_socket_acceptor.hpp | 60 +++++++++++++++++++++ asio/src/tests/unit/ip/tcp.cpp | 3 ++ 2 files changed, 63 insertions(+) diff --git a/asio/include/asio/basic_socket_acceptor.hpp b/asio/include/asio/basic_socket_acceptor.hpp index 210b8184..b6179c12 100644 --- a/asio/include/asio/basic_socket_acceptor.hpp +++ b/asio/include/asio/basic_socket_acceptor.hpp @@ -564,6 +564,66 @@ public: return this->service.get_option(this->implementation, option, ec); } + /// Perform an IO control command on the acceptor. + /** + * This function is used to execute an IO control command on the acceptor. + * + * @param command The IO control command to be performed on the acceptor. + * + * @throws asio::system_error Thrown on failure. + * + * @sa IoControlCommand @n + * asio::socket_base::non_blocking_io + * + * @par Example + * Getting the number of bytes ready to read: + * @code + * asio::ip::tcp::acceptor acceptor(io_service); + * ... + * asio::ip::tcp::acceptor::non_blocking_io command(true); + * socket.io_control(command); + * @endcode + */ + template + void io_control(IoControlCommand& command) + { + asio::error_code ec; + this->service.io_control(this->implementation, command, ec); + asio::detail::throw_error(ec); + } + + /// Perform an IO control command on the acceptor. + /** + * This function is used to execute an IO control command on the acceptor. + * + * @param command The IO control command to be performed on the acceptor. + * + * @param ec Set to indicate what error occurred, if any. + * + * @sa IoControlCommand @n + * asio::socket_base::non_blocking_io + * + * @par Example + * Getting the number of bytes ready to read: + * @code + * asio::ip::tcp::acceptor acceptor(io_service); + * ... + * asio::ip::tcp::acceptor::non_blocking_io command(true); + * asio::error_code ec; + * socket.io_control(command, ec); + * if (ec) + * { + * // An error occurred. + * } + * @endcode + */ + template + asio::error_code io_control(IoControlCommand& command, + asio::error_code& ec) + { + return this->service.io_control(this->implementation, command, ec); + } + /// Get the local endpoint of the acceptor. /** * This function is used to obtain the locally bound endpoint of the acceptor. diff --git a/asio/src/tests/unit/ip/tcp.cpp b/asio/src/tests/unit/ip/tcp.cpp index e26e58fc..b8d56d8a 100644 --- a/asio/src/tests/unit/ip/tcp.cpp +++ b/asio/src/tests/unit/ip/tcp.cpp @@ -515,6 +515,9 @@ void test() ip::tcp::endpoint client_endpoint; acceptor.accept(server_side_socket, client_endpoint); + ip::tcp::acceptor::non_blocking_io command(false); + acceptor.io_control(command); + ip::tcp::endpoint client_side_local_endpoint = client_side_socket.local_endpoint(); BOOST_CHECK(client_side_local_endpoint.port() == client_endpoint.port());