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