1 | /* |
1 | /* |
2 | * libev kqueue backend |
2 | * libev kqueue backend |
3 | * |
3 | * |
4 | * Copyright (c) 2007,2008 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 | * |
… | |
… | |
37 | * either the BSD or the GPL. |
37 | * either the BSD or the GPL. |
38 | */ |
38 | */ |
39 | |
39 | |
40 | #include <sys/types.h> |
40 | #include <sys/types.h> |
41 | #include <sys/time.h> |
41 | #include <sys/time.h> |
42 | #include <sys/queue.h> |
|
|
43 | #include <sys/event.h> |
42 | #include <sys/event.h> |
44 | #include <string.h> |
43 | #include <string.h> |
45 | #include <errno.h> |
44 | #include <errno.h> |
46 | |
45 | |
47 | void inline_speed |
46 | void inline_speed |
… | |
… | |
91 | ev_free (kqueue_events); |
90 | ev_free (kqueue_events); |
92 | kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_changecnt); |
91 | kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_changecnt); |
93 | kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); |
92 | kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); |
94 | } |
93 | } |
95 | |
94 | |
96 | if (expect_false (suspend_cb)) suspend_cb (EV_A); |
95 | EV_RELEASE_CB; |
97 | ts.tv_sec = (time_t)timeout; |
96 | ts.tv_sec = (time_t)timeout; |
98 | ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9); |
97 | ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9); |
99 | res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts); |
98 | res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts); |
100 | if (expect_false (resume_cb)) resume_cb (EV_A); |
99 | EV_ACQUIRE_CB; |
101 | kqueue_changecnt = 0; |
100 | kqueue_changecnt = 0; |
102 | |
101 | |
103 | if (expect_false (res < 0)) |
102 | if (expect_false (res < 0)) |
104 | { |
103 | { |
105 | if (errno != EINTR) |
104 | if (errno != EINTR) |