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

Comparing libev/ev.pod (file contents):
Revision 1.35 by root, Fri Nov 23 19:35:09 2007 UTC vs.
Revision 1.36 by root, Sat Nov 24 07:14:26 2007 UTC

505*) >>), and you can stop watching for events at any time by calling the 505*) >>), and you can stop watching for events at any time by calling the
506corresponding stop function (C<< ev_<type>_stop (loop, watcher *) >>. 506corresponding stop function (C<< ev_<type>_stop (loop, watcher *) >>.
507 507
508As long as your watcher is active (has been started but not stopped) you 508As long as your watcher is active (has been started but not stopped) you
509must not touch the values stored in it. Most specifically you must never 509must not touch the values stored in it. Most specifically you must never
510reinitialise it or call its set macro. 510reinitialise it or call its C<set> macro.
511
512You can check whether an event is active by calling the C<ev_is_active
513(watcher *)> macro. To see whether an event is outstanding (but the
514callback for it has not been called yet) you can use the C<ev_is_pending
515(watcher *)> macro.
516 511
517Each and every callback receives the event loop pointer as first, the 512Each and every callback receives the event loop pointer as first, the
518registered watcher structure as second, and a bitset of received events as 513registered watcher structure as second, and a bitset of received events as
519third argument. 514third argument.
520 515
576your callbacks is well-written it can just attempt the operation and cope 571your callbacks is well-written it can just attempt the operation and cope
577with the error from read() or write(). This will not work in multithreaded 572with the error from read() or write(). This will not work in multithreaded
578programs, though, so beware. 573programs, though, so beware.
579 574
580=back 575=back
576
577=head2 SUMMARY OF GENERIC WATCHER FUNCTIONS
578
579In the following description, C<TYPE> stands for the watcher type,
580e.g. C<timer> for C<ev_timer> watchers and C<io> for C<ev_io> watchers.
581
582=over 4
583
584=item C<ev_init> (ev_TYPE *watcher, callback)
585
586This macro initialises the generic portion of a watcher. The contents
587of the watcher object can be arbitrary (so C<malloc> will do). Only
588the generic parts of the watcher are initialised, you I<need> to call
589the type-specific C<ev_TYPE_set> macro afterwards to initialise the
590type-specific parts. For each type there is also a C<ev_TYPE_init> macro
591which rolls both calls into one.
592
593You can reinitialise a watcher at any time as long as it has been stopped
594(or never started) and there are no pending events outstanding.
595
596The callbakc is always of type C<void (*)(ev_loop *loop, ev_TYPE *watcher,
597int revents)>.
598
599=item C<ev_TYPE_set> (ev_TYPE *, [args])
600
601This macro initialises the type-specific parts of a watcher. You need to
602call C<ev_init> at least once before you call this macro, but you can
603call C<ev_TYPE_set> any number of times. You must not, however, call this
604macro on a watcher that is active (it can be pending, however, which is a
605difference to the C<ev_init> macro).
606
607Although some watcher types do not have type-specific arguments
608(e.g. C<ev_prepare>) you still need to call its C<set> macro.
609
610=item C<ev_TYPE_init> (ev_TYPE *watcher, callback, [args])
611
612This convinience macro rolls both C<ev_init> and C<ev_TYPE_set> macro
613calls into a single call. This is the most convinient method to initialise
614a watcher. The same limitations apply, of course.
615
616=item C<ev_TYPE_start> (loop *, ev_TYPE *watcher)
617
618Starts (activates) the given watcher. Only active watchers will receive
619events. If the watcher is already active nothing will happen.
620
621=item C<ev_TYPE_stop> (loop *, ev_TYPE *watcher)
622
623Stops the given watcher again (if active) and clears the pending
624status. It is possible that stopped watchers are pending (for example,
625non-repeating timers are being stopped when they become pending), but
626C<ev_TYPE_stop> ensures that the watcher is neither active nor pending. If
627you want to free or reuse the memory used by the watcher it is therefore a
628good idea to always call its C<ev_TYPE_stop> function.
629
630=item bool ev_is_active (ev_TYPE *watcher)
631
632Returns a true value iff the watcher is active (i.e. it has been started
633and not yet been stopped). As long as a watcher is active you must not modify
634it.
635
636=item bool ev_is_pending (ev_TYPE *watcher)
637
638Returns a true value iff the watcher is pending, (i.e. it has outstanding
639events but its callback has not yet been invoked). As long as a watcher
640is pending (but not active) you must not call an init function on it (but
641C<ev_TYPE_set> is safe) and you must make sure the watcher is available to
642libev (e.g. you cnanot C<free ()> it).
643
644=item callback = ev_cb (ev_TYPE *watcher)
645
646Returns the callback currently set on the watcher.
647
648=item ev_cb_set (ev_TYPE *watcher, callback)
649
650Change the callback. You can change the callback at virtually any time
651(modulo threads).
652
653=back
654
581 655
582=head2 ASSOCIATING CUSTOM DATA WITH A WATCHER 656=head2 ASSOCIATING CUSTOM DATA WITH A WATCHER
583 657
584Each watcher has, by default, a member C<void *data> that you can change 658Each watcher has, by default, a member C<void *data> that you can change
585and read at any time, libev will completely ignore it. This can be used 659and read at any time, libev will completely ignore it. This can be used
1058 1132
1059 1133
1060=head2 C<ev_embed> - when one backend isn't enough 1134=head2 C<ev_embed> - when one backend isn't enough
1061 1135
1062This is a rather advanced watcher type that lets you embed one event loop 1136This is a rather advanced watcher type that lets you embed one event loop
1063into another. 1137into another (currently only C<ev_io> events are supported in the embedded
1138loop, other types of watchers might be handled in a delayed or incorrect
1139fashion and must not be used).
1064 1140
1065There are primarily two reasons you would want that: work around bugs and 1141There are primarily two reasons you would want that: work around bugs and
1066prioritise I/O. 1142prioritise I/O.
1067 1143
1068As an example for a bug workaround, the kqueue backend might only support 1144As an example for a bug workaround, the kqueue backend might only support
1076As for prioritising I/O: rarely you have the case where some fds have 1152As for prioritising I/O: rarely you have the case where some fds have
1077to be watched and handled very quickly (with low latency), and even 1153to be watched and handled very quickly (with low latency), and even
1078priorities and idle watchers might have too much overhead. In this case 1154priorities and idle watchers might have too much overhead. In this case
1079you would put all the high priority stuff in one loop and all the rest in 1155you would put all the high priority stuff in one loop and all the rest in
1080a second one, and embed the second one in the first. 1156a second one, and embed the second one in the first.
1157
1158As long as the watcher is active, the callback will be invoked every time
1159there might be events pending in the embedded loop. The callback must then
1160call C<ev_embed_sweep (mainloop, watcher)> to make a single sweep and invoke
1161their callbacks (you could also start an idle watcher to give the embedded
1162loop strictly lower priority for example). You can also set the callback
1163to C<0>, in which case the embed watcher will automatically execute the
1164embedded loop sweep.
1081 1165
1082As long as the watcher is started it will automatically handle events. The 1166As long as the watcher is started it will automatically handle events. The
1083callback will be invoked whenever some events have been handled. You can 1167callback will be invoked whenever some events have been handled. You can
1084set the callback to C<0> to avoid having to specify one if you are not 1168set the callback to C<0> to avoid having to specify one if you are not
1085interested in that. 1169interested in that.
1117 else 1201 else
1118 loop_lo = loop_hi; 1202 loop_lo = loop_hi;
1119 1203
1120=over 4 1204=over 4
1121 1205
1122=item ev_embed_init (ev_embed *, callback, struct ev_loop *loop) 1206=item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)
1123 1207
1124=item ev_embed_set (ev_embed *, callback, struct ev_loop *loop) 1208=item ev_embed_set (ev_embed *, callback, struct ev_loop *embedded_loop)
1125 1209
1126Configures the watcher to embed the given loop, which must be embeddable. 1210Configures the watcher to embed the given loop, which must be
1211embeddable. If the callback is C<0>, then C<ev_embed_sweep> will be
1212invoked automatically, otherwise it is the responsibility of the callback
1213to invoke it (it will continue to be called until the sweep has been done,
1214if you do not want thta, you need to temporarily stop the embed watcher).
1215
1216=item ev_embed_sweep (loop, ev_embed *)
1217
1218Make a single, non-blocking sweep over the embedded loop. This works
1219similarly to C<ev_loop (embedded_loop, EVLOOP_NONBLOCK)>, but in the most
1220apropriate way for embedded loops.
1127 1221
1128=back 1222=back
1129 1223
1130 1224
1131=head1 OTHER FUNCTIONS 1225=head1 OTHER FUNCTIONS
1164 /* stdin might have data for us, joy! */; 1258 /* stdin might have data for us, joy! */;
1165 } 1259 }
1166 1260
1167 ev_once (STDIN_FILENO, EV_READ, 10., stdin_ready, 0); 1261 ev_once (STDIN_FILENO, EV_READ, 10., stdin_ready, 0);
1168 1262
1169=item ev_feed_event (loop, watcher, int events) 1263=item ev_feed_event (ev_loop *, watcher *, int revents)
1170 1264
1171Feeds the given event set into the event loop, as if the specified event 1265Feeds the given event set into the event loop, as if the specified event
1172had happened for the specified watcher (which must be a pointer to an 1266had happened for the specified watcher (which must be a pointer to an
1173initialised but not necessarily started event watcher). 1267initialised but not necessarily started event watcher).
1174 1268
1175=item ev_feed_fd_event (loop, int fd, int revents) 1269=item ev_feed_fd_event (ev_loop *, int fd, int revents)
1176 1270
1177Feed an event on the given fd, as if a file descriptor backend detected 1271Feed an event on the given fd, as if a file descriptor backend detected
1178the given events it. 1272the given events it.
1179 1273
1180=item ev_feed_signal_event (loop, int signum) 1274=item ev_feed_signal_event (ev_loop *loop, int signum)
1181 1275
1182Feed an event as if the given signal occured (loop must be the default loop!). 1276Feed an event as if the given signal occured (C<loop> must be the default
1277loop!).
1183 1278
1184=back 1279=back
1185 1280
1186 1281
1187=head1 LIBEVENT EMULATION 1282=head1 LIBEVENT EMULATION

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines