|
24 | 24 | namespace NNet { |
25 | 25 |
|
26 | 26 | /** |
27 | | - * @class TPollerBase |
28 | | - * @brief Base class for pollers managing asynchronous I/O events and timers. |
| 27 | + * @brief Backend-independent base for I/O pollers. |
29 | 28 | * |
30 | | - * TPollerBase provides the common interface and functionality for pollers that drive asynchronous |
31 | | - * operations. It allows scheduling timers, registering I/O events (read, write, remote hang-up) on file |
32 | | - * descriptors, and waking up waiting coroutines. It also offers convenience methods such as @ref Sleep() |
33 | | - * (and its overload accepting a std::chrono::duration) and @ref Yield(). |
| 29 | + * Manages three concerns shared by all poller backends: |
| 30 | + * - **Timers** — `AddTimer` / `RemoveTimer` / `ProcessTimers` |
| 31 | + * - **I/O event registration** — `AddRead`, `AddWrite`, `AddRemoteHup`, `RemoveEvent` |
| 32 | + * - **Coroutine scheduling** — `Sleep`, `Yield`, `Wakeup`, `WakeupReadyHandles` |
34 | 33 | * |
35 | | - * The class maintains internal collections for pending changes (events), ready events, and timers. |
36 | | - * It also keeps track of the maximum file descriptor, which is used in system-level polling calls. |
37 | | - * |
38 | | - * Key methods include: |
39 | | - * - @ref AddTimer() to schedule a timer. |
40 | | - * - @ref RemoveTimer() to cancel a timer. |
41 | | - * - @ref AddRead(), @ref AddWrite(), @ref AddRemoteHup() to register I/O events. |
42 | | - * - @ref RemoveEvent() to deregister events. |
43 | | - * - @ref Sleep() and @ref Yield() to suspend execution until a specified time or until the next |
44 | | - * polling round. |
45 | | - * - @ref Wakeup() and @ref WakeupReadyHandles() to resume waiting coroutines when events occur. |
46 | | - * |
47 | | - * The class also provides helper methods for computing timeout values (via @ref GetTimeout()). |
48 | | - * |
49 | | - * The detailed comment inside @ref Wakeup() describes how a waiting coroutine is resumed and how new |
50 | | - * event registrations are matched. |
| 34 | + * Concrete backends (TEPoll, TKqueue, …) inherit from this class and implement |
| 35 | + * `Poll()` to fill `ReadyEvents_` using the OS-specific mechanism, then call |
| 36 | + * `WakeupReadyHandles()` (provided here) to resume waiting coroutines. |
51 | 37 | */ |
52 | 38 | class TPollerBase { |
53 | 39 | public: |
@@ -91,20 +77,26 @@ class TPollerBase { |
91 | 77 | } |
92 | 78 |
|
93 | 79 | /** |
94 | | - * @brief Registers a read event on a file descriptor. |
| 80 | + * @brief Registers a read interest on a file descriptor. |
95 | 81 | * |
96 | | - * @param fd The file descriptor. |
97 | | - * @param h The coroutine handle to resume when data is available. |
| 82 | + * `h` will be resumed by `WakeupReadyHandles()` on the next loop iteration |
| 83 | + * after the fd becomes readable. |
| 84 | + * |
| 85 | + * @param fd File descriptor to watch. |
| 86 | + * @param h Coroutine to resume when data is available. |
98 | 87 | */ |
99 | 88 | void AddRead(int fd, THandle h) { |
100 | 89 | MaxFd_ = std::max(MaxFd_, fd); |
101 | 90 | Changes_.emplace_back(TEvent{fd, TEvent::READ, h}); |
102 | 91 | } |
103 | 92 | /** |
104 | | - * @brief Registers a write event on a file descriptor. |
| 93 | + * @brief Registers a write interest on a file descriptor. |
105 | 94 | * |
106 | | - * @param fd The file descriptor. |
107 | | - * @param h The coroutine handle to resume when ready for writing. |
| 95 | + * `h` will be resumed by `WakeupReadyHandles()` on the next loop iteration |
| 96 | + * after the fd becomes writable. |
| 97 | + * |
| 98 | + * @param fd File descriptor to watch. |
| 99 | + * @param h Coroutine to resume when ready for writing. |
108 | 100 | */ |
109 | 101 | void AddWrite(int fd, THandle h) { |
110 | 102 | MaxFd_ = std::max(MaxFd_, fd); |
@@ -133,12 +125,12 @@ class TPollerBase { |
133 | 125 | Changes_.emplace_back(TEvent{fd, TEvent::READ|TEvent::WRITE|TEvent::RHUP, {}}); |
134 | 126 | } |
135 | 127 | /** |
136 | | - * @brief Removes events associated with a given coroutine handle. |
| 128 | + * @brief No-op placeholder for future cleanup by handle. |
137 | 129 | * |
138 | | - * This overload will be called by destructors of unfinished futures. |
139 | | - * Unimplemented. |
| 130 | + * Intended to be called by destructors of unfinished futures so that |
| 131 | + * pending waits can be unregistered. Currently unimplemented. |
140 | 132 | * |
141 | | - * @param h The coroutine handle. |
| 133 | + * @param h The coroutine handle (unused). |
142 | 134 | */ |
143 | 135 | void RemoveEvent(THandle /*h*/) { |
144 | 136 | // TODO: Add new vector for this type of removing |
@@ -204,11 +196,13 @@ class TPollerBase { |
204 | 196 | return Sleep(TClock::now() + duration); |
205 | 197 | } |
206 | 198 | /** |
207 | | - * @brief Yields execution to the next event loop iteration. |
| 199 | + * @brief Suspends the coroutine until the next event-loop iteration. |
208 | 200 | * |
209 | | - * Equivalent to calling Sleep() with a default zero time. |
| 201 | + * Equivalent to `Sleep(TTime{})`, which fires immediately on the next |
| 202 | + * `ProcessTimers()` call. Use when you want to give other coroutines a |
| 203 | + * chance to run before continuing. |
210 | 204 | * |
211 | | - * @return An awaitable object for yielding execution. |
| 205 | + * @return An awaitable that resumes on the next loop tick. |
212 | 206 | */ |
213 | 207 | auto Yield() { |
214 | 208 | return Sleep(TTime{}); |
|
0 commit comments