`select` 有效,但 `kqueue` 在等待 X11 连接时无效

`select` works but `kqueue` doesn't when waiting on X11 connection

在有可用的 X11 事件之前会一直阻塞:

int x11_fd = ConnectionNumber(display);
fd_set in_fds;
FD_ZERO(&in_fds);
FD_SET(x11_fd, &in_fds);
select(x11_fd + 1, &in_fds, NULL, NULL, NULL);

这就马上returns:

int x11_fd = ConnectionNumber(display);
int kq = kqueue();
struct kevent ev;
EV_SET(&ev, x11_fd, EVFILT_READ, EV_ADD, 0, 0, 0);
kevent(kq, &ev, 1, NULL, 0, NULL);

为什么?我是不是用错了kqueue

我很确定我误解了 kqueue 的 API。

OP 中显示的调用仅将过滤器添加到队列中,不会等待它们。为此,需要将一个单独的 kevent 数组传递给 eventlist 参数。

kevent(kq, NULL, 0, &ev, 1, NULL);