summaryrefslogtreecommitdiff
path: root/boost/asio/basic_deadline_timer.hpp
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2019-12-05 15:11:01 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2019-12-05 15:11:01 +0900
commit3fdc3e5ee96dca5b11d1694975a65200787eab86 (patch)
tree5c1733853892b8397d67706fa453a9bd978d2102 /boost/asio/basic_deadline_timer.hpp
parent88e602c57797660ebe0f9e15dbd64c1ff16dead3 (diff)
downloadboost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.gz
boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.bz2
boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.zip
Imported Upstream version 1.66.0upstream/1.66.0
Diffstat (limited to 'boost/asio/basic_deadline_timer.hpp')
-rw-r--r--boost/asio/basic_deadline_timer.hpp178
1 files changed, 144 insertions, 34 deletions
diff --git a/boost/asio/basic_deadline_timer.hpp b/boost/asio/basic_deadline_timer.hpp
index 930370046b..f7179a853e 100644
--- a/boost/asio/basic_deadline_timer.hpp
+++ b/boost/asio/basic_deadline_timer.hpp
@@ -22,10 +22,17 @@
#include <cstddef>
#include <boost/asio/basic_io_object.hpp>
-#include <boost/asio/deadline_timer_service.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
+#include <boost/asio/time_traits.hpp>
+
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+# include <boost/asio/deadline_timer_service.hpp>
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+# include <boost/asio/detail/deadline_timer_service.hpp>
+# define BOOST_ASIO_SVC_T detail::deadline_timer_service<TimeTraits>
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
#include <boost/asio/detail/push_options.hpp>
@@ -51,7 +58,7 @@ namespace asio {
* Performing a blocking wait:
* @code
* // Construct a timer without setting an expiry time.
- * boost::asio::deadline_timer timer(io_service);
+ * boost::asio::deadline_timer timer(io_context);
*
* // Set an expiry time relative to now.
* timer.expires_from_now(boost::posix_time::seconds(5));
@@ -74,7 +81,7 @@ namespace asio {
* ...
*
* // Construct a timer with an absolute expiry time.
- * boost::asio::deadline_timer timer(io_service,
+ * boost::asio::deadline_timer timer(io_context,
* boost::posix_time::time_from_string("2005-12-07 23:59:59.000"));
*
* // Start an asynchronous wait.
@@ -121,12 +128,15 @@ namespace asio {
* it contains the value boost::asio::error::operation_aborted.
*/
template <typename Time,
- typename TimeTraits = boost::asio::time_traits<Time>,
- typename TimerService = deadline_timer_service<Time, TimeTraits> >
+ typename TimeTraits = boost::asio::time_traits<Time>
+ BOOST_ASIO_SVC_TPARAM_DEF2(= deadline_timer_service<Time, TimeTraits>)>
class basic_deadline_timer
- : public basic_io_object<TimerService>
+ : BOOST_ASIO_SVC_ACCESS basic_io_object<BOOST_ASIO_SVC_T>
{
public:
+ /// The type of the executor associated with the object.
+ typedef io_context::executor_type executor_type;
+
/// The time traits type.
typedef TimeTraits traits_type;
@@ -142,11 +152,11 @@ public:
* expires_at() or expires_from_now() functions must be called to set an
* expiry time before the timer can be waited on.
*
- * @param io_service The io_service object that the timer will use to dispatch
+ * @param io_context The io_context object that the timer will use to dispatch
* handlers for any asynchronous operations performed on the timer.
*/
- explicit basic_deadline_timer(boost::asio::io_service& io_service)
- : basic_io_object<TimerService>(io_service)
+ explicit basic_deadline_timer(boost::asio::io_context& io_context)
+ : basic_io_object<BOOST_ASIO_SVC_T>(io_context)
{
}
@@ -154,18 +164,18 @@ public:
/**
* This constructor creates a timer and sets the expiry time.
*
- * @param io_service The io_service object that the timer will use to dispatch
+ * @param io_context The io_context object that the timer will use to dispatch
* handlers for any asynchronous operations performed on the timer.
*
* @param expiry_time The expiry time to be used for the timer, expressed
* as an absolute time.
*/
- basic_deadline_timer(boost::asio::io_service& io_service,
+ basic_deadline_timer(boost::asio::io_context& io_context,
const time_type& expiry_time)
- : basic_io_object<TimerService>(io_service)
+ : basic_io_object<BOOST_ASIO_SVC_T>(io_context)
{
boost::system::error_code ec;
- this->service.expires_at(this->implementation, expiry_time, ec);
+ this->get_service().expires_at(this->get_implementation(), expiry_time, ec);
boost::asio::detail::throw_error(ec, "expires_at");
}
@@ -173,21 +183,105 @@ public:
/**
* This constructor creates a timer and sets the expiry time.
*
- * @param io_service The io_service object that the timer will use to dispatch
+ * @param io_context The io_context object that the timer will use to dispatch
* handlers for any asynchronous operations performed on the timer.
*
* @param expiry_time The expiry time to be used for the timer, relative to
* now.
*/
- basic_deadline_timer(boost::asio::io_service& io_service,
+ basic_deadline_timer(boost::asio::io_context& io_context,
const duration_type& expiry_time)
- : basic_io_object<TimerService>(io_service)
+ : basic_io_object<BOOST_ASIO_SVC_T>(io_context)
{
boost::system::error_code ec;
- this->service.expires_from_now(this->implementation, expiry_time, ec);
+ this->get_service().expires_from_now(
+ this->get_implementation(), expiry_time, ec);
boost::asio::detail::throw_error(ec, "expires_from_now");
}
+#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
+ /// Move-construct a basic_deadline_timer from another.
+ /**
+ * This constructor moves a timer from one object to another.
+ *
+ * @param other The other basic_deadline_timer object from which the move will
+ * occur.
+ *
+ * @note Following the move, the moved-from object is in the same state as if
+ * constructed using the @c basic_deadline_timer(io_context&) constructor.
+ */
+ basic_deadline_timer(basic_deadline_timer&& other)
+ : basic_io_object<BOOST_ASIO_SVC_T>(std::move(other))
+ {
+ }
+
+ /// Move-assign a basic_deadline_timer from another.
+ /**
+ * This assignment operator moves a timer from one object to another. Cancels
+ * any outstanding asynchronous operations associated with the target object.
+ *
+ * @param other The other basic_deadline_timer object from which the move will
+ * occur.
+ *
+ * @note Following the move, the moved-from object is in the same state as if
+ * constructed using the @c basic_deadline_timer(io_context&) constructor.
+ */
+ basic_deadline_timer& operator=(basic_deadline_timer&& other)
+ {
+ basic_io_object<BOOST_ASIO_SVC_T>::operator=(std::move(other));
+ return *this;
+ }
+#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
+
+ /// Destroys the timer.
+ /**
+ * This function destroys the timer, cancelling any outstanding asynchronous
+ * wait operations associated with the timer as if by calling @c cancel.
+ */
+ ~basic_deadline_timer()
+ {
+ }
+
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ // These functions are provided by basic_io_object<>.
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+#if !defined(BOOST_ASIO_NO_DEPRECATED)
+ /// (Deprecated: Use get_executor().) Get the io_context associated with the
+ /// object.
+ /**
+ * This function may be used to obtain the io_context object that the I/O
+ * object uses to dispatch handlers for asynchronous operations.
+ *
+ * @return A reference to the io_context object that the I/O object will use
+ * to dispatch handlers. Ownership is not transferred to the caller.
+ */
+ boost::asio::io_context& get_io_context()
+ {
+ return basic_io_object<BOOST_ASIO_SVC_T>::get_io_context();
+ }
+
+ /// (Deprecated: Use get_executor().) Get the io_context associated with the
+ /// object.
+ /**
+ * This function may be used to obtain the io_context object that the I/O
+ * object uses to dispatch handlers for asynchronous operations.
+ *
+ * @return A reference to the io_context object that the I/O object will use
+ * to dispatch handlers. Ownership is not transferred to the caller.
+ */
+ boost::asio::io_context& get_io_service()
+ {
+ return basic_io_object<BOOST_ASIO_SVC_T>::get_io_service();
+ }
+#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
+
+ /// Get the executor associated with the object.
+ executor_type get_executor() BOOST_ASIO_NOEXCEPT
+ {
+ return basic_io_object<BOOST_ASIO_SVC_T>::get_executor();
+ }
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+
/// Cancel any asynchronous operations that are waiting on the timer.
/**
* This function forces the completion of any pending asynchronous wait
@@ -213,7 +307,7 @@ public:
std::size_t cancel()
{
boost::system::error_code ec;
- std::size_t s = this->service.cancel(this->implementation, ec);
+ std::size_t s = this->get_service().cancel(this->get_implementation(), ec);
boost::asio::detail::throw_error(ec, "cancel");
return s;
}
@@ -242,7 +336,7 @@ public:
*/
std::size_t cancel(boost::system::error_code& ec)
{
- return this->service.cancel(this->implementation, ec);
+ return this->get_service().cancel(this->get_implementation(), ec);
}
/// Cancels one asynchronous operation that is waiting on the timer.
@@ -272,7 +366,8 @@ public:
std::size_t cancel_one()
{
boost::system::error_code ec;
- std::size_t s = this->service.cancel_one(this->implementation, ec);
+ std::size_t s = this->get_service().cancel_one(
+ this->get_implementation(), ec);
boost::asio::detail::throw_error(ec, "cancel_one");
return s;
}
@@ -303,7 +398,7 @@ public:
*/
std::size_t cancel_one(boost::system::error_code& ec)
{
- return this->service.cancel_one(this->implementation, ec);
+ return this->get_service().cancel_one(this->get_implementation(), ec);
}
/// Get the timer's expiry time as an absolute time.
@@ -313,7 +408,7 @@ public:
*/
time_type expires_at() const
{
- return this->service.expires_at(this->implementation);
+ return this->get_service().expires_at(this->get_implementation());
}
/// Set the timer's expiry time as an absolute time.
@@ -341,8 +436,8 @@ public:
std::size_t expires_at(const time_type& expiry_time)
{
boost::system::error_code ec;
- std::size_t s = this->service.expires_at(
- this->implementation, expiry_time, ec);
+ std::size_t s = this->get_service().expires_at(
+ this->get_implementation(), expiry_time, ec);
boost::asio::detail::throw_error(ec, "expires_at");
return s;
}
@@ -372,7 +467,8 @@ public:
std::size_t expires_at(const time_type& expiry_time,
boost::system::error_code& ec)
{
- return this->service.expires_at(this->implementation, expiry_time, ec);
+ return this->get_service().expires_at(
+ this->get_implementation(), expiry_time, ec);
}
/// Get the timer's expiry time relative to now.
@@ -382,7 +478,7 @@ public:
*/
duration_type expires_from_now() const
{
- return this->service.expires_from_now(this->implementation);
+ return this->get_service().expires_from_now(this->get_implementation());
}
/// Set the timer's expiry time relative to now.
@@ -410,8 +506,8 @@ public:
std::size_t expires_from_now(const duration_type& expiry_time)
{
boost::system::error_code ec;
- std::size_t s = this->service.expires_from_now(
- this->implementation, expiry_time, ec);
+ std::size_t s = this->get_service().expires_from_now(
+ this->get_implementation(), expiry_time, ec);
boost::asio::detail::throw_error(ec, "expires_from_now");
return s;
}
@@ -441,8 +537,8 @@ public:
std::size_t expires_from_now(const duration_type& expiry_time,
boost::system::error_code& ec)
{
- return this->service.expires_from_now(
- this->implementation, expiry_time, ec);
+ return this->get_service().expires_from_now(
+ this->get_implementation(), expiry_time, ec);
}
/// Perform a blocking wait on the timer.
@@ -455,7 +551,7 @@ public:
void wait()
{
boost::system::error_code ec;
- this->service.wait(this->implementation, ec);
+ this->get_service().wait(this->get_implementation(), ec);
boost::asio::detail::throw_error(ec, "wait");
}
@@ -468,7 +564,7 @@ public:
*/
void wait(boost::system::error_code& ec)
{
- this->service.wait(this->implementation, ec);
+ this->get_service().wait(this->get_implementation(), ec);
}
/// Start an asynchronous wait on the timer.
@@ -493,7 +589,7 @@ public:
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
* of the handler will be performed in a manner equivalent to using
- * boost::asio::io_service::post().
+ * boost::asio::io_context::post().
*/
template <typename WaitHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
@@ -504,8 +600,18 @@ public:
// not meet the documented type requirements for a WaitHandler.
BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
- return this->service.async_wait(this->implementation,
+#if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ return this->get_service().async_wait(this->get_implementation(),
BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
+#else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+ async_completion<WaitHandler,
+ void (boost::system::error_code)> init(handler);
+
+ this->get_service().async_wait(this->get_implementation(),
+ init.completion_handler);
+
+ return init.result.get();
+#endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
}
};
@@ -514,6 +620,10 @@ public:
#include <boost/asio/detail/pop_options.hpp>
+#if !defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+# undef BOOST_ASIO_SVC_T
+#endif // !defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
+
#endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
// || defined(GENERATING_DOCUMENTATION)