|
|
| TPollerBase ()=default |
| | Default constructor.
|
| |
|
| TPollerBase (const TPollerBase &)=delete |
| | Copying is disabled.
|
| |
|
TPollerBase & | operator= (const TPollerBase &)=delete |
| |
| unsigned | AddTimer (TTime deadline, THandle h) |
| | Schedules a timer.
|
| |
| bool | RemoveTimer (unsigned timerId, TTime deadline) |
| | Removes or cancels a timer.
|
| |
| void | AddRead (int fd, THandle h) |
| | Registers a read interest on a file descriptor.
|
| |
| void | AddWrite (int fd, THandle h) |
| | Registers a write interest on a file descriptor.
|
| |
| void | AddRemoteHup (int fd, THandle h) |
| | Registers a remote hang-up (RHUP) event.
|
| |
| void | RemoveEvent (int fd) |
| | Removes registered events for a specific file descriptor.
|
| |
| void | RemoveEvent (THandle) |
| | No-op placeholder for future cleanup by handle.
|
| |
| auto | Sleep (TTime until) |
| | Suspends execution until the specified time.
|
| |
| template<typename Rep , typename Period > |
| auto | Sleep (std::chrono::duration< Rep, Period > duration) |
| | Overload of Sleep() accepting a duration.
|
| |
| auto | Yield () |
| | Suspends the coroutine until the next event-loop iteration.
|
| |
| void | Wakeup (TEvent &&change) |
| | Wakes up a coroutine waiting on an event.
|
| |
| void | WakeupReadyHandles () |
| | Wakes up all coroutines waiting on ready events.
|
| |
| void | SetMaxDuration (std::chrono::milliseconds maxDuration) |
| | Sets the maximum polling duration.
|
| |
|
auto | TimersSize () const |
| | Returns the number of scheduled timers.
|
| |
|
|
int | MaxFd_ = 0 |
| | Highest file descriptor in use.
|
| |
|
std::vector< TEvent > | Changes_ |
| | Pending changes (registered events).
|
| |
|
std::vector< TEvent > | ReadyEvents_ |
| | Events ready to wake up their coroutines.
|
| |
|
unsigned | TimerId_ = 0 |
| | Counter for generating unique timer IDs.
|
| |
|
std::priority_queue< TTimer > | Timers_ |
| | Priority queue for scheduled timers.
|
| |
|
TTime | LastTimersProcessTime_ |
| | Last time timers were processed.
|
| |
|
unsigned | LastFiredTimer_ = (unsigned)(-1) |
| | ID of the last fired timer.
|
| |
|
std::chrono::milliseconds | MaxDuration_ = std::chrono::milliseconds(100) |
| | Maximum poll duration.
|
| |
|
timespec | MaxDurationTs_ = GetMaxDuration(MaxDuration_) |
| | Max duration represented as timespec.
|
| |
Backend-independent base for I/O pollers.
Manages three concerns shared by all poller backends:
- Timers —
AddTimer / RemoveTimer / ProcessTimers
- I/O event registration —
AddRead, AddWrite, AddRemoteHup, RemoveEvent
- Coroutine scheduling —
Sleep, Yield, Wakeup, WakeupReadyHandles
Concrete backends (TEPoll, TKqueue, …) inherit from this class and implement Poll() to fill ReadyEvents_ using the OS-specific mechanism, then call WakeupReadyHandles() (provided here) to resume waiting coroutines.
| void NNet::TPollerBase::Wakeup |
( |
TEvent && |
change | ) |
|
|
inline |
Wakes up a coroutine waiting on an event.
This method resumes the coroutine associated with the given TEvent (change), then checks whether that coroutine has added a new wait for the same file descriptor.
- Parameters
-
| change | The event change containing the file descriptor and coroutine handle. |
Wakes up the coroutine associated with the given TEvent change, then checks whether that coroutine has added a new wait on the same file descriptor (Fd). We first store the current size of the Changes_ vector and call change.Handle.resume().
If after resuming, the coroutine does NOT add (or match) a wait entry for change.Fd, we assume that this descriptor is not in use yet and remove it from the poller by resetting change.Handle and appending change to Changes_.
In most cases, Changes_ grows by exactly one entry after resuming a coroutine (it suspends again on a descriptor), but there are scenarios where it can grow by more than one. For example, one coroutine might launch another coroutine without waiting; that second coroutine suspends on ReadSome/WriteSome, returns control to the first coroutine, which then also suspends on ReadSome/WriteSome. In that chain of calls, multiple new waits can be added before returning here, so Changes_ can increase by 2 (or potentially more) in a single wake-up cycle.