]> granicus.if.org Git - libevent/blob - cmake/CheckWorkingKqueue.cmake
Optimize arc4random_uniform() (by syncing with OpenBSD implementation)
[libevent] / cmake / CheckWorkingKqueue.cmake
1 include(CheckCSourceRuns)
2
3 check_c_source_runs(
4 "
5 #include <stdlib.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <sys/time.h>
9 #include <sys/event.h>
10 #include <stdio.h>
11 #include <unistd.h>
12 #include <fcntl.h>
13
14 int
15 main(int argc, char **argv)
16 {
17     int kq;
18     int n;
19     int fd[2];
20     struct kevent ev;
21     struct timespec ts;
22     char buf[80000];
23
24     if (pipe(fd) == -1)
25         exit(1);
26     if (fcntl(fd[1], F_SETFL, O_NONBLOCK) == -1)
27         exit(1);
28
29     while ((n = write(fd[1], buf, sizeof(buf))) == sizeof(buf))
30         ;
31
32     if ((kq = kqueue()) == -1)
33         exit(1);
34
35     memset(&ev, 0, sizeof(ev));
36     ev.ident = fd[1];
37     ev.filter = EVFILT_WRITE;
38     ev.flags = EV_ADD | EV_ENABLE;
39     n = kevent(kq, &ev, 1, NULL, 0, NULL);
40     if (n == -1)
41         exit(1);
42
43     read(fd[0], buf, sizeof(buf));
44
45     ts.tv_sec = 0;
46     ts.tv_nsec = 0;
47     n = kevent(kq, NULL, 0, &ev, 1, &ts);
48     if (n == -1 || n == 0)
49         exit(1);
50
51     exit(0);
52 }
53
54 " EVENT__HAVE_WORKING_KQUEUE)