ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.pod
(Generate patch)

Comparing libev/ev.pod (file contents):
Revision 1.237 by root, Thu Apr 16 07:58:03 2009 UTC vs.
Revision 1.239 by root, Tue Apr 21 14:14:19 2009 UTC

644 644
645This function is rarely useful, but when some event callback runs for a 645This function is rarely useful, but when some event callback runs for a
646very long time without entering the event loop, updating libev's idea of 646very long time without entering the event loop, updating libev's idea of
647the current time is a good idea. 647the current time is a good idea.
648 648
649See also "The special problem of time updates" in the C<ev_timer> section. 649See also L<The special problem of time updates> in the C<ev_timer> section.
650 650
651=item ev_suspend (loop) 651=item ev_suspend (loop)
652 652
653=item ev_resume (loop) 653=item ev_resume (loop)
654 654
1332descriptors to non-blocking mode is also usually a good idea (but not 1332descriptors to non-blocking mode is also usually a good idea (but not
1333required if you know what you are doing). 1333required if you know what you are doing).
1334 1334
1335If you cannot use non-blocking mode, then force the use of a 1335If you cannot use non-blocking mode, then force the use of a
1336known-to-be-good backend (at the time of this writing, this includes only 1336known-to-be-good backend (at the time of this writing, this includes only
1337C<EVBACKEND_SELECT> and C<EVBACKEND_POLL>). 1337C<EVBACKEND_SELECT> and C<EVBACKEND_POLL>). The same applies to file
1338descriptors for which non-blocking operation makes no sense (such as
1339files) - libev doesn't guarentee any specific behaviour in that case.
1338 1340
1339Another thing you have to watch out for is that it is quite easy to 1341Another thing you have to watch out for is that it is quite easy to
1340receive "spurious" readiness notifications, that is your callback might 1342receive "spurious" readiness notifications, that is your callback might
1341be called with C<EV_READ> but a subsequent C<read>(2) will actually block 1343be called with C<EV_READ> but a subsequent C<read>(2) will actually block
1342because there is no data. Not only are some backends known to create a 1344because there is no data. Not only are some backends known to create a
2708event loop blocks next and before C<ev_check> watchers are being called, 2710event loop blocks next and before C<ev_check> watchers are being called,
2709and only in the child after the fork. If whoever good citizen calling 2711and only in the child after the fork. If whoever good citizen calling
2710C<ev_default_fork> cheats and calls it in the wrong process, the fork 2712C<ev_default_fork> cheats and calls it in the wrong process, the fork
2711handlers will be invoked, too, of course. 2713handlers will be invoked, too, of course.
2712 2714
2715=head3 The special problem of life after fork - how is it possible?
2716
2717Most uses of C<fork()> consist of forking, then some simple calls to ste
2718up/change the process environment, followed by a call to C<exec()>. This
2719sequence should be handled by libev without any problems.
2720
2721This changes when the application actually wants to do event handling
2722in the child, or both parent in child, in effect "continuing" after the
2723fork.
2724
2725The default mode of operation (for libev, with application help to detect
2726forks) is to duplicate all the state in the child, as would be expected
2727when I<either> the parent I<or> the child process continues.
2728
2729When both processes want to continue using libev, then this is usually the
2730wrong result. In that case, usually one process (typically the parent) is
2731supposed to continue with all watchers in place as before, while the other
2732process typically wants to start fresh, i.e. without any active watchers.
2733
2734The cleanest and most efficient way to achieve that with libev is to
2735simply create a new event loop, which of course will be "empty", and
2736use that for new watchers. This has the advantage of not touching more
2737memory than necessary, and thus avoiding the copy-on-write, and the
2738disadvantage of having to use multiple event loops (which do not support
2739signal watchers).
2740
2741When this is not possible, or you want to use the default loop for
2742other reasons, then in the process that wants to start "fresh", call
2743C<ev_default_destroy ()> followed by C<ev_default_loop (...)>. Destroying
2744the default loop will "orphan" (not stop) all registered watchers, so you
2745have to be careful not to execute code that modifies those watchers. Note
2746also that in that case, you have to re-register any signal watchers.
2747
2713=head3 Watcher-Specific Functions and Data Members 2748=head3 Watcher-Specific Functions and Data Members
2714 2749
2715=over 4 2750=over 4
2716 2751
2717=item ev_fork_init (ev_signal *, callback) 2752=item ev_fork_init (ev_signal *, callback)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines