… | |
… | |
933 | This is how one would do it normally anyway, the important point is that |
933 | This is how one would do it normally anyway, the important point is that |
934 | the libev application should not optimise around libev but should leave |
934 | the libev application should not optimise around libev but should leave |
935 | optimisations to libev. |
935 | optimisations to libev. |
936 | |
936 | |
937 | |
937 | |
|
|
938 | =head3 Watcher-Specific Functions |
|
|
939 | |
938 | =over 4 |
940 | =over 4 |
939 | |
941 | |
940 | =item ev_io_init (ev_io *, callback, int fd, int events) |
942 | =item ev_io_init (ev_io *, callback, int fd, int events) |
941 | |
943 | |
942 | =item ev_io_set (ev_io *, int fd, int events) |
944 | =item ev_io_set (ev_io *, int fd, int events) |
… | |
… | |
994 | ev_timer_set (&timer, after + ev_now () - ev_time (), 0.); |
996 | ev_timer_set (&timer, after + ev_now () - ev_time (), 0.); |
995 | |
997 | |
996 | The callback is guarenteed to be invoked only when its timeout has passed, |
998 | The callback is guarenteed to be invoked only when its timeout has passed, |
997 | but if multiple timers become ready during the same loop iteration then |
999 | but if multiple timers become ready during the same loop iteration then |
998 | order of execution is undefined. |
1000 | order of execution is undefined. |
|
|
1001 | |
|
|
1002 | =head3 Watcher-Specific Functions and Data Members |
999 | |
1003 | |
1000 | =over 4 |
1004 | =over 4 |
1001 | |
1005 | |
1002 | =item ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat) |
1006 | =item ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat) |
1003 | |
1007 | |
… | |
… | |
1109 | |
1113 | |
1110 | As with timers, the callback is guarenteed to be invoked only when the |
1114 | As with timers, the callback is guarenteed to be invoked only when the |
1111 | time (C<at>) has been passed, but if multiple periodic timers become ready |
1115 | time (C<at>) has been passed, but if multiple periodic timers become ready |
1112 | during the same loop iteration then order of execution is undefined. |
1116 | during the same loop iteration then order of execution is undefined. |
1113 | |
1117 | |
|
|
1118 | =head3 Watcher-Specific Functions and Data Members |
|
|
1119 | |
1114 | =over 4 |
1120 | =over 4 |
1115 | |
1121 | |
1116 | =item ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb) |
1122 | =item ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb) |
1117 | |
1123 | |
1118 | =item ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb) |
1124 | =item ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb) |
… | |
… | |
1264 | with the kernel (thus it coexists with your own signal handlers as long |
1270 | with the kernel (thus it coexists with your own signal handlers as long |
1265 | as you don't register any with libev). Similarly, when the last signal |
1271 | as you don't register any with libev). Similarly, when the last signal |
1266 | watcher for a signal is stopped libev will reset the signal handler to |
1272 | watcher for a signal is stopped libev will reset the signal handler to |
1267 | SIG_DFL (regardless of what it was set to before). |
1273 | SIG_DFL (regardless of what it was set to before). |
1268 | |
1274 | |
|
|
1275 | =head3 Watcher-Specific Functions and Data Members |
|
|
1276 | |
1269 | =over 4 |
1277 | =over 4 |
1270 | |
1278 | |
1271 | =item ev_signal_init (ev_signal *, callback, int signum) |
1279 | =item ev_signal_init (ev_signal *, callback, int signum) |
1272 | |
1280 | |
1273 | =item ev_signal_set (ev_signal *, int signum) |
1281 | =item ev_signal_set (ev_signal *, int signum) |
… | |
… | |
1284 | |
1292 | |
1285 | =head2 C<ev_child> - watch out for process status changes |
1293 | =head2 C<ev_child> - watch out for process status changes |
1286 | |
1294 | |
1287 | Child watchers trigger when your process receives a SIGCHLD in response to |
1295 | Child watchers trigger when your process receives a SIGCHLD in response to |
1288 | some child status changes (most typically when a child of yours dies). |
1296 | some child status changes (most typically when a child of yours dies). |
|
|
1297 | |
|
|
1298 | =head3 Watcher-Specific Functions and Data Members |
1289 | |
1299 | |
1290 | =over 4 |
1300 | =over 4 |
1291 | |
1301 | |
1292 | =item ev_child_init (ev_child *, callback, int pid) |
1302 | =item ev_child_init (ev_child *, callback, int pid) |
1293 | |
1303 | |
… | |
… | |
1361 | reader). Inotify will be used to give hints only and should not change the |
1371 | reader). Inotify will be used to give hints only and should not change the |
1362 | semantics of C<ev_stat> watchers, which means that libev sometimes needs |
1372 | semantics of C<ev_stat> watchers, which means that libev sometimes needs |
1363 | to fall back to regular polling again even with inotify, but changes are |
1373 | to fall back to regular polling again even with inotify, but changes are |
1364 | usually detected immediately, and if the file exists there will be no |
1374 | usually detected immediately, and if the file exists there will be no |
1365 | polling. |
1375 | polling. |
|
|
1376 | |
|
|
1377 | =head3 Watcher-Specific Functions and Data Members |
1366 | |
1378 | |
1367 | =over 4 |
1379 | =over 4 |
1368 | |
1380 | |
1369 | =item ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval) |
1381 | =item ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval) |
1370 | |
1382 | |
… | |
… | |
1453 | Apart from keeping your process non-blocking (which is a useful |
1465 | Apart from keeping your process non-blocking (which is a useful |
1454 | effect on its own sometimes), idle watchers are a good place to do |
1466 | effect on its own sometimes), idle watchers are a good place to do |
1455 | "pseudo-background processing", or delay processing stuff to after the |
1467 | "pseudo-background processing", or delay processing stuff to after the |
1456 | event loop has handled all outstanding events. |
1468 | event loop has handled all outstanding events. |
1457 | |
1469 | |
|
|
1470 | =head3 Watcher-Specific Functions and Data Members |
|
|
1471 | |
1458 | =over 4 |
1472 | =over 4 |
1459 | |
1473 | |
1460 | =item ev_idle_init (ev_signal *, callback) |
1474 | =item ev_idle_init (ev_signal *, callback) |
1461 | |
1475 | |
1462 | Initialises and configures the idle watcher - it has no parameters of any |
1476 | Initialises and configures the idle watcher - it has no parameters of any |
… | |
… | |
1529 | their job. As C<ev_check> watchers are often used to embed other event |
1543 | their job. As C<ev_check> watchers are often used to embed other event |
1530 | loops those other event loops might be in an unusable state until their |
1544 | loops those other event loops might be in an unusable state until their |
1531 | C<ev_check> watcher ran (always remind yourself to coexist peacefully with |
1545 | C<ev_check> watcher ran (always remind yourself to coexist peacefully with |
1532 | others). |
1546 | others). |
1533 | |
1547 | |
|
|
1548 | =head3 Watcher-Specific Functions and Data Members |
|
|
1549 | |
1534 | =over 4 |
1550 | =over 4 |
1535 | |
1551 | |
1536 | =item ev_prepare_init (ev_prepare *, callback) |
1552 | =item ev_prepare_init (ev_prepare *, callback) |
1537 | |
1553 | |
1538 | =item ev_check_init (ev_check *, callback) |
1554 | =item ev_check_init (ev_check *, callback) |
… | |
… | |
1739 | ev_embed_start (loop_hi, &embed); |
1755 | ev_embed_start (loop_hi, &embed); |
1740 | } |
1756 | } |
1741 | else |
1757 | else |
1742 | loop_lo = loop_hi; |
1758 | loop_lo = loop_hi; |
1743 | |
1759 | |
|
|
1760 | =head3 Watcher-Specific Functions and Data Members |
|
|
1761 | |
1744 | =over 4 |
1762 | =over 4 |
1745 | |
1763 | |
1746 | =item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop) |
1764 | =item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop) |
1747 | |
1765 | |
1748 | =item ev_embed_set (ev_embed *, callback, struct ev_loop *embedded_loop) |
1766 | =item ev_embed_set (ev_embed *, callback, struct ev_loop *embedded_loop) |
… | |
… | |
1774 | event loop blocks next and before C<ev_check> watchers are being called, |
1792 | event loop blocks next and before C<ev_check> watchers are being called, |
1775 | and only in the child after the fork. If whoever good citizen calling |
1793 | and only in the child after the fork. If whoever good citizen calling |
1776 | C<ev_default_fork> cheats and calls it in the wrong process, the fork |
1794 | C<ev_default_fork> cheats and calls it in the wrong process, the fork |
1777 | handlers will be invoked, too, of course. |
1795 | handlers will be invoked, too, of course. |
1778 | |
1796 | |
|
|
1797 | =head3 Watcher-Specific Functions and Data Members |
|
|
1798 | |
1779 | =over 4 |
1799 | =over 4 |
1780 | |
1800 | |
1781 | =item ev_fork_init (ev_signal *, callback) |
1801 | =item ev_fork_init (ev_signal *, callback) |
1782 | |
1802 | |
1783 | Initialises and configures the fork watcher - it has no parameters of any |
1803 | Initialises and configures the fork watcher - it has no parameters of any |
… | |
… | |
1999 | |
2019 | |
2000 | =item w->stop () |
2020 | =item w->stop () |
2001 | |
2021 | |
2002 | Stops the watcher if it is active. Again, no C<loop> argument. |
2022 | Stops the watcher if it is active. Again, no C<loop> argument. |
2003 | |
2023 | |
2004 | =item w->again () C<ev::timer>, C<ev::periodic> only |
2024 | =item w->again () (C<ev::timer>, C<ev::periodic> only) |
2005 | |
2025 | |
2006 | For C<ev::timer> and C<ev::periodic>, this invokes the corresponding |
2026 | For C<ev::timer> and C<ev::periodic>, this invokes the corresponding |
2007 | C<ev_TYPE_again> function. |
2027 | C<ev_TYPE_again> function. |
2008 | |
2028 | |
2009 | =item w->sweep () C<ev::embed> only |
2029 | =item w->sweep () (C<ev::embed> only) |
2010 | |
2030 | |
2011 | Invokes C<ev_embed_sweep>. |
2031 | Invokes C<ev_embed_sweep>. |
2012 | |
2032 | |
2013 | =item w->update () C<ev::stat> only |
2033 | =item w->update () (C<ev::stat> only) |
2014 | |
2034 | |
2015 | Invokes C<ev_stat_stat>. |
2035 | Invokes C<ev_stat_stat>. |
2016 | |
2036 | |
2017 | =back |
2037 | =back |
2018 | |
2038 | |
… | |
… | |
2038 | } |
2058 | } |
2039 | |
2059 | |
2040 | |
2060 | |
2041 | =head1 MACRO MAGIC |
2061 | =head1 MACRO MAGIC |
2042 | |
2062 | |
2043 | Libev can be compiled with a variety of options, the most fundemantal is |
2063 | Libev can be compiled with a variety of options, the most fundamantal |
2044 | C<EV_MULTIPLICITY>. This option determines whether (most) functions and |
2064 | of which is C<EV_MULTIPLICITY>. This option determines whether (most) |
2045 | callbacks have an initial C<struct ev_loop *> argument. |
2065 | functions and callbacks have an initial C<struct ev_loop *> argument. |
2046 | |
2066 | |
2047 | To make it easier to write programs that cope with either variant, the |
2067 | To make it easier to write programs that cope with either variant, the |
2048 | following macros are defined: |
2068 | following macros are defined: |
2049 | |
2069 | |
2050 | =over 4 |
2070 | =over 4 |