… | |
… | |
274 | a fork, you can also make libev check for a fork in each iteration by |
274 | a fork, you can also make libev check for a fork in each iteration by |
275 | enabling this flag. |
275 | enabling this flag. |
276 | |
276 | |
277 | This works by calling C<getpid ()> on every iteration of the loop, |
277 | This works by calling C<getpid ()> on every iteration of the loop, |
278 | and thus this might slow down your event loop if you do a lot of loop |
278 | and thus this might slow down your event loop if you do a lot of loop |
279 | iterations and little real work, but is usually not noticable (on my |
279 | iterations and little real work, but is usually not noticeable (on my |
280 | Linux system for example, C<getpid> is actually a simple 5-insn sequence |
280 | Linux system for example, C<getpid> is actually a simple 5-insn sequence |
281 | without a syscall and thus I<very> fast, but my Linux system also has |
281 | without a syscall and thus I<very> fast, but my Linux system also has |
282 | C<pthread_atfork> which is even faster). |
282 | C<pthread_atfork> which is even faster). |
283 | |
283 | |
284 | The big advantage of this flag is that you can forget about fork (and |
284 | The big advantage of this flag is that you can forget about fork (and |
… | |
… | |
429 | =item ev_loop_fork (loop) |
429 | =item ev_loop_fork (loop) |
430 | |
430 | |
431 | Like C<ev_default_fork>, but acts on an event loop created by |
431 | Like C<ev_default_fork>, but acts on an event loop created by |
432 | C<ev_loop_new>. Yes, you have to call this on every allocated event loop |
432 | C<ev_loop_new>. Yes, you have to call this on every allocated event loop |
433 | after fork, and how you do this is entirely your own problem. |
433 | after fork, and how you do this is entirely your own problem. |
|
|
434 | |
|
|
435 | =item unsigned int ev_loop_count (loop) |
|
|
436 | |
|
|
437 | Returns the count of loop iterations for the loop, which is identical to |
|
|
438 | the number of times libev did poll for new events. It starts at C<0> and |
|
|
439 | happily wraps around with enough iterations. |
|
|
440 | |
|
|
441 | This value can sometimes be useful as a generation counter of sorts (it |
|
|
442 | "ticks" the number of loop iterations), as it roughly corresponds with |
|
|
443 | C<ev_prepare> and C<ev_check> calls. |
434 | |
444 | |
435 | =item unsigned int ev_backend (loop) |
445 | =item unsigned int ev_backend (loop) |
436 | |
446 | |
437 | Returns one of the C<EVBACKEND_*> flags indicating the event backend in |
447 | Returns one of the C<EVBACKEND_*> flags indicating the event backend in |
438 | use. |
448 | use. |
… | |
… | |
1457 | |
1467 | |
1458 | // create io watchers for each fd and a timer before blocking |
1468 | // create io watchers for each fd and a timer before blocking |
1459 | static void |
1469 | static void |
1460 | adns_prepare_cb (ev_loop *loop, ev_prepare *w, int revents) |
1470 | adns_prepare_cb (ev_loop *loop, ev_prepare *w, int revents) |
1461 | { |
1471 | { |
1462 | int timeout = 3600000;truct pollfd fds [nfd]; |
1472 | int timeout = 3600000; |
|
|
1473 | struct pollfd fds [nfd]; |
1463 | // actual code will need to loop here and realloc etc. |
1474 | // actual code will need to loop here and realloc etc. |
1464 | adns_beforepoll (ads, fds, &nfd, &timeout, timeval_from (ev_time ())); |
1475 | adns_beforepoll (ads, fds, &nfd, &timeout, timeval_from (ev_time ())); |
1465 | |
1476 | |
1466 | /* the callback is illegal, but won't be called as we stop during check */ |
1477 | /* the callback is illegal, but won't be called as we stop during check */ |
1467 | ev_timer_init (&tw, 0, timeout * 1e-3); |
1478 | ev_timer_init (&tw, 0, timeout * 1e-3); |