1 | /* |
1 | /* |
2 | * libev epoll fd activity backend |
2 | * libev epoll fd activity 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 | * |
… | |
… | |
117 | |
117 | |
118 | static void |
118 | static void |
119 | epoll_poll (EV_P_ ev_tstamp timeout) |
119 | epoll_poll (EV_P_ ev_tstamp timeout) |
120 | { |
120 | { |
121 | int i; |
121 | int i; |
|
|
122 | int eventcnt; |
|
|
123 | |
|
|
124 | /* epoll wait times cannot be larger than (LONG_MAX - 999UL) / HZ msecs, which is below */ |
|
|
125 | /* the default libev max wait time, however. */ |
|
|
126 | EV_RELEASE_CB; |
122 | int eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.)); |
127 | eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.)); |
|
|
128 | EV_ACQUIRE_CB; |
123 | |
129 | |
124 | if (expect_false (eventcnt < 0)) |
130 | if (expect_false (eventcnt < 0)) |
125 | { |
131 | { |
126 | if (errno != EINTR) |
132 | if (errno != EINTR) |
127 | ev_syserr ("(libev) epoll_wait"); |
133 | ev_syserr ("(libev) epoll_wait"); |
… | |
… | |
175 | } |
181 | } |
176 | |
182 | |
177 | int inline_size |
183 | int inline_size |
178 | epoll_init (EV_P_ int flags) |
184 | epoll_init (EV_P_ int flags) |
179 | { |
185 | { |
|
|
186 | #ifdef EPOLL_CLOEXEC |
|
|
187 | backend_fd = epoll_create1 (EPOLL_CLOEXEC); |
|
|
188 | |
|
|
189 | if (backend_fd <= 0) |
|
|
190 | #endif |
180 | backend_fd = epoll_create (256); |
191 | backend_fd = epoll_create (256); |
181 | |
192 | |
182 | if (backend_fd < 0) |
193 | if (backend_fd < 0) |
183 | return 0; |
194 | return 0; |
184 | |
195 | |
185 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); |
196 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); |