… | |
… | |
1695 | static void |
1695 | static void |
1696 | 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) |
1697 | { |
1697 | { |
1698 | free (w); |
1698 | free (w); |
1699 | // now do something you wanted to do when the program has |
1699 | // now do something you wanted to do when the program has |
1700 | // no longer asnything immediate to do. |
1700 | // no longer anything immediate to do. |
1701 | } |
1701 | } |
1702 | |
1702 | |
1703 | struct ev_idle *idle_watcher = malloc (sizeof (struct ev_idle)); |
1703 | struct ev_idle *idle_watcher = malloc (sizeof (struct ev_idle)); |
1704 | ev_idle_init (idle_watcher, idle_cb); |
1704 | ev_idle_init (idle_watcher, idle_cb); |
1705 | ev_idle_start (loop, idle_cb); |
1705 | ev_idle_start (loop, idle_cb); |
… | |
… | |
2282 | 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 |
2283 | the constructor. |
2283 | the constructor. |
2284 | |
2284 | |
2285 | class myclass |
2285 | class myclass |
2286 | { |
2286 | { |
2287 | ev_io io; void io_cb (ev::io &w, int revents); |
2287 | ev::io io; void io_cb (ev::io &w, int revents); |
2288 | ev_idle idle void idle_cb (ev::idle &w, int revents); |
2288 | ev:idle idle void idle_cb (ev::idle &w, int revents); |
2289 | |
2289 | |
2290 | myclass (); |
2290 | myclass (int fd) |
2291 | } |
|
|
2292 | |
|
|
2293 | myclass::myclass (int fd) |
|
|
2294 | { |
2291 | { |
2295 | io .set <myclass, &myclass::io_cb > (this); |
2292 | io .set <myclass, &myclass::io_cb > (this); |
2296 | idle.set <myclass, &myclass::idle_cb> (this); |
2293 | idle.set <myclass, &myclass::idle_cb> (this); |
2297 | |
2294 | |
2298 | io.start (fd, ev::READ); |
2295 | io.start (fd, ev::READ); |
|
|
2296 | } |
2299 | } |
2297 | }; |
2300 | |
2298 | |
2301 | |
2299 | |
2302 | =head1 MACRO MAGIC |
2300 | =head1 MACRO MAGIC |
2303 | |
2301 | |
2304 | 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 |