14using TClock = std::chrono::steady_clock;
15using TTime = TClock::time_point;
16using THandle = std::coroutine_handle<>;
22 bool operator<(
const TTimer& e)
const {
23 return std::tuple(Deadline, Id,
static_cast<bool>(Handle)) > std::tuple(e.Deadline, e.Id,
static_cast<bool>(e.Handle));
33 return !Read && !Write && !RHup;
53 bool Match(
const TEvent& other)
const {
54 return Fd == other.Fd && (Type & other.Type);
58template<
typename T1,
typename T2>
59inline std::tuple<T1, T2>
60GetDurationPair(TTime now, TTime deadline, std::chrono::milliseconds maxDuration)
63 return std::make_tuple(T1(0), T2(0));
65 auto duration = (deadline - now);
66 if (duration > maxDuration) {
67 duration = maxDuration;
69 auto part1 = std::chrono::duration_cast<T1>(duration);
71 auto part2 = std::chrono::duration_cast<T2>(duration);
73 return std::make_tuple(part1,part2);
77inline timespec GetTimespec(TTime now, TTime deadline, std::chrono::milliseconds maxDuration)
79 auto [p1, p2] = GetDurationPair<std::chrono::seconds, std::chrono::nanoseconds>(now, deadline, maxDuration);
81 ret.tv_sec = p1.count();
82 ret.tv_nsec = p2.count();