… | |
… | |
685 | C<EVUNLOOP_ONE>, which will make the innermost C<ev_loop> call return, or |
685 | C<EVUNLOOP_ONE>, which will make the innermost C<ev_loop> call return, or |
686 | C<EVUNLOOP_ALL>, which will make all nested C<ev_loop> calls return. |
686 | C<EVUNLOOP_ALL>, which will make all nested C<ev_loop> calls return. |
687 | |
687 | |
688 | This "unloop state" will be cleared when entering C<ev_loop> again. |
688 | This "unloop state" will be cleared when entering C<ev_loop> again. |
689 | |
689 | |
|
|
690 | It is safe to call C<ev_unloop> from otuside any C<ev_loop> calls. |
|
|
691 | |
690 | =item ev_ref (loop) |
692 | =item ev_ref (loop) |
691 | |
693 | |
692 | =item ev_unref (loop) |
694 | =item ev_unref (loop) |
693 | |
695 | |
694 | Ref/unref can be used to add or remove a reference count on the event |
696 | Ref/unref can be used to add or remove a reference count on the event |
… | |
… | |
2502 | =over 4 |
2504 | =over 4 |
2503 | |
2505 | |
2504 | =item ev_once (loop, int fd, int events, ev_tstamp timeout, callback) |
2506 | =item ev_once (loop, int fd, int events, ev_tstamp timeout, callback) |
2505 | |
2507 | |
2506 | This function combines a simple timer and an I/O watcher, calls your |
2508 | This function combines a simple timer and an I/O watcher, calls your |
2507 | callback on whichever event happens first and automatically stop both |
2509 | callback on whichever event happens first and automatically stops both |
2508 | watchers. This is useful if you want to wait for a single event on an fd |
2510 | watchers. This is useful if you want to wait for a single event on an fd |
2509 | or timeout without having to allocate/configure/start/stop/free one or |
2511 | or timeout without having to allocate/configure/start/stop/free one or |
2510 | more watchers yourself. |
2512 | more watchers yourself. |
2511 | |
2513 | |
2512 | If C<fd> is less than 0, then no I/O watcher will be started and events |
2514 | If C<fd> is less than 0, then no I/O watcher will be started and the |
2513 | is being ignored. Otherwise, an C<ev_io> watcher for the given C<fd> and |
2515 | C<events> argument is being ignored. Otherwise, an C<ev_io> watcher for |
2514 | C<events> set will be created and started. |
2516 | the given C<fd> and C<events> set will be created and started. |
2515 | |
2517 | |
2516 | If C<timeout> is less than 0, then no timeout watcher will be |
2518 | If C<timeout> is less than 0, then no timeout watcher will be |
2517 | started. Otherwise an C<ev_timer> watcher with after = C<timeout> (and |
2519 | started. Otherwise an C<ev_timer> watcher with after = C<timeout> (and |
2518 | repeat = 0) will be started. While C<0> is a valid timeout, it is of |
2520 | repeat = 0) will be started. C<0> is a valid timeout. |
2519 | dubious value. |
|
|
2520 | |
2521 | |
2521 | The callback has the type C<void (*cb)(int revents, void *arg)> and gets |
2522 | The callback has the type C<void (*cb)(int revents, void *arg)> and gets |
2522 | passed an C<revents> set like normal event callbacks (a combination of |
2523 | passed an C<revents> set like normal event callbacks (a combination of |
2523 | C<EV_ERROR>, C<EV_READ>, C<EV_WRITE> or C<EV_TIMEOUT>) and the C<arg> |
2524 | C<EV_ERROR>, C<EV_READ>, C<EV_WRITE> or C<EV_TIMEOUT>) and the C<arg> |
2524 | value passed to C<ev_once>: |
2525 | value passed to C<ev_once>. Note that it is possible to receive I<both> |
|
|
2526 | a timeout and an io event at the same time - you probably should give io |
|
|
2527 | events precedence. |
|
|
2528 | |
|
|
2529 | Example: wait up to ten seconds for data to appear on STDIN_FILENO. |
2525 | |
2530 | |
2526 | static void stdin_ready (int revents, void *arg) |
2531 | static void stdin_ready (int revents, void *arg) |
2527 | { |
2532 | { |
|
|
2533 | if (revents & EV_READ) |
|
|
2534 | /* stdin might have data for us, joy! */; |
2528 | if (revents & EV_TIMEOUT) |
2535 | else if (revents & EV_TIMEOUT) |
2529 | /* doh, nothing entered */; |
2536 | /* doh, nothing entered */; |
2530 | else if (revents & EV_READ) |
|
|
2531 | /* stdin might have data for us, joy! */; |
|
|
2532 | } |
2537 | } |
2533 | |
2538 | |
2534 | ev_once (STDIN_FILENO, EV_READ, 10., stdin_ready, 0); |
2539 | ev_once (STDIN_FILENO, EV_READ, 10., stdin_ready, 0); |
2535 | |
2540 | |
2536 | =item ev_feed_event (ev_loop *, watcher *, int revents) |
2541 | =item ev_feed_event (ev_loop *, watcher *, int revents) |