summaryrefslogtreecommitdiff
path: root/ev.pod
diff options
context:
space:
mode:
authorroot <root>2010-11-10 14:36:42 +0000
committerroot <root>2010-11-10 14:36:42 +0000
commit7932500041954eb78d398298efc297aa8ae00182 (patch)
tree4336c251c2e87b985746866069dc47ae40b1f328 /ev.pod
parentd73eaa2c434ebf68c0cf8385d11ce6a872b1ea0e (diff)
*** empty log message ***
Diffstat (limited to 'ev.pod')
-rw-r--r--ev.pod55
1 files changed, 55 insertions, 0 deletions
diff --git a/ev.pod b/ev.pod
index bcea84b..a72bec9 100644
--- a/ev.pod
+++ b/ev.pod
@@ -3369,6 +3369,56 @@ loop!).
=back
+=head1 COMMON OR USEFUL IDIOMS (OR BOTH)
+
+This section explains some common idioms that are not immediately
+obvious. Note that examples are sprinkled over the whole manual, and this
+section only contains stuff that wouldn't fit anywhere else.
+
+=over 4
+
+=item Model/nested event loop invocations and exit conditions.
+
+Often (especially in GUI toolkits) there are places where you have
+I<modal> interaction, which is most easily implemented by recursively
+invoking C<ev_run>.
+
+This brings the problem of exiting - a callback might want to finish the
+main C<ev_run> call, but not the nested one (e.g. user clicked "Quit", but
+a modal "Are you sure?" dialog is still waiting), or just the nested one
+and not the main one (e.g. user clocked "Ok" in a modal dialog), or some
+other combination: In these cases, C<ev_break> will not work alone.
+
+The solution is to maintain "break this loop" variable for each C<ev_run>
+invocation, and use a loop around C<ev_run> until the condition is
+triggered, using C<EVRUN_ONCE>:
+
+ // main loop
+ int exit_main_loop = 0;
+
+ while (!exit_main_loop)
+ ev_run (EV_DEFAULT_ EVRUN_ONCE);
+
+ // in a model watcher
+ int exit_nested_loop = 0;
+
+ while (!exit_nested_loop)
+ ev_run (EV_A_ EVRUN_ONCE);
+
+To exit from any of these loops, just set the corresponding exit variable:
+
+ // exit modal loop
+ exit_nested_loop = 1;
+
+ // exit main program, after modal loop is finished
+ exit_main_loop = 1;
+
+ // exit both
+ exit_main_loop = exit_nested_loop = 1;
+
+=back
+
+
=head1 LIBEVENT EMULATION
Libev offers a compatibility emulation layer for libevent. It cannot
@@ -3376,6 +3426,11 @@ emulate the internals of libevent, so here are some usage hints:
=over 4
+=item * Only the libevent-1.4.1-beta API is being emulated.
+
+This was the newest libevent version available when libev was implemented,
+and is still mostly uncanged in 2010.
+
=item * Use it by including <event.h>, as usual.
=item * The following members are fully supported: ev_base, ev_callback,