… | |
… | |
1438 | |
1438 | |
1439 | =head3 Watcher-Specific Functions and Data Members |
1439 | =head3 Watcher-Specific Functions and Data Members |
1440 | |
1440 | |
1441 | =over 4 |
1441 | =over 4 |
1442 | |
1442 | |
1443 | =item ev_child_init (ev_child *, callback, int pid) |
1443 | =item ev_child_init (ev_child *, callback, int pid, int trace) |
1444 | |
1444 | |
1445 | =item ev_child_set (ev_child *, int pid) |
1445 | =item ev_child_set (ev_child *, int pid, int trace) |
1446 | |
1446 | |
1447 | Configures the watcher to wait for status changes of process C<pid> (or |
1447 | Configures the watcher to wait for status changes of process C<pid> (or |
1448 | I<any> process if C<pid> is specified as C<0>). The callback can look |
1448 | I<any> process if C<pid> is specified as C<0>). The callback can look |
1449 | at the C<rstatus> member of the C<ev_child> watcher structure to see |
1449 | at the C<rstatus> member of the C<ev_child> watcher structure to see |
1450 | the status word (use the macros from C<sys/wait.h> and see your systems |
1450 | the status word (use the macros from C<sys/wait.h> and see your systems |
1451 | C<waitpid> documentation). The C<rpid> member contains the pid of the |
1451 | C<waitpid> documentation). The C<rpid> member contains the pid of the |
1452 | process causing the status change. |
1452 | process causing the status change. C<trace> must be either C<0> (only |
|
|
1453 | activate the watcher when the process terminates) or C<1> (additionally |
|
|
1454 | activate the watcher when the process is stopped or continued). |
1453 | |
1455 | |
1454 | =item int pid [read-only] |
1456 | =item int pid [read-only] |
1455 | |
1457 | |
1456 | The process id this watcher watches out for, or C<0>, meaning any process id. |
1458 | The process id this watcher watches out for, or C<0>, meaning any process id. |
1457 | |
1459 | |
… | |
… | |
1693 | static void |
1695 | static void |
1694 | idle_cb (struct ev_loop *loop, struct ev_idle *w, int revents) |
1696 | idle_cb (struct ev_loop *loop, struct ev_idle *w, int revents) |
1695 | { |
1697 | { |
1696 | free (w); |
1698 | free (w); |
1697 | // now do something you wanted to do when the program has |
1699 | // now do something you wanted to do when the program has |
1698 | // no longer asnything immediate to do. |
1700 | // no longer anything immediate to do. |
1699 | } |
1701 | } |
1700 | |
1702 | |
1701 | struct ev_idle *idle_watcher = malloc (sizeof (struct ev_idle)); |
1703 | struct ev_idle *idle_watcher = malloc (sizeof (struct ev_idle)); |
1702 | ev_idle_init (idle_watcher, idle_cb); |
1704 | ev_idle_init (idle_watcher, idle_cb); |
1703 | ev_idle_start (loop, idle_cb); |
1705 | ev_idle_start (loop, idle_cb); |
… | |
… | |
2280 | Example: Define a class with an IO and idle watcher, start one of them in |
2282 | Example: Define a class with an IO and idle watcher, start one of them in |
2281 | the constructor. |
2283 | the constructor. |
2282 | |
2284 | |
2283 | class myclass |
2285 | class myclass |
2284 | { |
2286 | { |
2285 | ev_io io; void io_cb (ev::io &w, int revents); |
2287 | ev::io io; void io_cb (ev::io &w, int revents); |
2286 | ev_idle idle void idle_cb (ev::idle &w, int revents); |
2288 | ev:idle idle void idle_cb (ev::idle &w, int revents); |
2287 | |
2289 | |
2288 | myclass (); |
2290 | myclass (int fd) |
2289 | } |
|
|
2290 | |
|
|
2291 | myclass::myclass (int fd) |
|
|
2292 | { |
2291 | { |
2293 | io .set <myclass, &myclass::io_cb > (this); |
2292 | io .set <myclass, &myclass::io_cb > (this); |
2294 | idle.set <myclass, &myclass::idle_cb> (this); |
2293 | idle.set <myclass, &myclass::idle_cb> (this); |
2295 | |
2294 | |
2296 | io.start (fd, ev::READ); |
2295 | io.start (fd, ev::READ); |
|
|
2296 | } |
2297 | } |
2297 | }; |
2298 | |
2298 | |
2299 | |
2299 | |
2300 | =head1 MACRO MAGIC |
2300 | =head1 MACRO MAGIC |
2301 | |
2301 | |
2302 | Libev can be compiled with a variety of options, the most fundamantal |
2302 | Libev can be compiled with a variety of options, the most fundamantal |