… | |
… | |
4 | * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009,2010,2011 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 | * |
10 | * 1. Redistributions of source code must retain the above copyright notice, |
10 | * 1. Redistributions of source code must retain the above copyright notice, |
11 | * this list of conditions and the following disclaimer. |
11 | * this list of conditions and the following disclaimer. |
12 | * |
12 | * |
13 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the |
14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. |
15 | * documentation and/or other materials provided with the distribution. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
… | |
… | |
376 | # undef EV_USE_INOTIFY |
376 | # undef EV_USE_INOTIFY |
377 | # define EV_USE_INOTIFY 0 |
377 | # define EV_USE_INOTIFY 0 |
378 | #endif |
378 | #endif |
379 | |
379 | |
380 | #if !EV_USE_NANOSLEEP |
380 | #if !EV_USE_NANOSLEEP |
381 | # ifndef _WIN32 |
381 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
|
|
382 | # if !defined(_WIN32) && !defined(__hpux) |
382 | # include <sys/select.h> |
383 | # include <sys/select.h> |
383 | # endif |
384 | # endif |
384 | #endif |
385 | #endif |
385 | |
386 | |
386 | #if EV_USE_INOTIFY |
387 | #if EV_USE_INOTIFY |
… | |
… | |
973 | inline_size void |
974 | inline_size void |
974 | fd_reify (EV_P) |
975 | fd_reify (EV_P) |
975 | { |
976 | { |
976 | int i; |
977 | int i; |
977 | |
978 | |
|
|
979 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
|
|
980 | for (i = 0; i < fdchangecnt; ++i) |
|
|
981 | { |
|
|
982 | int fd = fdchanges [i]; |
|
|
983 | ANFD *anfd = anfds + fd; |
|
|
984 | |
|
|
985 | if (anfd->reify & EV__IOFDSET) |
|
|
986 | { |
|
|
987 | SOCKET handle = EV_FD_TO_WIN32_HANDLE (fd); |
|
|
988 | |
|
|
989 | if (handle != anfd->handle) |
|
|
990 | { |
|
|
991 | unsigned long arg; |
|
|
992 | |
|
|
993 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (handle, FIONREAD, &arg) == 0)); |
|
|
994 | |
|
|
995 | /* handle changed, but fd didn't - we need to do it in two steps */ |
|
|
996 | backend_modify (EV_A_ fd, anfd->events, 0); |
|
|
997 | anfd->events = 0; |
|
|
998 | anfd->handle = handle; |
|
|
999 | } |
|
|
1000 | } |
|
|
1001 | } |
|
|
1002 | #endif |
|
|
1003 | |
978 | for (i = 0; i < fdchangecnt; ++i) |
1004 | for (i = 0; i < fdchangecnt; ++i) |
979 | { |
1005 | { |
980 | int fd = fdchanges [i]; |
1006 | int fd = fdchanges [i]; |
981 | ANFD *anfd = anfds + fd; |
1007 | ANFD *anfd = anfds + fd; |
982 | ev_io *w; |
1008 | ev_io *w; |
983 | |
1009 | |
984 | unsigned char o_events = anfd->events; |
1010 | unsigned char o_events = anfd->events; |
985 | unsigned char o_reify = anfd->reify; |
1011 | unsigned char o_reify = anfd->reify; |
986 | |
1012 | |
987 | anfd->reify = 0; |
1013 | anfd->reify = 0; |
988 | |
|
|
989 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
|
|
990 | if (o_reify & EV__IOFDSET) |
|
|
991 | { |
|
|
992 | unsigned long arg; |
|
|
993 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
|
|
994 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
|
|
995 | printf ("oi %d %x\n", fd, anfd->handle);//D |
|
|
996 | } |
|
|
997 | #endif |
|
|
998 | |
1014 | |
999 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
1015 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
1000 | { |
1016 | { |
1001 | anfd->events = 0; |
1017 | anfd->events = 0; |
1002 | |
1018 | |
… | |
… | |
1351 | char dummy; |
1367 | char dummy; |
1352 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1368 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1353 | read (evpipe [0], &dummy, 1); |
1369 | read (evpipe [0], &dummy, 1); |
1354 | } |
1370 | } |
1355 | |
1371 | |
|
|
1372 | #if EV_SIGNAL_ENABLE |
1356 | if (sig_pending) |
1373 | if (sig_pending) |
1357 | { |
1374 | { |
1358 | sig_pending = 0; |
1375 | sig_pending = 0; |
1359 | |
1376 | |
1360 | for (i = EV_NSIG - 1; i--; ) |
1377 | for (i = EV_NSIG - 1; i--; ) |
1361 | if (expect_false (signals [i].pending)) |
1378 | if (expect_false (signals [i].pending)) |
1362 | ev_feed_signal_event (EV_A_ i + 1); |
1379 | ev_feed_signal_event (EV_A_ i + 1); |
1363 | } |
1380 | } |
|
|
1381 | #endif |
1364 | |
1382 | |
1365 | #if EV_ASYNC_ENABLE |
1383 | #if EV_ASYNC_ENABLE |
1366 | if (async_pending) |
1384 | if (async_pending) |
1367 | { |
1385 | { |
1368 | async_pending = 0; |
1386 | async_pending = 0; |
… | |
… | |
2189 | feed_reverse_done (EV_A_ EV_TIMER); |
2207 | feed_reverse_done (EV_A_ EV_TIMER); |
2190 | } |
2208 | } |
2191 | } |
2209 | } |
2192 | |
2210 | |
2193 | #if EV_PERIODIC_ENABLE |
2211 | #if EV_PERIODIC_ENABLE |
|
|
2212 | |
|
|
2213 | inline_speed void |
|
|
2214 | periodic_recalc (EV_P_ ev_periodic *w) |
|
|
2215 | { |
|
|
2216 | /* TODO: use slow but potentially more correct incremental algo, */ |
|
|
2217 | /* also do not rely on ceil */ |
|
|
2218 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
|
|
2219 | } |
|
|
2220 | |
2194 | /* make periodics pending */ |
2221 | /* make periodics pending */ |
2195 | inline_size void |
2222 | inline_size void |
2196 | periodics_reify (EV_P) |
2223 | periodics_reify (EV_P) |
2197 | { |
2224 | { |
2198 | EV_FREQUENT_CHECK; |
2225 | EV_FREQUENT_CHECK; |
… | |
… | |
2217 | ANHE_at_cache (periodics [HEAP0]); |
2244 | ANHE_at_cache (periodics [HEAP0]); |
2218 | downheap (periodics, periodiccnt, HEAP0); |
2245 | downheap (periodics, periodiccnt, HEAP0); |
2219 | } |
2246 | } |
2220 | else if (w->interval) |
2247 | else if (w->interval) |
2221 | { |
2248 | { |
2222 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2249 | periodic_recalc (EV_A_ w); |
|
|
2250 | |
2223 | /* if next trigger time is not sufficiently in the future, put it there */ |
2251 | /* if next trigger time is not sufficiently in the future, put it there */ |
2224 | /* this might happen because of floating point inexactness */ |
2252 | /* this might happen because of floating point inexactness */ |
2225 | if (ev_at (w) - ev_rt_now < TIME_EPSILON) |
2253 | if (ev_at (w) - ev_rt_now < TIME_EPSILON) |
2226 | { |
2254 | { |
2227 | ev_at (w) += w->interval; |
2255 | ev_at (w) += w->interval; |
… | |
… | |
2261 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]); |
2289 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]); |
2262 | |
2290 | |
2263 | if (w->reschedule_cb) |
2291 | if (w->reschedule_cb) |
2264 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
2292 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
2265 | else if (w->interval) |
2293 | else if (w->interval) |
2266 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2294 | periodic_recalc (EV_A_ w); |
2267 | |
2295 | |
2268 | ANHE_at_cache (periodics [i]); |
2296 | ANHE_at_cache (periodics [i]); |
2269 | } |
2297 | } |
2270 | |
2298 | |
2271 | reheap (periodics, periodiccnt); |
2299 | reheap (periodics, periodiccnt); |
… | |
… | |
2763 | if (w->reschedule_cb) |
2791 | if (w->reschedule_cb) |
2764 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
2792 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
2765 | else if (w->interval) |
2793 | else if (w->interval) |
2766 | { |
2794 | { |
2767 | assert (("libev: ev_periodic_start called with negative interval value", w->interval >= 0.)); |
2795 | assert (("libev: ev_periodic_start called with negative interval value", w->interval >= 0.)); |
2768 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
2796 | periodic_recalc (EV_A_ w); |
2769 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
|
|
2770 | } |
2797 | } |
2771 | else |
2798 | else |
2772 | ev_at (w) = w->offset; |
2799 | ev_at (w) = w->offset; |
2773 | |
2800 | |
2774 | EV_FREQUENT_CHECK; |
2801 | EV_FREQUENT_CHECK; |
… | |
… | |
3051 | if (!pend || pend == path) |
3078 | if (!pend || pend == path) |
3052 | break; |
3079 | break; |
3053 | |
3080 | |
3054 | *pend = 0; |
3081 | *pend = 0; |
3055 | w->wd = inotify_add_watch (fs_fd, path, mask); |
3082 | w->wd = inotify_add_watch (fs_fd, path, mask); |
3056 | } |
3083 | } |
3057 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
3084 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
3058 | } |
3085 | } |
3059 | } |
3086 | } |
3060 | |
3087 | |
3061 | if (w->wd >= 0) |
3088 | if (w->wd >= 0) |