17#ifndef TOOLBOX_IO_REACTOR_HPP
18#define TOOLBOX_IO_REACTOR_HPP
46 EndOfEventDispatch = 2,
56 constexpr Handle(std::nullptr_t =
nullptr) noexcept {}
65 : reactor_{rhs.reactor_}
69 rhs.reactor_ =
nullptr;
79 bool empty() const noexcept {
return reactor_ ==
nullptr; }
80 explicit operator bool() const noexcept {
return reactor_ !=
nullptr; }
81 auto fd() const noexcept {
return fd_; }
82 auto sid() const noexcept {
return sid_; }
84 void reset(std::nullptr_t =
nullptr) noexcept
87 reactor_->unsubscribe(fd_, sid_);
95 std::swap(reactor_, rhs.reactor_);
96 std::swap(fd_, rhs.fd_);
97 std::swap(sid_, rhs.sid_);
104 reactor_->set_events(fd_, sid_, events, slot, ec);
109 reactor_->set_events(fd_, sid_, events, slot);
111 void set_events(
unsigned events, std::error_code& ec)
noexcept
114 reactor_->set_events(fd_, sid_, events, ec);
119 reactor_->set_events(fd_, sid_, events);
124 int fd_{-1}, sid_{0};
127 explicit Reactor(std::size_t size_hint = 0);
139 [[nodiscard]]
Handle subscribe(
int fd,
unsigned events,
IoSlot slot);
144 return tqs_[
static_cast<size_t>(priority)].insert(expiry, interval, slot);
149 return tqs_[
static_cast<size_t>(priority)].insert(expiry, slot);
156 case HookType::EndOfCycleNoWait:
157 end_of_cycle_no_wait_hooks.push_back(hook);
159 case HookType::EndOfEventDispatch:
160 end_of_event_dispatch_hooks_.push_back(hook);
171 void do_wakeup() noexcept final;
176 int dispatch(
CyclTime now, Event* buf,
int size);
177 void set_events(
int fd,
int sid,
unsigned events,
IoSlot slot,
std::error_code& ec) noexcept;
178 void set_events(
int fd,
int sid,
unsigned events,
IoSlot slot);
179 void set_events(
int fd,
int sid,
unsigned events,
std::error_code& ec) noexcept;
180 void set_events(
int fd,
int sid,
unsigned events);
181 void unsubscribe(
int fd,
int sid) noexcept;
189 std::vector<Data> data_;
190 EventFd notify_{0, EFD_NONBLOCK};
191 static_assert(
static_cast<int>(Priority::High) == 0);
192 static_assert(
static_cast<int>(Priority::Low) == 1);
194 std::array<TimerQueue, 2> tqs_{tp_, tp_};
195 HookList end_of_cycle_no_wait_hooks, end_of_event_dispatch_hooks_;