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.11 by root, Sat Nov 24 07:14:26 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines