xref: /netbsd-src/external/bsd/libevent/dist/cmake/CheckWorkingKqueue.cmake (revision 657871a79c9a2060a6255a242fa1a1ef76b56ec6)
1*657871a7Schristosinclude(CheckCSourceRuns)
2*657871a7Schristos
3*657871a7Schristoscheck_c_source_runs(
4*657871a7Schristos"
5*657871a7Schristos#include <sys/types.h>
6*657871a7Schristos#include <sys/time.h>
7*657871a7Schristos#include <sys/event.h>
8*657871a7Schristos#include <stdio.h>
9*657871a7Schristos#include <unistd.h>
10*657871a7Schristos#include <fcntl.h>
11*657871a7Schristos
12*657871a7Schristosint
13*657871a7Schristosmain(int argc, char **argv)
14*657871a7Schristos{
15*657871a7Schristos    int kq;
16*657871a7Schristos    int n;
17*657871a7Schristos    int fd[2];
18*657871a7Schristos    struct kevent ev;
19*657871a7Schristos    struct timespec ts;
20*657871a7Schristos    char buf[80000];
21*657871a7Schristos
22*657871a7Schristos    if (pipe(fd) == -1)
23*657871a7Schristos        exit(1);
24*657871a7Schristos    if (fcntl(fd[1], F_SETFL, O_NONBLOCK) == -1)
25*657871a7Schristos        exit(1);
26*657871a7Schristos
27*657871a7Schristos    while ((n = write(fd[1], buf, sizeof(buf))) == sizeof(buf))
28*657871a7Schristos        ;
29*657871a7Schristos
30*657871a7Schristos    if ((kq = kqueue()) == -1)
31*657871a7Schristos        exit(1);
32*657871a7Schristos
33*657871a7Schristos    memset(&ev, 0, sizeof(ev));
34*657871a7Schristos    ev.ident = fd[1];
35*657871a7Schristos    ev.filter = EVFILT_WRITE;
36*657871a7Schristos    ev.flags = EV_ADD | EV_ENABLE;
37*657871a7Schristos    n = kevent(kq, &ev, 1, NULL, 0, NULL);
38*657871a7Schristos    if (n == -1)
39*657871a7Schristos        exit(1);
40*657871a7Schristos
41*657871a7Schristos    read(fd[0], buf, sizeof(buf));
42*657871a7Schristos
43*657871a7Schristos    ts.tv_sec = 0;
44*657871a7Schristos    ts.tv_nsec = 0;
45*657871a7Schristos    n = kevent(kq, NULL, 0, &ev, 1, &ts);
46*657871a7Schristos    if (n == -1 || n == 0)
47*657871a7Schristos        exit(1);
48*657871a7Schristos
49*657871a7Schristos    exit(0);
50*657871a7Schristos}
51*657871a7Schristos
52*657871a7Schristos" EVENT__HAVE_WORKING_KQUEUE)
53