… | |
… | |
569 | kernel is more efficient (which says nothing about its actual speed, of |
569 | kernel is more efficient (which says nothing about its actual speed, of |
570 | course). While stopping, setting and starting an I/O watcher does never |
570 | course). While stopping, setting and starting an I/O watcher does never |
571 | cause an extra system call as with C<EVBACKEND_EPOLL>, it still adds up to |
571 | cause an extra system call as with C<EVBACKEND_EPOLL>, it still adds up to |
572 | two event changes per incident. Support for C<fork ()> is very bad (you |
572 | two event changes per incident. Support for C<fork ()> is very bad (you |
573 | might have to leak fd's on fork, but it's more sane than epoll) and it |
573 | might have to leak fd's on fork, but it's more sane than epoll) and it |
574 | drops fds silently in similarly hard-to-detect cases |
574 | drops fds silently in similarly hard-to-detect cases. |
575 | |
575 | |
576 | This backend usually performs well under most conditions. |
576 | This backend usually performs well under most conditions. |
577 | |
577 | |
578 | While nominally embeddable in other event loops, this doesn't work |
578 | While nominally embeddable in other event loops, this doesn't work |
579 | everywhere, so you might need to test for this. And since it is broken |
579 | everywhere, so you might need to test for this. And since it is broken |
… | |
… | |
1393 | transition between them will be described in more detail - and while these |
1393 | transition between them will be described in more detail - and while these |
1394 | rules might look complicated, they usually do "the right thing". |
1394 | rules might look complicated, they usually do "the right thing". |
1395 | |
1395 | |
1396 | =over 4 |
1396 | =over 4 |
1397 | |
1397 | |
1398 | =item initialiased |
1398 | =item initialised |
1399 | |
1399 | |
1400 | Before a watcher can be registered with the event loop it has to be |
1400 | Before a watcher can be registered with the event loop it has to be |
1401 | initialised. This can be done with a call to C<ev_TYPE_init>, or calls to |
1401 | initialised. This can be done with a call to C<ev_TYPE_init>, or calls to |
1402 | C<ev_init> followed by the watcher-specific C<ev_TYPE_set> function. |
1402 | C<ev_init> followed by the watcher-specific C<ev_TYPE_set> function. |
1403 | |
1403 | |
… | |
… | |
3658 | already been invoked. |
3658 | already been invoked. |
3659 | |
3659 | |
3660 | A common way around all these issues is to make sure that |
3660 | A common way around all these issues is to make sure that |
3661 | C<start_new_request> I<always> returns before the callback is invoked. If |
3661 | C<start_new_request> I<always> returns before the callback is invoked. If |
3662 | C<start_new_request> immediately knows the result, it can artificially |
3662 | C<start_new_request> immediately knows the result, it can artificially |
3663 | delay invoking the callback by e.g. using a C<prepare> or C<idle> watcher |
3663 | delay invoking the callback by using a C<prepare> or C<idle> watcher for |
3664 | for example, or more sneakily, by reusing an existing (stopped) watcher |
3664 | example, or more sneakily, by reusing an existing (stopped) watcher and |
3665 | and pushing it into the pending queue: |
3665 | pushing it into the pending queue: |
3666 | |
3666 | |
3667 | ev_set_cb (watcher, callback); |
3667 | ev_set_cb (watcher, callback); |
3668 | ev_feed_event (EV_A_ watcher, 0); |
3668 | ev_feed_event (EV_A_ watcher, 0); |
3669 | |
3669 | |
3670 | This way, C<start_new_request> can safely return before the callback is |
3670 | This way, C<start_new_request> can safely return before the callback is |
… | |
… | |
3678 | |
3678 | |
3679 | This brings the problem of exiting - a callback might want to finish the |
3679 | This brings the problem of exiting - a callback might want to finish the |
3680 | main C<ev_run> call, but not the nested one (e.g. user clicked "Quit", but |
3680 | main C<ev_run> call, but not the nested one (e.g. user clicked "Quit", but |
3681 | a modal "Are you sure?" dialog is still waiting), or just the nested one |
3681 | a modal "Are you sure?" dialog is still waiting), or just the nested one |
3682 | and not the main one (e.g. user clocked "Ok" in a modal dialog), or some |
3682 | and not the main one (e.g. user clocked "Ok" in a modal dialog), or some |
3683 | other combination: In these cases, C<ev_break> will not work alone. |
3683 | other combination: In these cases, a simple C<ev_break> will not work. |
3684 | |
3684 | |
3685 | The solution is to maintain "break this loop" variable for each C<ev_run> |
3685 | The solution is to maintain "break this loop" variable for each C<ev_run> |
3686 | invocation, and use a loop around C<ev_run> until the condition is |
3686 | invocation, and use a loop around C<ev_run> until the condition is |
3687 | triggered, using C<EVRUN_ONCE>: |
3687 | triggered, using C<EVRUN_ONCE>: |
3688 | |
3688 | |