fix doc example typo
[boost.git] / boost / asio / deadline_timer_service.hpp
blobdccd1394ac18307263420f2b3532fb0e4b4a3fff
1 //
2 // deadline_timer_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
11 #ifndef BOOST_ASIO_DEADLINE_TIMER_SERVICE_HPP
12 #define BOOST_ASIO_DEADLINE_TIMER_SERVICE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/push_options.hpp>
20 #include <boost/asio/detail/push_options.hpp>
21 #include <cstddef>
22 #include <boost/config.hpp>
23 #include <boost/asio/detail/pop_options.hpp>
25 #include <boost/asio/io_service.hpp>
26 #include <boost/asio/time_traits.hpp>
27 #include <boost/asio/detail/deadline_timer_service.hpp>
28 #include <boost/asio/detail/epoll_reactor.hpp>
29 #include <boost/asio/detail/kqueue_reactor.hpp>
30 #include <boost/asio/detail/select_reactor.hpp>
31 #include <boost/asio/detail/service_base.hpp>
32 #include <boost/asio/detail/win_iocp_io_service.hpp>
34 namespace boost {
35 namespace asio {
37 /// Default service implementation for a timer.
38 template <typename TimeType,
39 typename TimeTraits = boost::asio::time_traits<TimeType> >
40 class deadline_timer_service
41 #if defined(GENERATING_DOCUMENTATION)
42 : public boost::asio::io_service::service
43 #else
44 : public boost::asio::detail::service_base<
45 deadline_timer_service<TimeType, TimeTraits> >
46 #endif
48 public:
49 #if defined(GENERATING_DOCUMENTATION)
50 /// The unique service identifier.
51 static boost::asio::io_service::id id;
52 #endif
54 /// The time traits type.
55 typedef TimeTraits traits_type;
57 /// The time type.
58 typedef typename traits_type::time_type time_type;
60 /// The duration type.
61 typedef typename traits_type::duration_type duration_type;
63 private:
64 // The type of the platform-specific implementation.
65 #if defined(BOOST_ASIO_HAS_IOCP)
66 typedef detail::deadline_timer_service<
67 traits_type, detail::win_iocp_io_service> service_impl_type;
68 #elif defined(BOOST_ASIO_HAS_EPOLL)
69 typedef detail::deadline_timer_service<
70 traits_type, detail::epoll_reactor<false> > service_impl_type;
71 #elif defined(BOOST_ASIO_HAS_KQUEUE)
72 typedef detail::deadline_timer_service<
73 traits_type, detail::kqueue_reactor<false> > service_impl_type;
74 #elif defined(BOOST_ASIO_HAS_DEV_POLL)
75 typedef detail::deadline_timer_service<
76 traits_type, detail::dev_poll_reactor<false> > service_impl_type;
77 #else
78 typedef detail::deadline_timer_service<
79 traits_type, detail::select_reactor<false> > service_impl_type;
80 #endif
82 public:
83 /// The implementation type of the deadline timer.
84 #if defined(GENERATING_DOCUMENTATION)
85 typedef implementation_defined implementation_type;
86 #else
87 typedef typename service_impl_type::implementation_type implementation_type;
88 #endif
90 /// Construct a new timer service for the specified io_service.
91 explicit deadline_timer_service(boost::asio::io_service& io_service)
92 : boost::asio::detail::service_base<
93 deadline_timer_service<TimeType, TimeTraits> >(io_service),
94 service_impl_(boost::asio::use_service<service_impl_type>(io_service))
98 /// Destroy all user-defined handler objects owned by the service.
99 void shutdown_service()
103 /// Construct a new timer implementation.
104 void construct(implementation_type& impl)
106 service_impl_.construct(impl);
109 /// Destroy a timer implementation.
110 void destroy(implementation_type& impl)
112 service_impl_.destroy(impl);
115 /// Cancel any asynchronous wait operations associated with the timer.
116 std::size_t cancel(implementation_type& impl, boost::system::error_code& ec)
118 return service_impl_.cancel(impl, ec);
121 /// Get the expiry time for the timer as an absolute time.
122 time_type expires_at(const implementation_type& impl) const
124 return service_impl_.expires_at(impl);
127 /// Set the expiry time for the timer as an absolute time.
128 std::size_t expires_at(implementation_type& impl,
129 const time_type& expiry_time, boost::system::error_code& ec)
131 return service_impl_.expires_at(impl, expiry_time, ec);
134 /// Get the expiry time for the timer relative to now.
135 duration_type expires_from_now(const implementation_type& impl) const
137 return service_impl_.expires_from_now(impl);
140 /// Set the expiry time for the timer relative to now.
141 std::size_t expires_from_now(implementation_type& impl,
142 const duration_type& expiry_time, boost::system::error_code& ec)
144 return service_impl_.expires_from_now(impl, expiry_time, ec);
147 // Perform a blocking wait on the timer.
148 void wait(implementation_type& impl, boost::system::error_code& ec)
150 service_impl_.wait(impl, ec);
153 // Start an asynchronous wait on the timer.
154 template <typename WaitHandler>
155 void async_wait(implementation_type& impl, WaitHandler handler)
157 service_impl_.async_wait(impl, handler);
160 private:
161 // The service that provides the platform-specific implementation.
162 service_impl_type& service_impl_;
165 } // namespace asio
166 } // namespace boost
168 #include <boost/asio/detail/pop_options.hpp>
170 #endif // BOOST_ASIO_DEADLINE_TIMER_SERVICE_HPP