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

Comparing libev/ev.3 (file contents):
Revision 1.10 by root, Sat Nov 24 06:23:27 2007 UTC vs.
Revision 1.12 by root, Sat Nov 24 07:20:42 2007 UTC

458\& fatal ("no epoll found here, maybe it hides under your chair"); 458\& fatal ("no epoll found here, maybe it hides under your chair");
459.Ve 459.Ve
460.IP "ev_default_destroy ()" 4 460.IP "ev_default_destroy ()" 4
461.IX Item "ev_default_destroy ()" 461.IX Item "ev_default_destroy ()"
462Destroys the default loop again (frees all memory and kernel state 462Destroys the default loop again (frees all memory and kernel state
463etc.). This stops all registered event watchers (by not touching them in 463etc.). None of the active event watchers will be stopped in the normal
464any way whatsoever, although you cannot rely on this :). 464sense, so e.g. \f(CW\*(C`ev_is_active\*(C'\fR might still return true. It is your
465responsibility to either stop all watchers cleanly yoursef \fIbefore\fR
466calling this function, or cope with the fact afterwards (which is usually
467the easiest thing, youc na just ignore the watchers and/or \f(CW\*(C`free ()\*(C'\fR them
468for example).
465.IP "ev_loop_destroy (loop)" 4 469.IP "ev_loop_destroy (loop)" 4
466.IX Item "ev_loop_destroy (loop)" 470.IX Item "ev_loop_destroy (loop)"
467Like \f(CW\*(C`ev_default_destroy\*(C'\fR, but destroys an event loop created by an 471Like \f(CW\*(C`ev_default_destroy\*(C'\fR, but destroys an event loop created by an
468earlier call to \f(CW\*(C`ev_loop_new\*(C'\fR. 472earlier call to \f(CW\*(C`ev_loop_new\*(C'\fR.
469.IP "ev_default_fork ()" 4 473.IP "ev_default_fork ()" 4
645*)\*(C'\fR), and you can stop watching for events at any time by calling the 649*)\*(C'\fR), and you can stop watching for events at any time by calling the
646corresponding stop function (\f(CW\*(C`ev_<type>_stop (loop, watcher *)\*(C'\fR. 650corresponding stop function (\f(CW\*(C`ev_<type>_stop (loop, watcher *)\*(C'\fR.
647.PP 651.PP
648As long as your watcher is active (has been started but not stopped) you 652As long as your watcher is active (has been started but not stopped) you
649must not touch the values stored in it. Most specifically you must never 653must not touch the values stored in it. Most specifically you must never
650reinitialise it or call its set macro. 654reinitialise it or call its \f(CW\*(C`set\*(C'\fR macro.
651.PP
652You can check whether an event is active by calling the \f(CW\*(C`ev_is_active
653(watcher *)\*(C'\fR macro. To see whether an event is outstanding (but the
654callback for it has not been called yet) you can use the \f(CW\*(C`ev_is_pending
655(watcher *)\*(C'\fR macro.
656.PP 655.PP
657Each and every callback receives the event loop pointer as first, the 656Each and every callback receives the event loop pointer as first, the
658registered watcher structure as second, and a bitset of received events as 657registered watcher structure as second, and a bitset of received events as
659third argument. 658third argument.
660.PP 659.PP
718Libev will usually signal a few \*(L"dummy\*(R" events together with an error, 717Libev will usually signal a few \*(L"dummy\*(R" events together with an error,
719for example it might indicate that a fd is readable or writable, and if 718for example it might indicate that a fd is readable or writable, and if
720your callbacks is well-written it can just attempt the operation and cope 719your callbacks is well-written it can just attempt the operation and cope
721with the error from \fIread()\fR or \fIwrite()\fR. This will not work in multithreaded 720with the error from \fIread()\fR or \fIwrite()\fR. This will not work in multithreaded
722programs, though, so beware. 721programs, though, so beware.
722.Sh "\s-1SUMMARY\s0 \s-1OF\s0 \s-1GENERIC\s0 \s-1WATCHER\s0 \s-1FUNCTIONS\s0"
723.IX Subsection "SUMMARY OF GENERIC WATCHER FUNCTIONS"
724In the following description, \f(CW\*(C`TYPE\*(C'\fR stands for the watcher type,
725e.g. \f(CW\*(C`timer\*(C'\fR for \f(CW\*(C`ev_timer\*(C'\fR watchers and \f(CW\*(C`io\*(C'\fR for \f(CW\*(C`ev_io\*(C'\fR watchers.
726.ie n .IP """ev_init"" (ev_TYPE *watcher, callback)" 4
727.el .IP "\f(CWev_init\fR (ev_TYPE *watcher, callback)" 4
728.IX Item "ev_init (ev_TYPE *watcher, callback)"
729This macro initialises the generic portion of a watcher. The contents
730of the watcher object can be arbitrary (so \f(CW\*(C`malloc\*(C'\fR will do). Only
731the generic parts of the watcher are initialised, you \fIneed\fR to call
732the type-specific \f(CW\*(C`ev_TYPE_set\*(C'\fR macro afterwards to initialise the
733type-specific parts. For each type there is also a \f(CW\*(C`ev_TYPE_init\*(C'\fR macro
734which rolls both calls into one.
735.Sp
736You can reinitialise a watcher at any time as long as it has been stopped
737(or never started) and there are no pending events outstanding.
738.Sp
739The callbakc is always of type \f(CW\*(C`void (*)(ev_loop *loop, ev_TYPE *watcher,
740int revents)\*(C'\fR.
741.ie n .IP """ev_TYPE_set"" (ev_TYPE *, [args])" 4
742.el .IP "\f(CWev_TYPE_set\fR (ev_TYPE *, [args])" 4
743.IX Item "ev_TYPE_set (ev_TYPE *, [args])"
744This macro initialises the type-specific parts of a watcher. You need to
745call \f(CW\*(C`ev_init\*(C'\fR at least once before you call this macro, but you can
746call \f(CW\*(C`ev_TYPE_set\*(C'\fR any number of times. You must not, however, call this
747macro on a watcher that is active (it can be pending, however, which is a
748difference to the \f(CW\*(C`ev_init\*(C'\fR macro).
749.Sp
750Although some watcher types do not have type-specific arguments
751(e.g. \f(CW\*(C`ev_prepare\*(C'\fR) you still need to call its \f(CW\*(C`set\*(C'\fR macro.
752.ie n .IP """ev_TYPE_init"" (ev_TYPE *watcher, callback, [args])" 4
753.el .IP "\f(CWev_TYPE_init\fR (ev_TYPE *watcher, callback, [args])" 4
754.IX Item "ev_TYPE_init (ev_TYPE *watcher, callback, [args])"
755This convinience macro rolls both \f(CW\*(C`ev_init\*(C'\fR and \f(CW\*(C`ev_TYPE_set\*(C'\fR macro
756calls into a single call. This is the most convinient method to initialise
757a watcher. The same limitations apply, of course.
758.ie n .IP """ev_TYPE_start"" (loop *, ev_TYPE *watcher)" 4
759.el .IP "\f(CWev_TYPE_start\fR (loop *, ev_TYPE *watcher)" 4
760.IX Item "ev_TYPE_start (loop *, ev_TYPE *watcher)"
761Starts (activates) the given watcher. Only active watchers will receive
762events. If the watcher is already active nothing will happen.
763.ie n .IP """ev_TYPE_stop"" (loop *, ev_TYPE *watcher)" 4
764.el .IP "\f(CWev_TYPE_stop\fR (loop *, ev_TYPE *watcher)" 4
765.IX Item "ev_TYPE_stop (loop *, ev_TYPE *watcher)"
766Stops the given watcher again (if active) and clears the pending
767status. It is possible that stopped watchers are pending (for example,
768non-repeating timers are being stopped when they become pending), but
769\&\f(CW\*(C`ev_TYPE_stop\*(C'\fR ensures that the watcher is neither active nor pending. If
770you want to free or reuse the memory used by the watcher it is therefore a
771good idea to always call its \f(CW\*(C`ev_TYPE_stop\*(C'\fR function.
772.IP "bool ev_is_active (ev_TYPE *watcher)" 4
773.IX Item "bool ev_is_active (ev_TYPE *watcher)"
774Returns a true value iff the watcher is active (i.e. it has been started
775and not yet been stopped). As long as a watcher is active you must not modify
776it.
777.IP "bool ev_is_pending (ev_TYPE *watcher)" 4
778.IX Item "bool ev_is_pending (ev_TYPE *watcher)"
779Returns a true value iff the watcher is pending, (i.e. it has outstanding
780events but its callback has not yet been invoked). As long as a watcher
781is pending (but not active) you must not call an init function on it (but
782\&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe) and you must make sure the watcher is available to
783libev (e.g. you cnanot \f(CW\*(C`free ()\*(C'\fR it).
784.IP "callback = ev_cb (ev_TYPE *watcher)" 4
785.IX Item "callback = ev_cb (ev_TYPE *watcher)"
786Returns the callback currently set on the watcher.
787.IP "ev_cb_set (ev_TYPE *watcher, callback)" 4
788.IX Item "ev_cb_set (ev_TYPE *watcher, callback)"
789Change the callback. You can change the callback at virtually any time
790(modulo threads).
723.Sh "\s-1ASSOCIATING\s0 \s-1CUSTOM\s0 \s-1DATA\s0 \s-1WITH\s0 A \s-1WATCHER\s0" 791.Sh "\s-1ASSOCIATING\s0 \s-1CUSTOM\s0 \s-1DATA\s0 \s-1WITH\s0 A \s-1WATCHER\s0"
724.IX Subsection "ASSOCIATING CUSTOM DATA WITH A WATCHER" 792.IX Subsection "ASSOCIATING CUSTOM DATA WITH A WATCHER"
725Each watcher has, by default, a member \f(CW\*(C`void *data\*(C'\fR that you can change 793Each watcher has, by default, a member \f(CW\*(C`void *data\*(C'\fR that you can change
726and read at any time, libev will completely ignore it. This can be used 794and read at any time, libev will completely ignore it. This can be used
727to associate arbitrary data with your watcher. If you need more data and 795to associate arbitrary data with your watcher. If you need more data and
1205Example: *TODO*. 1273Example: *TODO*.
1206.ie n .Sh """ev_embed"" \- when one backend isn't enough" 1274.ie n .Sh """ev_embed"" \- when one backend isn't enough"
1207.el .Sh "\f(CWev_embed\fP \- when one backend isn't enough" 1275.el .Sh "\f(CWev_embed\fP \- when one backend isn't enough"
1208.IX Subsection "ev_embed - when one backend isn't enough" 1276.IX Subsection "ev_embed - when one backend isn't enough"
1209This is a rather advanced watcher type that lets you embed one event loop 1277This is a rather advanced watcher type that lets you embed one event loop
1210into another. 1278into another (currently only \f(CW\*(C`ev_io\*(C'\fR events are supported in the embedded
1279loop, other types of watchers might be handled in a delayed or incorrect
1280fashion and must not be used).
1211.PP 1281.PP
1212There are primarily two reasons you would want that: work around bugs and 1282There are primarily two reasons you would want that: work around bugs and
1213prioritise I/O. 1283prioritise I/O.
1214.PP 1284.PP
1215As an example for a bug workaround, the kqueue backend might only support 1285As an example for a bug workaround, the kqueue backend might only support
1223As for prioritising I/O: rarely you have the case where some fds have 1293As for prioritising I/O: rarely you have the case where some fds have
1224to be watched and handled very quickly (with low latency), and even 1294to be watched and handled very quickly (with low latency), and even
1225priorities and idle watchers might have too much overhead. In this case 1295priorities and idle watchers might have too much overhead. In this case
1226you would put all the high priority stuff in one loop and all the rest in 1296you would put all the high priority stuff in one loop and all the rest in
1227a second one, and embed the second one in the first. 1297a second one, and embed the second one in the first.
1298.PP
1299As long as the watcher is active, the callback will be invoked every time
1300there might be events pending in the embedded loop. The callback must then
1301call \f(CW\*(C`ev_embed_sweep (mainloop, watcher)\*(C'\fR to make a single sweep and invoke
1302their callbacks (you could also start an idle watcher to give the embedded
1303loop strictly lower priority for example). You can also set the callback
1304to \f(CW0\fR, in which case the embed watcher will automatically execute the
1305embedded loop sweep.
1228.PP 1306.PP
1229As long as the watcher is started it will automatically handle events. The 1307As long as the watcher is started it will automatically handle events. The
1230callback will be invoked whenever some events have been handled. You can 1308callback will be invoked whenever some events have been handled. You can
1231set the callback to \f(CW0\fR to avoid having to specify one if you are not 1309set the callback to \f(CW0\fR to avoid having to specify one if you are not
1232interested in that. 1310interested in that.
1267\& ev_embed_start (loop_hi, &embed); 1345\& ev_embed_start (loop_hi, &embed);
1268\& } 1346\& }
1269\& else 1347\& else
1270\& loop_lo = loop_hi; 1348\& loop_lo = loop_hi;
1271.Ve 1349.Ve
1272.IP "ev_embed_init (ev_embed *, callback, struct ev_loop *loop)" 4 1350.IP "ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)" 4
1273.IX Item "ev_embed_init (ev_embed *, callback, struct ev_loop *loop)" 1351.IX Item "ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)"
1274.PD 0 1352.PD 0
1275.IP "ev_embed_set (ev_embed *, callback, struct ev_loop *loop)" 4 1353.IP "ev_embed_set (ev_embed *, callback, struct ev_loop *embedded_loop)" 4
1276.IX Item "ev_embed_set (ev_embed *, callback, struct ev_loop *loop)" 1354.IX Item "ev_embed_set (ev_embed *, callback, struct ev_loop *embedded_loop)"
1277.PD 1355.PD
1278Configures the watcher to embed the given loop, which must be embeddable. 1356Configures the watcher to embed the given loop, which must be
1357embeddable. If the callback is \f(CW0\fR, then \f(CW\*(C`ev_embed_sweep\*(C'\fR will be
1358invoked automatically, otherwise it is the responsibility of the callback
1359to invoke it (it will continue to be called until the sweep has been done,
1360if you do not want thta, you need to temporarily stop the embed watcher).
1361.IP "ev_embed_sweep (loop, ev_embed *)" 4
1362.IX Item "ev_embed_sweep (loop, ev_embed *)"
1363Make a single, non-blocking sweep over the embedded loop. This works
1364similarly to \f(CW\*(C`ev_loop (embedded_loop, EVLOOP_NONBLOCK)\*(C'\fR, but in the most
1365apropriate way for embedded loops.
1279.SH "OTHER FUNCTIONS" 1366.SH "OTHER FUNCTIONS"
1280.IX Header "OTHER FUNCTIONS" 1367.IX Header "OTHER FUNCTIONS"
1281There are some other functions of possible interest. Described. Here. Now. 1368There are some other functions of possible interest. Described. Here. Now.
1282.IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4 1369.IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4
1283.IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 1370.IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)"
1312.Ve 1399.Ve
1313.Sp 1400.Sp
1314.Vb 1 1401.Vb 1
1315\& ev_once (STDIN_FILENO, EV_READ, 10., stdin_ready, 0); 1402\& ev_once (STDIN_FILENO, EV_READ, 10., stdin_ready, 0);
1316.Ve 1403.Ve
1317.IP "ev_feed_event (loop, watcher, int events)" 4 1404.IP "ev_feed_event (ev_loop *, watcher *, int revents)" 4
1318.IX Item "ev_feed_event (loop, watcher, int events)" 1405.IX Item "ev_feed_event (ev_loop *, watcher *, int revents)"
1319Feeds the given event set into the event loop, as if the specified event 1406Feeds the given event set into the event loop, as if the specified event
1320had happened for the specified watcher (which must be a pointer to an 1407had happened for the specified watcher (which must be a pointer to an
1321initialised but not necessarily started event watcher). 1408initialised but not necessarily started event watcher).
1322.IP "ev_feed_fd_event (loop, int fd, int revents)" 4 1409.IP "ev_feed_fd_event (ev_loop *, int fd, int revents)" 4
1323.IX Item "ev_feed_fd_event (loop, int fd, int revents)" 1410.IX Item "ev_feed_fd_event (ev_loop *, int fd, int revents)"
1324Feed an event on the given fd, as if a file descriptor backend detected 1411Feed an event on the given fd, as if a file descriptor backend detected
1325the given events it. 1412the given events it.
1326.IP "ev_feed_signal_event (loop, int signum)" 4 1413.IP "ev_feed_signal_event (ev_loop *loop, int signum)" 4
1327.IX Item "ev_feed_signal_event (loop, int signum)" 1414.IX Item "ev_feed_signal_event (ev_loop *loop, int signum)"
1328Feed an event as if the given signal occured (loop must be the default loop!). 1415Feed an event as if the given signal occured (\f(CW\*(C`loop\*(C'\fR must be the default
1416loop!).
1329.SH "LIBEVENT EMULATION" 1417.SH "LIBEVENT EMULATION"
1330.IX Header "LIBEVENT EMULATION" 1418.IX Header "LIBEVENT EMULATION"
1331Libev offers a compatibility emulation layer for libevent. It cannot 1419Libev offers a compatibility emulation layer for libevent. It cannot
1332emulate the internals of libevent, so here are some usage hints: 1420emulate the internals of libevent, so here are some usage hints:
1333.IP "* Use it by including <event.h>, as usual." 4 1421.IP "* Use it by including <event.h>, as usual." 4

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines