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

Comparing libev/ev.pod (file contents):
Revision 1.344 by root, Wed Nov 10 13:41:48 2010 UTC vs.
Revision 1.345 by root, Wed Nov 10 14:36:42 2010 UTC

3367loop!). 3367loop!).
3368 3368
3369=back 3369=back
3370 3370
3371 3371
3372=head1 COMMON OR USEFUL IDIOMS (OR BOTH)
3373
3374This section explains some common idioms that are not immediately
3375obvious. Note that examples are sprinkled over the whole manual, and this
3376section only contains stuff that wouldn't fit anywhere else.
3377
3378=over 4
3379
3380=item Model/nested event loop invocations and exit conditions.
3381
3382Often (especially in GUI toolkits) there are places where you have
3383I<modal> interaction, which is most easily implemented by recursively
3384invoking C<ev_run>.
3385
3386This brings the problem of exiting - a callback might want to finish the
3387main C<ev_run> call, but not the nested one (e.g. user clicked "Quit", but
3388a modal "Are you sure?" dialog is still waiting), or just the nested one
3389and not the main one (e.g. user clocked "Ok" in a modal dialog), or some
3390other combination: In these cases, C<ev_break> will not work alone.
3391
3392The solution is to maintain "break this loop" variable for each C<ev_run>
3393invocation, and use a loop around C<ev_run> until the condition is
3394triggered, using C<EVRUN_ONCE>:
3395
3396 // main loop
3397 int exit_main_loop = 0;
3398
3399 while (!exit_main_loop)
3400 ev_run (EV_DEFAULT_ EVRUN_ONCE);
3401
3402 // in a model watcher
3403 int exit_nested_loop = 0;
3404
3405 while (!exit_nested_loop)
3406 ev_run (EV_A_ EVRUN_ONCE);
3407
3408To exit from any of these loops, just set the corresponding exit variable:
3409
3410 // exit modal loop
3411 exit_nested_loop = 1;
3412
3413 // exit main program, after modal loop is finished
3414 exit_main_loop = 1;
3415
3416 // exit both
3417 exit_main_loop = exit_nested_loop = 1;
3418
3419=back
3420
3421
3372=head1 LIBEVENT EMULATION 3422=head1 LIBEVENT EMULATION
3373 3423
3374Libev offers a compatibility emulation layer for libevent. It cannot 3424Libev offers a compatibility emulation layer for libevent. It cannot
3375emulate the internals of libevent, so here are some usage hints: 3425emulate the internals of libevent, so here are some usage hints:
3376 3426
3377=over 4 3427=over 4
3428
3429=item * Only the libevent-1.4.1-beta API is being emulated.
3430
3431This was the newest libevent version available when libev was implemented,
3432and is still mostly uncanged in 2010.
3378 3433
3379=item * Use it by including <event.h>, as usual. 3434=item * Use it by including <event.h>, as usual.
3380 3435
3381=item * The following members are fully supported: ev_base, ev_callback, 3436=item * The following members are fully supported: ev_base, ev_callback,
3382ev_arg, ev_fd, ev_res, ev_events. 3437ev_arg, ev_fd, ev_res, ev_events.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines