Skip to content

Commit

Permalink
Fix kqueue response for wait_for_fd with interests=0
Browse files Browse the repository at this point in the history
  • Loading branch information
Coldwings committed Sep 12, 2024
1 parent 5b40acf commit 4f9feed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion io/epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ ok: entry.interests |= eint;
}
return ret;
}
ret = thread_usleep(timeout.timeout() ? timeout : Timeout(10));
ret = thread_usleep(timeout);
ERRNO err;
if (ret == -1 && err.no == EOK) {
return 0; // Event arrived
Expand Down
11 changes: 8 additions & 3 deletions io/kqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,16 @@ class KQueue : public MasterEventEngine, public CascadingEventEngine, public Res
}

int wait_for_fd(int fd, uint32_t interests, Timeout timeout) override {
if (unlikely(interests == 0)) {
errno = ENOSYS;
return -1;
}
short ev = (interests == EVENT_READ) ? EVFILT_READ : EVFILT_WRITE;
auto current = CURRENT;
enqueue(fd, ev, EV_ADD | EV_ONESHOT, 0, current, true);
int ret = enqueue(fd, ev, EV_ADD | EV_ONESHOT, 0, current);
if (ret < 0) return ret;
if (timeout.expired()) {
int ret = -1;
ret = -1;
do_wait_and_fire_events(0, [current, &ret](thread* th) {
if (th == current)
ret = 0;
Expand All @@ -139,7 +144,7 @@ class KQueue : public MasterEventEngine, public CascadingEventEngine, public Res
}
return ret;
}
int ret = thread_usleep(timeout);
ret = thread_usleep(timeout);
ERRNO err;
if (ret == -1 && err.no == EOK) {
return 0; // event arrived
Expand Down

0 comments on commit 4f9feed

Please sign in to comment.