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 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 | * |
… | |
… | |
83 | kqueue_poll (EV_P_ ev_tstamp timeout) |
83 | kqueue_poll (EV_P_ ev_tstamp timeout) |
84 | { |
84 | { |
85 | int res, i; |
85 | int res, i; |
86 | struct timespec ts; |
86 | struct timespec ts; |
87 | |
87 | |
|
|
88 | EV_SUSPEND_CB; |
|
|
89 | |
88 | /* need to resize so there is enough space for errors */ |
90 | /* need to resize so there is enough space for errors */ |
89 | if (kqueue_changecnt > kqueue_eventmax) |
91 | if (kqueue_changecnt > kqueue_eventmax) |
90 | { |
92 | { |
91 | ev_free (kqueue_events); |
93 | ev_free (kqueue_events); |
92 | kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_changecnt); |
94 | kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_changecnt); |
… | |
… | |
96 | ts.tv_sec = (time_t)timeout; |
98 | ts.tv_sec = (time_t)timeout; |
97 | ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9); |
99 | 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); |
100 | res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts); |
99 | kqueue_changecnt = 0; |
101 | kqueue_changecnt = 0; |
100 | |
102 | |
|
|
103 | EV_RESUME_CB; |
|
|
104 | |
101 | if (expect_false (res < 0)) |
105 | if (expect_false (res < 0)) |
102 | { |
106 | { |
103 | if (errno != EINTR) |
107 | if (errno != EINTR) |
104 | syserr ("(libev) kevent"); |
108 | ev_syserr ("(libev) kevent"); |
105 | |
109 | |
106 | return; |
110 | return; |
107 | } |
111 | } |
108 | |
112 | |
109 | for (i = 0; i < res; ++i) |
113 | for (i = 0; i < res; ++i) |
… | |
… | |
182 | kqueue_fork (EV_P) |
186 | kqueue_fork (EV_P) |
183 | { |
187 | { |
184 | close (backend_fd); |
188 | close (backend_fd); |
185 | |
189 | |
186 | while ((backend_fd = kqueue ()) < 0) |
190 | while ((backend_fd = kqueue ()) < 0) |
187 | syserr ("(libev) kqueue"); |
191 | ev_syserr ("(libev) kqueue"); |
188 | |
192 | |
189 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); |
193 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); |
190 | |
194 | |
191 | /* re-register interest in fds */ |
195 | /* re-register interest in fds */ |
192 | fd_rearm_all (EV_A); |
196 | fd_rearm_all (EV_A); |