| 225 | #endif |
| 226 | |
| 227 | void process_events(struct kevent *events, int r) |
| 228 | { |
| 229 | std::lock_guard<decltype(Base::lock)> guard(Base::lock); |
| 230 | |
| 231 | for (int i = 0; i < r; i++) { |
| 232 | if (events[i].filter == EVFILT_SIGNAL) { |
| 233 | bool reenable = pull_signal(events[i].ident, events[i].udata); |
| 234 | events[i].flags = reenable ? EV_ENABLE : EV_DISABLE; |
| 235 | } |
| 236 | else if (events[i].filter == EVFILT_READ || events[i].filter == EVFILT_WRITE) { |
| 237 | int flags = events[i].filter == EVFILT_READ ? IN_EVENTS : OUT_EVENTS; |
| 238 | auto r = Base::receive_fd_event(*this, fd_r(events[i].ident), events[i].udata, flags); |
| 239 | if (std::get<0>(r) == 0) { |
| 240 | // we use EV_CLEAR to clear the EOF status of fifos/pipes (and wait for |
| 241 | // another connection). |
| 242 | events[i].flags = EV_DISABLE | EV_CLEAR; |
| 243 | } |
| 244 | else { |
| 245 | events[i].flags = EV_ENABLE; |
| 246 | } |
| 247 | } |
| 248 | else { |
| 249 | events[i].flags = EV_DISABLE; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // Now we disable all received events, to simulate EV_DISPATCH: |
| 254 | kevent(kqfd, events, r, nullptr, 0, nullptr); |
| 255 | } |
| 256 | |
| 257 | // Pull a signal from pending, and report it, until it is no longer pending or the watch |
| 258 | // should be disabled. Call with lock held. |