… | |
… | |
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, |
… | |
… | |
974 | inline_size void |
974 | inline_size void |
975 | fd_reify (EV_P) |
975 | fd_reify (EV_P) |
976 | { |
976 | { |
977 | int i; |
977 | int i; |
978 | |
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 | |
979 | for (i = 0; i < fdchangecnt; ++i) |
1004 | for (i = 0; i < fdchangecnt; ++i) |
980 | { |
1005 | { |
981 | int fd = fdchanges [i]; |
1006 | int fd = fdchanges [i]; |
982 | ANFD *anfd = anfds + fd; |
1007 | ANFD *anfd = anfds + fd; |
983 | ev_io *w; |
1008 | ev_io *w; |
984 | |
1009 | |
985 | unsigned char o_events = anfd->events; |
1010 | unsigned char o_events = anfd->events; |
986 | unsigned char o_reify = anfd->reify; |
1011 | unsigned char o_reify = anfd->reify; |
987 | |
1012 | |
988 | anfd->reify = 0; |
1013 | anfd->reify = 0; |
989 | |
|
|
990 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
|
|
991 | if (o_reify & EV__IOFDSET) |
|
|
992 | { |
|
|
993 | unsigned long arg; |
|
|
994 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
|
|
995 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
|
|
996 | printf ("oi %d %x\n", fd, anfd->handle);//D |
|
|
997 | } |
|
|
998 | #endif |
|
|
999 | |
1014 | |
1000 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
1015 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
1001 | { |
1016 | { |
1002 | anfd->events = 0; |
1017 | anfd->events = 0; |
1003 | |
1018 | |
… | |
… | |
1354 | read (evpipe [0], &dummy, 1); |
1369 | read (evpipe [0], &dummy, 1); |
1355 | } |
1370 | } |
1356 | |
1371 | |
1357 | #if EV_SIGNAL_ENABLE |
1372 | #if EV_SIGNAL_ENABLE |
1358 | if (sig_pending) |
1373 | if (sig_pending) |
1359 | { |
1374 | { |
1360 | sig_pending = 0; |
1375 | sig_pending = 0; |
1361 | |
1376 | |
1362 | for (i = EV_NSIG - 1; i--; ) |
1377 | for (i = EV_NSIG - 1; i--; ) |
1363 | if (expect_false (signals [i].pending)) |
1378 | if (expect_false (signals [i].pending)) |
1364 | ev_feed_signal_event (EV_A_ i + 1); |
1379 | ev_feed_signal_event (EV_A_ i + 1); |
… | |
… | |
2193 | } |
2208 | } |
2194 | } |
2209 | } |
2195 | |
2210 | |
2196 | #if EV_PERIODIC_ENABLE |
2211 | #if EV_PERIODIC_ENABLE |
2197 | |
2212 | |
2198 | inline_speed |
2213 | inline_speed void |
2199 | periodic_recalc (EV_P_ ev_periodic *w) |
2214 | periodic_recalc (EV_P_ ev_periodic *w) |
2200 | { |
2215 | { |
2201 | /* TODO: use slow but potentially more correct incremental algo, */ |
2216 | /* TODO: use slow but potentially more correct incremental algo, */ |
2202 | /* also do not rely on ceil */ |
2217 | /* also do not rely on ceil */ |
2203 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2218 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
… | |
… | |
3063 | if (!pend || pend == path) |
3078 | if (!pend || pend == path) |
3064 | break; |
3079 | break; |
3065 | |
3080 | |
3066 | *pend = 0; |
3081 | *pend = 0; |
3067 | w->wd = inotify_add_watch (fs_fd, path, mask); |
3082 | w->wd = inotify_add_watch (fs_fd, path, mask); |
3068 | } |
3083 | } |
3069 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
3084 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
3070 | } |
3085 | } |
3071 | } |
3086 | } |
3072 | |
3087 | |
3073 | if (w->wd >= 0) |
3088 | if (w->wd >= 0) |