From cbba2f8ecd7eded1befcd84e06d3b5b2b75f5d48 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Sun, 20 May 2007 00:30:54 +0000 Subject: [PATCH] Documentation updates. [SVN r37718] --- doc/reference.qbk | 359 +++++++++++++++++++- doc/reference.xsl | 1 + include/boost/asio/basic_deadline_timer.hpp | 96 +++--- include/boost/asio/io_service.hpp | 71 ++-- 4 files changed, 425 insertions(+), 102 deletions(-) diff --git a/doc/reference.qbk b/doc/reference.qbk index 3ec37b0b..4d191668 100644 --- a/doc/reference.qbk +++ b/doc/reference.qbk @@ -3815,6 +3815,16 @@ A basic_socket is always the lowest layer. ] +The basic_socket class template provides functionality that is common to both stream-oriented and datagram-oriented sockets. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -5500,6 +5510,43 @@ Performing an asynchronous wait: +[heading Changing an active deadline_timer's expiry time] + + + +Changing the expiry time of a timer while there are pending asynchronous waits causes those wait operations to be cancelled. To ensure that the action associated with the timer is performed only once, use something like this: used: + + + + void on_some_event() + { + if (my_timer.expires_from_now(seconds(5)) > 0) + { + // We managed to cancel the timer. Start new asynchronous wait. + my_timer.async_wait(on_timeout); + } + else + { + // Too late, timer has already expired! + } + } + + void on_timeout(const boost::system::error_code& e) + { + if (e != boost::asio::error::operation_aborted) + { + // Timer was not cancelled, take necessary action. + } + } + + + + + +* The boost::asio::basic_deadline_timer::expires_from_now() function cancels any pending asynchronous waits, and returns the number of asynchronous waits that were cancelled. If it returns 0 then you were too late and the wait handler has already been executed, or will soon be executed. If it returns 1 then the wait handler was successfully cancelled. + +* If a wait handler is cancelled, the boost::system::error_code passed to it contains the value boost::asio::error::operation_aborted. + [section:async_wait basic_deadline_timer::async_wait] @@ -5768,8 +5815,6 @@ Set the timer's expiry time as an absolute time. This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the boost::asio::error::operation\_aborted error code. -See Changing an active deadline_timer's expiry time for more information on altering the expiry time of an active timer. - [heading Parameters] @@ -5810,8 +5855,6 @@ Set the timer's expiry time as an absolute time. This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the boost::asio::error::operation\_aborted error code. -See Changing an active deadline_timer's expiry time for more information on altering the expiry time of an active timer. - [heading Parameters] @@ -5873,8 +5916,6 @@ Set the timer's expiry time relative to now. This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the boost::asio::error::operation\_aborted error code. -See Changing an active deadline_timer's expiry time for more information on altering the expiry time of an active timer. - [heading Parameters] @@ -5915,8 +5956,6 @@ Set the timer's expiry time relative to now. This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the boost::asio::error::operation\_aborted error code. -See Changing an active deadline_timer's expiry time for more information on altering the expiry time of an active timer. - [heading Parameters] @@ -8247,6 +8286,16 @@ A basic_socket is always the lowest layer. ] +The basic_socket class template provides functionality that is common to both stream-oriented and datagram-oriented sockets. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -13597,6 +13646,16 @@ A basic_socket is always the lowest layer. ] +The basic_socket class template provides functionality that is common to both stream-oriented and datagram-oriented sockets. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -17022,6 +17081,16 @@ A basic_socket is always the lowest layer. ] +The basic_socket class template provides functionality that is common to both stream-oriented and datagram-oriented sockets. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -21150,6 +21219,8 @@ The type for each element in the list of buffers. ] +The const_buffer class provides a safe representation of a buffer that cannot be modified. It does not own the underlying data, and so is cheap to copy or assign. + [endsect] @@ -21998,6 +22069,93 @@ Typedef for the typical usage of timer. ] +The basic_deadline_timer class template provides the ability to perform a blocking or asynchronous wait for a timer to expire. + +Most applications will use the boost::asio::deadline\_timer typedef. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + +[heading Examples] + +Performing a blocking wait: + + // Construct a timer without setting an expiry time. + boost::asio::deadline_timer timer(io_service); + + // Set an expiry time relative to now. + timer.expires_from_now(boost::posix_time::seconds(5)); + + // Wait for the timer to expire. + timer.wait(); + + + + +Performing an asynchronous wait: + + void handler(const boost::system::error_code& error) + { + if (!error) + { + // Timer expired. + } + } + + ... + + // Construct a timer with an absolute expiry time. + boost::asio::deadline_timer timer(io_service, + boost::posix_time::time_from_string("2005-12-07 23:59:59.000")); + + // Start an asynchronous wait. + timer.async_wait(handler); + + + + +[heading Changing an active deadline_timer's expiry time] + + + +Changing the expiry time of a timer while there are pending asynchronous waits causes those wait operations to be cancelled. To ensure that the action associated with the timer is performed only once, use something like this: used: + + + + void on_some_event() + { + if (my_timer.expires_from_now(seconds(5)) > 0) + { + // We managed to cancel the timer. Start new asynchronous wait. + my_timer.async_wait(on_timeout); + } + else + { + // Too late, timer has already expired! + } + } + + void on_timeout(const boost::system::error_code& e) + { + if (e != boost::asio::error::operation_aborted) + { + // Timer was not cancelled, take necessary action. + } + } + + + + + +* The boost::asio::basic_deadline_timer::expires_from_now() function cancels any pending asynchronous waits, and returns the number of asynchronous waits that were cancelled. If it returns 0 then you were too late and the wait handler has already been executed, or will soon be executed. If it returns 1 then the wait handler was successfully cancelled. + +* If a wait handler is cancelled, the boost::system::error_code passed to it contains the value boost::asio::error::operation_aborted. + + [endsect] @@ -23570,6 +23728,35 @@ The io_service class also includes facilities intended for developers of custom [*Shared] [*objects:] Safe, with the exception that calling reset() while there are unfinished run() calls results in undefined behaviour. +[heading Effect of exceptions thrown from handlers] + + + +If an exception is thrown from a handler, the exception is allowed to propagate through the throwing thread's invocation of boost::asio::io\_service::run(), boost::asio::io\_service::run\_one(), boost::asio::io\_service::poll() or boost::asio::io\_service::poll\_one(). No other threads that are calling any of these functions are affected. It is then the responsibility of the application to catch the exception. + +After the exception has been caught, the boost::asio::io\_service::run(), boost::asio::io\_service::run\_one(), boost::asio::io\_service::poll() or boost::asio::io\_service::poll\_one() call may be restarted [*without] the need for an intervening call to boost::asio::io\_service::reset(). This allows the thread to rejoin the io\_service's thread pool without impacting any other threads in the pool. + +For example: + + + + boost::asio::io_service io_service; + ... + for (;;) + { + try + { + io_service.run(); + break; // run() exited normally + } + catch (my_exception& e) + { + // Deal with exception as appropriate. + } + } + + + [section:add_service io_service::add_service] @@ -29060,6 +29247,30 @@ The TCP acceptor type. ] +The basic_socket_acceptor class template is used for accepting new socket connections. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + +[heading Example] + +Opening a socket acceptor with the SO\_REUSEADDR option enabled: + + boost::asio::ip::tcp::acceptor acceptor(io_service); + boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port); + acceptor.open(endpoint.protocol()); + acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); + acceptor.bind(endpoint); + acceptor.listen(); + + + + + [endsect] @@ -29172,6 +29383,17 @@ The type of a TCP endpoint. ] +The +[link boost_asio.reference.ip__basic_endpoint ip::basic_endpoint] class template describes an endpoint that may be associated with a particular socket. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -29395,6 +29617,16 @@ The TCP resolver type. ] +The basic_resolver class template provides the ability to resolve a query to a list of endpoints. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -29424,6 +29656,24 @@ The type of a resolver iterator. ] +The +[link boost_asio.reference.ip__basic_resolver_iterator ip::basic_resolver_iterator] class template is used to define iterators over the results returned by a resolver. + +The iterator's value\_type, obtained when the iterator is dereferenced, is: + + const basic_resolver_entry + + + + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -29517,6 +29767,17 @@ The type of a resolver query. ] +The +[link boost_asio.reference.ip__basic_resolver_query ip::basic_resolver_query] class template describes a query that can be passed to a resolver. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -29855,6 +30116,16 @@ The TCP socket type. ] +The basic_stream_socket class template provides asynchronous and blocking stream-oriented socket functionality. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -30112,6 +30383,17 @@ The type of a UDP endpoint. ] +The +[link boost_asio.reference.ip__basic_endpoint ip::basic_endpoint] class template describes an endpoint that may be associated with a particular socket. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -30256,6 +30538,16 @@ The UDP resolver type. ] +The basic_resolver class template provides the ability to resolve a query to a list of endpoints. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -30285,6 +30577,24 @@ The type of a resolver iterator. ] +The +[link boost_asio.reference.ip__basic_resolver_iterator ip::basic_resolver_iterator] class template is used to define iterators over the results returned by a resolver. + +The iterator's value\_type, obtained when the iterator is dereferenced, is: + + const basic_resolver_entry + + + + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -30378,6 +30688,17 @@ The type of a resolver query. ] +The +[link boost_asio.reference.ip__basic_resolver_query ip::basic_resolver_query] class template describes a query that can be passed to a resolver. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -30716,6 +31037,16 @@ The IPv4 UDP socket type. ] +The basic_datagram_socket class template provides asynchronous and blocking datagram-oriented socket functionality. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Unsafe. + + [endsect] @@ -31147,6 +31478,8 @@ The type for each element in the list of buffers. ] +The mutable_buffer class provides a safe representation of a buffer that can be modified. It does not own the underlying data, and so is cheap to copy or assign. + [endsect] @@ -37195,6 +37528,16 @@ Typedef for backwards compatibility. ] +The io_service::strand class provides the ability to post and dispatch handlers with the guarantee that none of those handlers will execute concurrently. + + +[heading Thread Safety] + +[*Distinct] [*objects:] Safe. + +[*Shared] [*objects:] Safe. + + [endsect] diff --git a/doc/reference.xsl b/doc/reference.xsl index fda9951b..e72a8d40 100644 --- a/doc/reference.xsl +++ b/doc/reference.xsl @@ -778,6 +778,7 @@ + diff --git a/include/boost/asio/basic_deadline_timer.hpp b/include/boost/asio/basic_deadline_timer.hpp index 422eabde..67750a49 100644 --- a/include/boost/asio/basic_deadline_timer.hpp +++ b/include/boost/asio/basic_deadline_timer.hpp @@ -41,8 +41,6 @@ namespace asio { * @e Distinct @e objects: Safe.@n * @e Shared @e objects: Unsafe. * - * @sa @ref deadline_timer_reset - * * @par Examples * Performing a blocking wait: * @code @@ -76,6 +74,45 @@ namespace asio { * // Start an asynchronous wait. * timer.async_wait(handler); * @endcode + * + * @par Changing an active deadline_timer's expiry time + * + * Changing the expiry time of a timer while there are pending asynchronous + * waits causes those wait operations to be cancelled. To ensure that the action + * associated with the timer is performed only once, use something like this: + * used: + * + * @code + * void on_some_event() + * { + * if (my_timer.expires_from_now(seconds(5)) > 0) + * { + * // We managed to cancel the timer. Start new asynchronous wait. + * my_timer.async_wait(on_timeout); + * } + * else + * { + * // Too late, timer has already expired! + * } + * } + * + * void on_timeout(const boost::system::error_code& e) + * { + * if (e != boost::asio::error::operation_aborted) + * { + * // Timer was not cancelled, take necessary action. + * } + * } + * @endcode + * + * @li The boost::asio::basic_deadline_timer::expires_from_now() function + * cancels any pending asynchronous waits, and returns the number of + * asynchronous waits that were cancelled. If it returns 0 then you were too + * late and the wait handler has already been executed, or will soon be + * executed. If it returns 1 then the wait handler was successfully cancelled. + * + * @li If a wait handler is cancelled, the boost::system::error_code passed to + * it contains the value boost::asio::error::operation_aborted. */ template , @@ -198,9 +235,6 @@ public: * operations will be cancelled. The handler for each cancelled operation will * be invoked with the boost::asio::error::operation_aborted error code. * - * See @ref deadline_timer_reset for more information on altering the expiry - * time of an active timer. - * * @param expiry_time The expiry time to be used for the timer. * * @return The number of asynchronous operations that were cancelled. @@ -222,9 +256,6 @@ public: * operations will be cancelled. The handler for each cancelled operation will * be invoked with the boost::asio::error::operation_aborted error code. * - * See @ref deadline_timer_reset for more information on altering the expiry - * time of an active timer. - * * @param expiry_time The expiry time to be used for the timer. * * @param ec Set to indicate what error occurred, if any. @@ -253,9 +284,6 @@ public: * operations will be cancelled. The handler for each cancelled operation will * be invoked with the boost::asio::error::operation_aborted error code. * - * See @ref deadline_timer_reset for more information on altering the expiry - * time of an active timer. - * * @param expiry_time The expiry time to be used for the timer. * * @return The number of asynchronous operations that were cancelled. @@ -277,9 +305,6 @@ public: * operations will be cancelled. The handler for each cancelled operation will * be invoked with the boost::asio::error::operation_aborted error code. * - * See @ref deadline_timer_reset for more information on altering the expiry - * time of an active timer. - * * @param expiry_time The expiry time to be used for the timer. * * @param ec Set to indicate what error occurred, if any. @@ -350,49 +375,6 @@ public: } }; -/** - * @page deadline_timer_reset Changing an active deadline_timer's expiry time - * - * Changing the expiry time of a timer while there are pending asynchronous - * waits causes those wait operations to be cancelled. To ensure that the action - * associated with the timer is performed only once, use something like this: - * used: - * - * @code - * void on_some_event() - * { - * if (my_timer.expires_from_now(seconds(5)) > 0) - * { - * // We managed to cancel the timer. Start new asynchronous wait. - * my_timer.async_wait(on_timeout); - * } - * else - * { - * // Too late, timer has already expired! - * } - * } - * - * void on_timeout(const boost::system::error_code& e) - * { - * if (e != boost::asio::error::operation_aborted) - * { - * // Timer was not cancelled, take necessary action. - * } - * } - * @endcode - * - * @li The boost::asio::basic_deadline_timer::expires_from_now() function - * cancels any pending asynchronous waits, and returns the number of - * asynchronous waits that were cancelled. If it returns 0 then you were too - * late and the wait handler has already been executed, or will soon be - * executed. If it returns 1 then the wait handler was successfully cancelled. - * - * @li If a wait handler is cancelled, the boost::system::error_code passed to - * it contains the value boost::asio::error::operation_aborted. - * - * @sa boost::asio::basic_deadline_timer - */ - } // namespace asio } // namespace boost diff --git a/include/boost/asio/io_service.hpp b/include/boost/asio/io_service.hpp index 0ba6b15b..dea7a046 100644 --- a/include/boost/asio/io_service.hpp +++ b/include/boost/asio/io_service.hpp @@ -61,7 +61,40 @@ namespace asio { * @par Concepts: * Dispatcher. * - * @sa @ref io_service_handler_exception + * @par Effect of exceptions thrown from handlers + * + * If an exception is thrown from a handler, the exception is allowed to + * propagate through the throwing thread's invocation of + * boost::asio::io_service::run(), boost::asio::io_service::run_one(), + * boost::asio::io_service::poll() or boost::asio::io_service::poll_one(). + * No other threads that are calling any of these functions are affected. It is + * then the responsibility of the application to catch the exception. + * + * After the exception has been caught, the + * boost::asio::io_service::run(), boost::asio::io_service::run_one(), + * boost::asio::io_service::poll() or boost::asio::io_service::poll_one() + * call may be restarted @em without the need for an intervening call to + * boost::asio::io_service::reset(). This allows the thread to rejoin the + * io_service's thread pool without impacting any other threads in the pool. + * + * For example: + * + * @code + * boost::asio::io_service io_service; + * ... + * for (;;) + * { + * try + * { + * io_service.run(); + * break; // run() exited normally + * } + * catch (my_exception& e) + * { + * // Deal with exception as appropriate. + * } + * } + * @endcode */ class io_service : private noncopyable @@ -461,42 +494,6 @@ public: } }; -/** - * @page io_service_handler_exception Effect of exceptions thrown from handlers - * - * If an exception is thrown from a handler, the exception is allowed to - * propagate through the throwing thread's invocation of - * boost::asio::io_service::run(), boost::asio::io_service::run_one(), - * boost::asio::io_service::poll() or boost::asio::io_service::poll_one(). - * No other threads that are calling any of these functions are affected. It is - * then the responsibility of the application to catch the exception. - * - * After the exception has been caught, the - * boost::asio::io_service::run(), boost::asio::io_service::run_one(), - * boost::asio::io_service::poll() or boost::asio::io_service::poll_one() - * call may be restarted @em without the need for an intervening call to - * boost::asio::io_service::reset(). This allows the thread to rejoin the - * io_service's thread pool without impacting any other threads in the pool. - * - * @par Example - * @code - * boost::asio::io_service io_service; - * ... - * for (;;) - * { - * try - * { - * io_service.run(); - * break; // run() exited normally - * } - * catch (my_exception& e) - * { - * // Deal with exception as appropriate. - * } - * } - * @endcode - */ - } // namespace asio } // namespace boost