diff --git a/asio/src/doc/reference.qbk b/asio/src/doc/reference.qbk index 09226b94de..9319fdbac6 100644 --- a/asio/src/doc/reference.qbk +++ b/asio/src/doc/reference.qbk @@ -38,6 +38,7 @@ [include requirements/IoControlCommand.qbk] [include requirements/IoObjectService.qbk] [include requirements/IteratorConnectHandler.qbk] +[include requirements/LegacyCompletionHandler.qbk] [include requirements/MoveAcceptHandler.qbk] [include requirements/MutableBufferSequence.qbk] [include requirements/ProtoAllocator.qbk] @@ -1380,7 +1381,7 @@ Start an asynchronous operation to read a certain amount of data from a stream. AsyncReadStream & s, DynamicBuffer && buffers, ReadHandler && handler, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.async_read.overload3 more...]]`` template< @@ -1393,7 +1394,7 @@ Start an asynchronous operation to read a certain amount of data from a stream. DynamicBuffer && buffers, CompletionCondition completion_condition, ReadHandler && handler, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.async_read.overload4 more...]]`` template< @@ -1607,7 +1608,7 @@ Start an asynchronous operation to read a certain amount of data from a stream. AsyncReadStream & s, DynamicBuffer && buffers, ReadHandler && handler, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true: @@ -1682,7 +1683,7 @@ Start an asynchronous operation to read a certain amount of data from a stream. DynamicBuffer && buffers, CompletionCondition completion_condition, ReadHandler && handler, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true: @@ -3692,7 +3693,7 @@ Start an asynchronous operation to write a certain amount of data to a stream. AsyncWriteStream & s, DynamicBuffer && buffers, WriteHandler && handler, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.async_write.overload3 more...]]`` template< @@ -3705,7 +3706,7 @@ Start an asynchronous operation to write a certain amount of data to a stream. DynamicBuffer && buffers, CompletionCondition completion_condition, WriteHandler && handler, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.async_write.overload4 more...]]`` template< @@ -3906,7 +3907,7 @@ Start an asynchronous operation to write all of the supplied data to a stream. AsyncWriteStream & s, DynamicBuffer && buffers, WriteHandler && handler, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to asynchronously write a certain number of bytes of data to a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true: @@ -3967,7 +3968,7 @@ Start an asynchronous operation to write a certain amount of data to a stream. DynamicBuffer && buffers, CompletionCondition completion_condition, WriteHandler && handler, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to asynchronously write a certain number of bytes of data to a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true: @@ -61667,9 +61668,9 @@ This function is implemented as follows: template< - typename ``[link asio.reference.CompletionHandler CompletionHandler]``> + typename ``[link asio.reference.LegacyCompletionHandler LegacyCompletionHandler]``> ``[link asio.reference.asynchronous_operations.automatic_deduction_of_initiating_function_return_type ['DEDUCED]]`` dispatch( - CompletionHandler && handler); + LegacyCompletionHandler && handler); This function is used to ask the [link asio.reference.io_context `io_context`] to execute the given handler. @@ -62148,9 +62149,9 @@ The number of handlers that were executed. template< - typename ``[link asio.reference.CompletionHandler CompletionHandler]``> + typename ``[link asio.reference.LegacyCompletionHandler LegacyCompletionHandler]``> ``[link asio.reference.asynchronous_operations.automatic_deduction_of_initiating_function_return_type ['DEDUCED]]`` post( - CompletionHandler && handler); + LegacyCompletionHandler && handler); This function is used to ask the [link asio.reference.io_context `io_context`] to execute the given handler, but without allowing the [link asio.reference.io_context `io_context`] to call the handler from inside this function. @@ -63482,9 +63483,9 @@ Request the strand to invoke the given function object. template< - typename ``[link asio.reference.CompletionHandler CompletionHandler]``> + typename ``[link asio.reference.LegacyCompletionHandler LegacyCompletionHandler]``> ``[link asio.reference.asynchronous_operations.automatic_deduction_of_initiating_function_return_type ['DEDUCED]]`` ``[link asio.reference.io_context__strand.dispatch.overload2 dispatch]``( - CompletionHandler && handler); + LegacyCompletionHandler && handler); `` [''''»''' [link asio.reference.io_context__strand.dispatch.overload2 more...]]`` @@ -63534,9 +63535,9 @@ This function is used to ask the strand to execute the given function object on template< - typename ``[link asio.reference.CompletionHandler CompletionHandler]``> + typename ``[link asio.reference.LegacyCompletionHandler LegacyCompletionHandler]``> ``[link asio.reference.asynchronous_operations.automatic_deduction_of_initiating_function_return_type ['DEDUCED]]`` dispatch( - CompletionHandler && handler); + LegacyCompletionHandler && handler); This function is used to ask the strand to execute the given handler. @@ -63712,9 +63713,9 @@ Request the strand to invoke the given function object. template< - typename ``[link asio.reference.CompletionHandler CompletionHandler]``> + typename ``[link asio.reference.LegacyCompletionHandler LegacyCompletionHandler]``> ``[link asio.reference.asynchronous_operations.automatic_deduction_of_initiating_function_return_type ['DEDUCED]]`` ``[link asio.reference.io_context__strand.post.overload2 post]``( - CompletionHandler && handler); + LegacyCompletionHandler && handler); `` [''''»''' [link asio.reference.io_context__strand.post.overload2 more...]]`` @@ -63764,9 +63765,9 @@ This function is used to ask the executor to execute the given function object. template< - typename ``[link asio.reference.CompletionHandler CompletionHandler]``> + typename ``[link asio.reference.LegacyCompletionHandler LegacyCompletionHandler]``> ``[link asio.reference.asynchronous_operations.automatic_deduction_of_initiating_function_return_type ['DEDUCED]]`` post( - CompletionHandler && handler); + LegacyCompletionHandler && handler); This function is used to ask the strand to execute the given handler, but without allowing the strand to call the handler from inside this function. @@ -76702,7 +76703,7 @@ Swap the results range with another. The type of a value in the results range. - typedef basic_resolver_entry< endpoint_type > value_type; + typedef basic_resolver_entry< protocol_type > value_type; [heading Types] @@ -90427,7 +90428,7 @@ Attempt to read a certain amount of data from a stream before returning. std::size_t ``[link asio.reference.read.overload5 read]``( SyncReadStream & s, DynamicBuffer && buffers, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.read.overload5 more...]]`` template< @@ -90437,7 +90438,7 @@ Attempt to read a certain amount of data from a stream before returning. SyncReadStream & s, DynamicBuffer && buffers, asio::error_code & ec, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.read.overload6 more...]]`` template< @@ -90448,7 +90449,7 @@ Attempt to read a certain amount of data from a stream before returning. SyncReadStream & s, DynamicBuffer && buffers, CompletionCondition completion_condition, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.read.overload7 more...]]`` template< @@ -90460,7 +90461,7 @@ Attempt to read a certain amount of data from a stream before returning. DynamicBuffer && buffers, CompletionCondition completion_condition, asio::error_code & ec, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.read.overload8 more...]]`` template< @@ -90825,7 +90826,7 @@ Attempt to read a certain amount of data from a stream before returning. std::size_t read( SyncReadStream & s, DynamicBuffer && buffers, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to read a certain number of bytes of data from a stream. The call will block until one of the following conditions is true: @@ -90897,7 +90898,7 @@ Attempt to read a certain amount of data from a stream before returning. SyncReadStream & s, DynamicBuffer && buffers, asio::error_code & ec, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to read a certain number of bytes of data from a stream. The call will block until one of the following conditions is true: @@ -90962,7 +90963,7 @@ Attempt to read a certain amount of data from a stream before returning. SyncReadStream & s, DynamicBuffer && buffers, CompletionCondition completion_condition, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to read a certain number of bytes of data from a stream. The call will block until one of the following conditions is true: @@ -91036,7 +91037,7 @@ Attempt to read a certain amount of data from a stream before returning. DynamicBuffer && buffers, CompletionCondition completion_condition, asio::error_code & ec, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to read a certain number of bytes of data from a stream. The call will block until one of the following conditions is true: @@ -113214,7 +113215,7 @@ Write a certain amount of data to a stream before returning. std::size_t ``[link asio.reference.write.overload5 write]``( SyncWriteStream & s, DynamicBuffer && buffers, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.write.overload5 more...]]`` template< @@ -113224,7 +113225,7 @@ Write a certain amount of data to a stream before returning. SyncWriteStream & s, DynamicBuffer && buffers, asio::error_code & ec, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.write.overload6 more...]]`` template< @@ -113235,7 +113236,7 @@ Write a certain amount of data to a stream before returning. SyncWriteStream & s, DynamicBuffer && buffers, CompletionCondition completion_condition, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.write.overload7 more...]]`` template< @@ -113247,7 +113248,7 @@ Write a certain amount of data to a stream before returning. DynamicBuffer && buffers, CompletionCondition completion_condition, asio::error_code & ec, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); `` [''''»''' [link asio.reference.write.overload8 more...]]`` template< @@ -113612,7 +113613,7 @@ Write all of the supplied data to a stream before returning. std::size_t write( SyncWriteStream & s, DynamicBuffer && buffers, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to write a certain number of bytes of data to a stream. The call will block until one of the following conditions is true: @@ -113684,7 +113685,7 @@ Write all of the supplied data to a stream before returning. SyncWriteStream & s, DynamicBuffer && buffers, asio::error_code & ec, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to write a certain number of bytes of data to a stream. The call will block until one of the following conditions is true: @@ -113749,7 +113750,7 @@ Write a certain amount of data to a stream before returning. SyncWriteStream & s, DynamicBuffer && buffers, CompletionCondition completion_condition, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to write a certain number of bytes of data to a stream. The call will block until one of the following conditions is true: @@ -113823,7 +113824,7 @@ Write a certain amount of data to a stream before returning. DynamicBuffer && buffers, CompletionCondition completion_condition, asio::error_code & ec, - typename enable_if< is_dynamic_buffer< DynamicBuffer >::value >::type * = 0); + typename enable_if< is_dynamic_buffer< typename decay< DynamicBuffer >::type >::value >::type * = 0); This function is used to write a certain number of bytes of data to a stream. The call will block until one of the following conditions is true: diff --git a/asio/src/doc/tutorial.qbk b/asio/src/doc/tutorial.qbk index d7707bceed..a7dcad7960 100644 --- a/asio/src/doc/tutorial.qbk +++ b/asio/src/doc/tutorial.qbk @@ -81,13 +81,6 @@ All of the asio classes can be used by simply including the `"asio.hpp"` header -Since this example uses timers, we need to include the appropriate Boost.Date\_Time header file for manipulating times. - - - ``''''''``#include - - - All programs that use asio need to have at least one [link asio.reference.io_context io_context] object. This class provides access to I/O functionality. We declare an object of this type first thing in the main function. @@ -99,17 +92,17 @@ All programs that use asio need to have at least one -Next we declare an object of type asio::deadline\_timer. The core asio classes that provide I/O functionality (or as in this case timer functionality) always take a reference to an io\_context as their first constructor argument. The second argument to the constructor sets the timer to expire 5 seconds from now. +Next we declare an object of type asio::steady\_timer. The core asio classes that provide I/O functionality (or as in this case timer functionality) always take a reference to an io\_context as their first constructor argument. The second argument to the constructor sets the timer to expire 5 seconds from now. - ``''''''`` asio::deadline_timer t(io, boost::posix_time::seconds(5)); + ``''''''`` asio::steady_timer t(io, asio::chrono::seconds(5)); -In this simple example we perform a blocking wait on the timer. That is, the call to [link asio.reference.basic_deadline_timer.wait deadline_timer::wait()] will not return until the timer has expired, 5 seconds after it was created (i.e. not from when the wait starts). +In this simple example we perform a blocking wait on the timer. That is, the call to [link asio.reference.basic_waitable_timer.wait steady_timer::wait()] will not return until the timer has expired, 5 seconds after it was created (i.e. not from when the wait starts). -A deadline timer is always in one of two states: "expired" or "not expired". If the [link asio.reference.basic_deadline_timer.wait deadline_timer::wait()] function is called on an expired timer, it will return immediately. +A timer is always in one of two states: "expired" or "not expired". If the [link asio.reference.basic_waitable_timer.wait steady_timer::wait()] function is called on an expired timer, it will return immediately. ``''''''`` t.wait(); @@ -150,13 +143,12 @@ Next: [link asio.tutorial.tuttimer2 Timer.2 - Using a timer asynchronously] ``''''''``#include ``''''''``#include - ``''''''``#include ``''''''``int main() ``''''''``{ ``''''''`` asio::io_context io; - ``''''''`` asio::deadline_timer t(io, boost::posix_time::seconds(5)); + ``''''''`` asio::steady_timer t(io, asio::chrono::seconds(5)); ``''''''`` t.wait(); ``''''''`` std::cout << "Hello, world!" << std::endl; @@ -181,7 +173,6 @@ This tutorial program demonstrates how to use asio's asynchronous callback funct ``''''''``#include ``''''''``#include - ``''''''``#include @@ -198,11 +189,11 @@ Using asio's asynchronous functionality means having a callback function that wi ``''''''``{ ``''''''`` asio::io_context io; - ``''''''`` asio::deadline_timer t(io, boost::posix_time::seconds(5)); + ``''''''`` asio::steady_timer t(io, asio::chrono::seconds(5)); -Next, instead of doing a blocking wait as in tutorial Timer.1, we call the [link asio.reference.basic_deadline_timer.async_wait deadline_timer::async_wait()] function to perform an asynchronous wait. When calling this function we pass the `print` callback handler that was defined above. +Next, instead of doing a blocking wait as in tutorial Timer.1, we call the [link asio.reference.basic_waitable_timer.async_wait steady_timer::async_wait()] function to perform an asynchronous wait. When calling this function we pass the `print` callback handler that was defined above. ``''''''`` t.async_wait(&print); @@ -215,7 +206,7 @@ The asio library provides a guarantee that callback handlers will only be called The [link asio.reference.io_context.run io_context::run()] function will also continue to run while there is still "work" to do. In this example, the work is the asynchronous wait on the timer, so the call will not return until the timer has expired and the callback has completed. -It is important to remember to give the io\_context some work to do before calling [link asio.reference.io_context.run io_context::run()]. For example, if we had omitted the above call to [link asio.reference.basic_deadline_timer.async_wait deadline_timer::async_wait()], the io\_context would not have had any work to do, and consequently [link asio.reference.io_context.run io_context::run()] would have returned immediately. +It is important to remember to give the io\_context some work to do before calling [link asio.reference.io_context.run io_context::run()]. For example, if we had omitted the above call to [link asio.reference.basic_waitable_timer.async_wait steady_timer::async_wait()], the io\_context would not have had any work to do, and consequently [link asio.reference.io_context.run io_context::run()] would have returned immediately. ``''''''`` io.run(); @@ -250,7 +241,6 @@ Next: [link asio.tutorial.tuttimer3 Timer.3 - Binding arguments to a handler] ``''''''``#include ``''''''``#include - ``''''''``#include ``''''''``void print(const asio::error_code& /*e*/) ``''''''``{ @@ -261,7 +251,7 @@ Next: [link asio.tutorial.tuttimer3 Timer.3 - Binding arguments to a handler] ``''''''``{ ``''''''`` asio::io_context io; - ``''''''`` asio::deadline_timer t(io, boost::posix_time::seconds(5)); + ``''''''`` asio::steady_timer t(io, asio::chrono::seconds(5)); ``''''''`` t.async_wait(&print); ``''''''`` io.run(); @@ -287,7 +277,6 @@ In this tutorial we will modify the program from tutorial Timer.2 so that the ti ``''''''``#include ``''''''``#include ``''''''``#include - ``''''''``#include @@ -302,7 +291,7 @@ To implement a repeating timer using asio you need to change the timer's expiry ``''''''``void print(const asio::error_code& /*e*/, - ``''''''`` asio::deadline_timer* t, int* count) + ``''''''`` asio::steady_timer* t, int* count) ``''''''``{ @@ -321,11 +310,11 @@ Next we move the expiry time for the timer along by one second from the previous - ``''''''`` t->expires_at(t->expires_at() + boost::posix_time::seconds(1)); + ``''''''`` t->expires_at(t->expiry() + asio::chrono::seconds(1)); -Then we start a new asynchronous wait on the timer. As you can see, the [link asio.tutorial.boost_bind boost::bind] function is used to associate the extra parameters with your callback handler. The [link asio.reference.basic_deadline_timer.async_wait deadline_timer::async_wait()] function expects a handler function (or function object) with the signature `void(const asio::error_code&)`. Binding the additional parameters converts your `print` function into a function object that matches the signature correctly. +Then we start a new asynchronous wait on the timer. As you can see, the [link asio.tutorial.boost_bind boost::bind] function is used to associate the extra parameters with your callback handler. The [link asio.reference.basic_waitable_timer.async_wait steady_timer::async_wait()] function expects a handler function (or function object) with the signature `void(const asio::error_code&)`. Binding the additional parameters converts your `print` function into a function object that matches the signature correctly. See the [@http://www.boost.org/libs/bind/bind.html Boost.Bind documentation] for more information on how to use [link asio.tutorial.boost_bind boost::bind] . @@ -348,11 +337,11 @@ A new `count` variable is added so that we can stop the program when the timer f ``''''''`` int count = 0; - ``''''''`` asio::deadline_timer t(io, boost::posix_time::seconds(1)); + ``''''''`` asio::steady_timer t(io, asio::chrono::seconds(1)); -As in Step 4, when making the call to [link asio.reference.basic_deadline_timer.async_wait deadline_timer::async_wait()] from `main` we bind the additional parameters needed for the `print` function. +As in Step 4, when making the call to [link asio.reference.basic_waitable_timer.async_wait steady_timer::async_wait()] from `main` we bind the additional parameters needed for the `print` function. ``''''''`` t.async_wait(boost::bind(print, @@ -399,17 +388,16 @@ Next: [link asio.tutorial.tuttimer4 Timer.4 - Using a member function as a handl ``''''''``#include ``''''''``#include ``''''''``#include - ``''''''``#include ``''''''``void print(const asio::error_code& /*e*/, - ``''''''`` asio::deadline_timer* t, int* count) + ``''''''`` asio::steady_timer* t, int* count) ``''''''``{ ``''''''`` if (*count < 5) ``''''''`` { ``''''''`` std::cout << *count << std::endl; ``''''''`` ++(*count); - ``''''''`` t->expires_at(t->expires_at() + boost::posix_time::seconds(1)); + ``''''''`` t->expires_at(t->expiry() + asio::chrono::seconds(1)); ``''''''`` t->async_wait(boost::bind(print, ``''''''`` asio::placeholders::error, t, count)); ``''''''`` } @@ -420,7 +408,7 @@ Next: [link asio.tutorial.tuttimer4 Timer.4 - Using a member function as a handl ``''''''`` asio::io_context io; ``''''''`` int count = 0; - ``''''''`` asio::deadline_timer t(io, boost::posix_time::seconds(1)); + ``''''''`` asio::steady_timer t(io, asio::chrono::seconds(1)); ``''''''`` t.async_wait(boost::bind(print, ``''''''`` asio::placeholders::error, &t, &count)); @@ -449,7 +437,6 @@ In this tutorial we will see how to use a class member function as a callback ha ``''''''``#include ``''''''``#include ``''''''``#include - ``''''''``#include @@ -467,7 +454,7 @@ The constructor of this class will take a reference to the io\_context object an ``''''''`` printer(asio::io_context& io) - ``''''''`` : timer_(io, boost::posix_time::seconds(1)), + ``''''''`` : timer_(io, asio::chrono::seconds(1)), ``''''''`` count_(0) ``''''''`` { @@ -505,13 +492,13 @@ The `print` member function is very similar to the `print` function from tutoria ``''''''`` std::cout << count_ << std::endl; ``''''''`` ++count_; - ``''''''`` timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(1)); + ``''''''`` timer_.expires_at(timer_.expiry() + asio::chrono::seconds(1)); ``''''''`` timer_.async_wait(boost::bind(&printer::print, this)); ``''''''`` } ``''''''`` } ``''''''``private: - ``''''''`` asio::deadline_timer timer_; + ``''''''`` asio::steady_timer timer_; ``''''''`` int count_; ``''''''``}; @@ -560,13 +547,12 @@ Next: [link asio.tutorial.tuttimer5 Timer.5 - Synchronising handlers in multithr ``''''''``#include ``''''''``#include ``''''''``#include - ``''''''``#include ``''''''``class printer ``''''''``{ ``''''''``public: ``''''''`` printer(asio::io_context& io) - ``''''''`` : timer_(io, boost::posix_time::seconds(1)), + ``''''''`` : timer_(io, asio::chrono::seconds(1)), ``''''''`` count_(0) ``''''''`` { ``''''''`` timer_.async_wait(boost::bind(&printer::print, this)); @@ -584,13 +570,13 @@ Next: [link asio.tutorial.tuttimer5 Timer.5 - Synchronising handlers in multithr ``''''''`` std::cout << count_ << std::endl; ``''''''`` ++count_; - ``''''''`` timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(1)); + ``''''''`` timer_.expires_at(timer_.expiry() + asio::chrono::seconds(1)); ``''''''`` timer_.async_wait(boost::bind(&printer::print, this)); ``''''''`` } ``''''''`` } ``''''''``private: - ``''''''`` asio::deadline_timer timer_; + ``''''''`` asio::steady_timer timer_; ``''''''`` int count_; ``''''''``}; @@ -636,7 +622,6 @@ If you find yourself running into these limitations, an alternative approach is ``''''''``#include ``''''''``#include ``''''''``#include - ``''''''``#include @@ -650,7 +635,7 @@ We start by defining a class called `printer`, similar to the class in the previ -In addition to initialising a pair of asio::deadline\_timer members, the constructor initialises the `strand_` member, an object of type +In addition to initialising a pair of asio::steady\_timer members, the constructor initialises the `strand_` member, an object of type [link asio.reference.io_context__strand io_context::strand]. An @@ -661,8 +646,8 @@ An ``''''''`` printer(asio::io_context& io) ``''''''`` : strand_(io), - ``''''''`` timer1_(io, boost::posix_time::seconds(1)), - ``''''''`` timer2_(io, boost::posix_time::seconds(1)), + ``''''''`` timer1_(io, asio::chrono::seconds(1)), + ``''''''`` timer2_(io, asio::chrono::seconds(1)), ``''''''`` count_(0) ``''''''`` { @@ -699,7 +684,7 @@ In a multithreaded program, the handlers for asynchronous operations should be s ``''''''`` std::cout << "Timer 1: " << count_ << std::endl; ``''''''`` ++count_; - ``''''''`` timer1_.expires_at(timer1_.expires_at() + boost::posix_time::seconds(1)); + ``''''''`` timer1_.expires_at(timer1_.expiry() + asio::chrono::seconds(1)); ``''''''`` timer1_.async_wait(asio::bind_executor(strand_, ``''''''`` boost::bind(&printer::print1, this))); @@ -713,7 +698,7 @@ In a multithreaded program, the handlers for asynchronous operations should be s ``''''''`` std::cout << "Timer 2: " << count_ << std::endl; ``''''''`` ++count_; - ``''''''`` timer2_.expires_at(timer2_.expires_at() + boost::posix_time::seconds(1)); + ``''''''`` timer2_.expires_at(timer2_.expiry() + asio::chrono::seconds(1)); ``''''''`` timer2_.async_wait(asio::bind_executor(strand_, ``''''''`` boost::bind(&printer::print2, this))); @@ -722,8 +707,8 @@ In a multithreaded program, the handlers for asynchronous operations should be s ``''''''``private: ``''''''`` asio::io_context::strand strand_; - ``''''''`` asio::deadline_timer timer1_; - ``''''''`` asio::deadline_timer timer2_; + ``''''''`` asio::steady_timer timer1_; + ``''''''`` asio::steady_timer timer2_; ``''''''`` int count_; ``''''''``}; @@ -775,15 +760,14 @@ Previous: [link asio.tutorial.tuttimer4 Timer.4 - Using a member function as a h ``''''''``#include ``''''''``#include ``''''''``#include - ``''''''``#include ``''''''``class printer ``''''''``{ ``''''''``public: ``''''''`` printer(asio::io_context& io) ``''''''`` : strand_(io), - ``''''''`` timer1_(io, boost::posix_time::seconds(1)), - ``''''''`` timer2_(io, boost::posix_time::seconds(1)), + ``''''''`` timer1_(io, asio::chrono::seconds(1)), + ``''''''`` timer2_(io, asio::chrono::seconds(1)), ``''''''`` count_(0) ``''''''`` { ``''''''`` timer1_.async_wait(asio::bind_executor(strand_, @@ -805,7 +789,7 @@ Previous: [link asio.tutorial.tuttimer4 Timer.4 - Using a member function as a h ``''''''`` std::cout << "Timer 1: " << count_ << std::endl; ``''''''`` ++count_; - ``''''''`` timer1_.expires_at(timer1_.expires_at() + boost::posix_time::seconds(1)); + ``''''''`` timer1_.expires_at(timer1_.expiry() + asio::chrono::seconds(1)); ``''''''`` timer1_.async_wait(asio::bind_executor(strand_, ``''''''`` boost::bind(&printer::print1, this))); @@ -819,7 +803,7 @@ Previous: [link asio.tutorial.tuttimer4 Timer.4 - Using a member function as a h ``''''''`` std::cout << "Timer 2: " << count_ << std::endl; ``''''''`` ++count_; - ``''''''`` timer2_.expires_at(timer2_.expires_at() + boost::posix_time::seconds(1)); + ``''''''`` timer2_.expires_at(timer2_.expiry() + asio::chrono::seconds(1)); ``''''''`` timer2_.async_wait(asio::bind_executor(strand_, ``''''''`` boost::bind(&printer::print2, this))); @@ -828,8 +812,8 @@ Previous: [link asio.tutorial.tuttimer4 Timer.4 - Using a member function as a h ``''''''``private: ``''''''`` asio::io_context::strand strand_; - ``''''''`` asio::deadline_timer timer1_; - ``''''''`` asio::deadline_timer timer2_; + ``''''''`` asio::steady_timer timer1_; + ``''''''`` asio::steady_timer timer2_; ``''''''`` int count_; ``''''''``};