24#ifndef LELY_IO2_TIMER_HPP_
25#define LELY_IO2_TIMER_HPP_
47 auto overrun = wait->r.result;
49 if (overrun == -1) ec = util::make_error_code(wait->r.errc);
51 compat::invoke(::std::move(self->func_), overrun, ec);
54 func_(::std::forward<F>(f)) {}
61 typename ::std::decay<F>::type func_;
72inline typename ::std::enable_if<
86 using Signature =
void(
int, ::std::error_code);
95 auto self =
static_cast<TimerWait*
>(wait);
100 ec = util::make_error_code(wait->r.errc);
101 self->func_(overrun, ec);
104 func_(::std::forward<F>(f)) {}
114 operator ev_task&() &
noexcept {
return task; }
123 ::std::function<Signature> func_;
134 using duration = Clock::duration;
135 using time_point = Clock::time_point;
140 operator io_timer_t*()
const noexcept {
return timer; }
157 ec = util::make_error_code();
165 ::std::error_code ec;
166 int overrun = getoverrun(ec);
167 if (overrun < 0) throw ::std::system_error(ec,
"getoverrun");
178 ::std::pair<duration, duration>
179 gettime(::std::error_code& ec)
const noexcept {
186 ec = util::make_error_code();
188 return {util::from_timespec(value.
it_value),
199 ::std::pair<duration, duration>
201 ::std::error_code ec;
202 auto value = gettime(ec);
203 if (ec) throw ::std::system_error(ec,
"gettime");
208 ::std::pair<duration, duration>
210 ::std::error_code& ec)
noexcept {
218 ec = util::make_error_code();
220 return {util::from_timespec(
ovalue.it_value),
221 util::from_timespec(
ovalue.it_interval)};
225 ::std::pair<duration, duration>
227 ::std::error_code ec;
229 if (ec) throw ::std::system_error(ec,
"settime");
234 ::std::pair<duration, duration>
236 ::std::error_code& ec)
noexcept {
244 ec = util::make_error_code();
246 return {util::from_timespec(
ovalue.it_value),
247 util::from_timespec(
ovalue.it_interval)};
251 ::std::pair<duration, duration>
253 ::std::error_code ec;
255 if (ec) throw ::std::system_error(ec,
"settime");
274 typename ::std::enable_if<!::std::is_base_of<
277 submit_wait(
nullptr, ::std::forward<F>(f));
296 if (!future) util::throw_errc(
"async_wait");
303 return async_wait(
nullptr,
pwait);
An abstract task executor. This class is a wrapper around #ev_exec_t*.
An abstract clock. This class is a wrapper around #io_clock_t*.
An abstract I/O device. This class is a wrapper around #io_dev_t*.
A reference to an abstract timer.
void submit_wait(io_timer_wait &wait) noexcept
::std::pair< duration, duration > gettime(::std::error_code &ec) const noexcept
bool abort_wait(struct io_timer_wait &wait) noexcept
bool cancel_wait(struct io_timer_wait &wait) noexcept
::std::pair< duration, duration > settime(const duration &expiry, const duration &period={})
void submit_wait(ev_exec_t *exec, F &&f)
int getoverrun(::std::error_code &ec) const noexcept
Clock get_clock() const noexcept
ev::Future< int, int > async_wait(struct io_timer_wait **pwait=nullptr)
::std::pair< duration, duration > gettime() const
typename::std::enable_if<!::std::is_base_of< io_timer_wait, typename::std::decay< F >::type >::value >::type submit_wait(F &&f)
::std::pair< duration, duration > settime(const time_point &expiry, const duration &period={})
::std::pair< duration, duration > settime(const time_point &expiry, const duration &period, ::std::error_code &ec) noexcept
ev::Future< int, int > async_wait(ev_exec_t *exec, struct io_timer_wait **pwait=nullptr)
::std::pair< duration, duration > settime(const duration &expiry, const duration &period, ::std::error_code &ec) noexcept
A wait operation suitable for use with an I/O timer.
ev::Executor get_executor() const noexcept
Returns the executor to which the completion task is (to be) submitted.
TimerWait(ev_exec_t *exec, F &&f)
Constructs a wait operation with a completion task.
TimerWait(F &&f)
Constructs a wait operation with a completion task.
This header file is part of the I/O library; it contains the C++ interface for the abstract clock.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
This header file is part of the event library; it contains the C++ interface for the futures and prom...
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
This header file is part of the I/O library; it contains the abstract timer interface.
int io_timer_settime(io_timer_t *timer, int flags, const struct itimerspec *value, struct itimerspec *ovalue)
Arms or disarms an I/O timer.
const struct io_timer_vtbl *const io_timer_t
An abstract timer.
static size_t io_timer_abort_wait(io_timer_t *timer, struct io_timer_wait *wait)
Aborts the specified I/O timer wait operation if it is pending.
static size_t io_timer_cancel_wait(io_timer_t *timer, struct io_timer_wait *wait)
Cancels the specified I/O timer wait operation if it is pending.
io_clock_t * io_timer_get_clock(const io_timer_t *timer)
Returns a pointer to the clock used by the timer.
io_dev_t * io_timer_get_dev(const io_timer_t *timer)
Returns a pointer to the abstract I/O device representing the timer.
void io_timer_submit_wait(io_timer_t *timer, struct io_timer_wait *wait)
Submits a wait operation to an I/O timer.
struct io_timer_wait * io_timer_wait_from_task(struct ev_task *task)
Obtains a pointer to an I/O timer wait operation from a pointer to its completion task.
int io_timer_getoverrun(const io_timer_t *timer)
Obtains the I/O timer expiration overrun count of the last successfully processed expiration.
int io_timer_gettime(const io_timer_t *timer, struct itimerspec *value)
Obtains the amount of time until the specified I/O timer expires and the reload value of the timer.
#define IO_TIMER_WAIT_INIT(exec, func)
The static initializer for io_timer_wait.
const struct io_dev_vtbl *const io_dev_t
An abstract I/O device.
This header file is part of the I/O library; it contains the C++ interface for the abstract I/O devic...
int result
The result of the wait operation: the expiration overrun count (see io_timer_getoverrun()) on success...
A wait operation suitable for use with an I/O timer.
struct io_timer_wait_result r
The result of the wait operation.
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
A struct specifying an interval and initial value for a timer.
struct timespec it_interval
The timer period.
struct timespec it_value
The timer expiration.
Determines whether F can be invoked with the arguments Args....
typename::std::enable_if< compat::is_invocable< F, int,::std::error_code >::value, detail::TimerWaitWrapper< F > * >::type make_timer_wait_wrapper(ev_exec_t *exec, F &&f)
Creates a wait operation with a completion task.