Lely core libraries
2.3.4
|
Go to the documentation of this file.
24 #ifndef LELY_IO2_TIMER_HPP_
25 #define LELY_IO2_TIMER_HPP_
47 auto overrun = wait->r.result;
51 compat::invoke(::std::move(self->func_), overrun, ec);
54 func_(::std::forward<F>(f)) {}
61 typename ::std::decay<F>::type func_;
72 inline typename ::std::enable_if<
86 using Signature = void(
int, ::std::error_code);
95 auto self =
static_cast<TimerWait*
>(wait);
101 self->func_(overrun, ec);
104 func_(::std::forward<F>(f)) {}
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; }
165 ::std::error_code ec;
167 if (overrun < 0) throw ::std::system_error(ec,
"getoverrun");
178 ::std::pair<duration, duration>
179 gettime(::std::error_code& ec)
const noexcept {
182 itimerspec value = {{0, 0}, {0, 0}};
188 return {util::from_timespec(value.it_value),
189 util::from_timespec(value.it_interval)};
199 ::std::pair<duration, duration>
201 ::std::error_code ec;
203 if (ec) throw ::std::system_error(ec,
"gettime");
208 ::std::pair<duration, duration>
209 settime(
const duration& expiry,
const duration& period,
210 ::std::error_code& ec) noexcept {
213 itimerspec value = {util::to_timespec(period), util::to_timespec(expiry)};
214 itimerspec ovalue = {{0, 0}, {0, 0}};
220 return {util::from_timespec(ovalue.it_value),
221 util::from_timespec(ovalue.it_interval)};
225 ::std::pair<duration, duration>
226 settime(
const duration& expiry,
const duration& period = {}) {
227 ::std::error_code ec;
228 auto ovalue =
settime(expiry, period, ec);
229 if (ec) throw ::std::system_error(ec,
"settime");
234 ::std::pair<duration, duration>
235 settime(
const time_point& expiry,
const duration& period,
236 ::std::error_code& ec) noexcept {
239 itimerspec value = {util::to_timespec(period), util::to_timespec(expiry)};
240 itimerspec ovalue = {{0, 0}, {0, 0}};
246 return {util::from_timespec(ovalue.it_value),
247 util::from_timespec(ovalue.it_interval)};
251 ::std::pair<duration, duration>
252 settime(
const time_point& expiry,
const duration& period = {}) {
253 ::std::error_code ec;
254 auto ovalue =
settime(expiry, period, ec);
255 if (ec) throw ::std::system_error(ec,
"settime");
274 typename ::std::enable_if<!::std::is_base_of<
296 if (!future) util::throw_errc(
"async_wait");
313 #endif // !LELY_IO2_TIMER_HPP_
::std::pair< duration, duration > settime(const duration &expiry, const duration &period={})
io_dev_t * io_timer_get_dev(const io_timer_t *timer)
Returns a pointer to the abstract I/O device representing the timer.
::std::pair< duration, duration > settime(const time_point &expiry, const duration &period, ::std::error_code &ec) noexcept
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
A reference to an abstract timer.
int result
The result of the wait operation: the expiration overrun count (see io_timer_getoverrun()) on success...
void submit_wait(io_timer_wait &wait) noexcept
bool abort_wait(struct io_timer_wait &wait) noexcept
io_clock_t * io_timer_get_clock(const io_timer_t *timer)
Returns a pointer to the clock used by the timer.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
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.
struct io_timer_wait_result r
The result of the wait operation.
ev::Executor get_executor() const noexcept
Returns the executor to which the completion task is (to be) submitted.
ev_future_t * io_timer_async_wait(io_timer_t *timer, ev_exec_t *exec, struct io_timer_wait **pwait)
Submits an asynchronous wait operation to an I/O timer and creates a future which becomes ready once ...
::std::pair< duration, duration > gettime() const
ev::Future< int, int > async_wait(struct io_timer_wait **pwait=nullptr)
int getoverrun(::std::error_code &ec) const noexcept
A wait operation suitable for use with an I/O timer.
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.
TimerWait(ev_exec_t *exec, F &&f)
Constructs a wait operation with a completion task.
::std::pair< duration, duration > settime(const duration &expiry, const duration &period, ::std::error_code &ec) noexcept
bool cancel_wait(struct io_timer_wait &wait) noexcept
An abstract I/O device. This class is a wrapper around #io_dev_t*.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
An abstract task executor. This class is a wrapper around #ev_exec_t*.
Determines whether F can be invoked with the arguments Args....
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.
#define IO_TIMER_WAIT_INIT(exec, func)
The static initializer for io_timer_wait.
ev::Future< int, int > async_wait(ev_exec_t *exec, struct io_timer_wait **pwait=nullptr)
void io_timer_submit_wait(io_timer_t *timer, struct io_timer_wait *wait)
Submits a wait operation to an I/O timer.
TimerWait(F &&f)
Constructs a wait operation with a completion task.
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={})
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
A wait operation suitable for use with an I/O timer.
::std::pair< duration, duration > gettime(::std::error_code &ec) const noexcept
An abstract clock. This class is a wrapper around #io_clock_t*.
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_settime(io_timer_t *timer, int flags, const struct itimerspec *value, struct itimerspec *ovalue)
Arms or disarms an I/O timer.
void submit_wait(ev_exec_t *exec, F &&f)
const struct io_dev_vtbl *const io_dev_t
An abstract I/O device.
Clock get_clock() const noexcept
const struct io_timer_vtbl *const io_timer_t
An abstract timer.
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
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.
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.