1 | /* |
1 | /* |
2 | * libev kqueue backend |
2 | * libev kqueue backend |
3 | * |
3 | * |
4 | * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009 Marc Alexander Lehmann <libev@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * tion, are permitted provided that the following conditions are met: |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * |
9 | * |
… | |
… | |
91 | ev_free (kqueue_events); |
91 | ev_free (kqueue_events); |
92 | kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_changecnt); |
92 | kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_changecnt); |
93 | kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); |
93 | kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); |
94 | } |
94 | } |
95 | |
95 | |
|
|
96 | EV_RELEASE_CB; |
96 | ts.tv_sec = (time_t)timeout; |
97 | ts.tv_sec = (time_t)timeout; |
97 | ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9); |
98 | ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9); |
98 | res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts); |
99 | res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts); |
|
|
100 | EV_ACQUIRE_CB; |
99 | kqueue_changecnt = 0; |
101 | kqueue_changecnt = 0; |
100 | |
102 | |
101 | if (expect_false (res < 0)) |
103 | if (expect_false (res < 0)) |
102 | { |
104 | { |
103 | if (errno != EINTR) |
105 | if (errno != EINTR) |
104 | syserr ("(libev) kevent"); |
106 | ev_syserr ("(libev) kevent"); |
105 | |
107 | |
106 | return; |
108 | return; |
107 | } |
109 | } |
108 | |
110 | |
109 | for (i = 0; i < res; ++i) |
111 | for (i = 0; i < res; ++i) |
… | |
… | |
182 | kqueue_fork (EV_P) |
184 | kqueue_fork (EV_P) |
183 | { |
185 | { |
184 | close (backend_fd); |
186 | close (backend_fd); |
185 | |
187 | |
186 | while ((backend_fd = kqueue ()) < 0) |
188 | while ((backend_fd = kqueue ()) < 0) |
187 | syserr ("(libev) kqueue"); |
189 | ev_syserr ("(libev) kqueue"); |
188 | |
190 | |
189 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); |
191 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); |
190 | |
192 | |
191 | /* re-register interest in fds */ |
193 | /* re-register interest in fds */ |
192 | fd_rearm_all (EV_A); |
194 | fd_rearm_all (EV_A); |