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