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

Comparing libev/ev.3 (file contents):
Revision 1.77 by root, Sun Feb 15 01:44:40 2009 UTC vs.
Revision 1.78 by root, Tue Apr 28 00:50:19 2009 UTC

130.\} 130.\}
131.rm #[ #] #H #V #F C 131.rm #[ #] #H #V #F C
132.\" ======================================================================== 132.\" ========================================================================
133.\" 133.\"
134.IX Title "LIBEV 3" 134.IX Title "LIBEV 3"
135.TH LIBEV 3 "2009-02-06" "libev-3.53" "libev - high performance full featured event loop" 135.TH LIBEV 3 "2009-04-25" "libev-3.6" "libev - high performance full featured event loop"
136.\" For nroff, turn off justification. Always turn off hyphenation; it makes 136.\" For nroff, turn off justification. Always turn off hyphenation; it makes
137.\" way too many mistakes in technical documents. 137.\" way too many mistakes in technical documents.
138.if n .ad l 138.if n .ad l
139.nh 139.nh
140.SH "NAME" 140.SH "NAME"
201\& 201\&
202\& // unloop was called, so exit 202\& // unloop was called, so exit
203\& return 0; 203\& return 0;
204\& } 204\& }
205.Ve 205.Ve
206.SH "DESCRIPTION" 206.SH "ABOUT THIS DOCUMENT"
207.IX Header "DESCRIPTION" 207.IX Header "ABOUT THIS DOCUMENT"
208This document documents the libev software package.
209.PP
208The newest version of this document is also available as an html-formatted 210The newest version of this document is also available as an html-formatted
209web page you might find easier to navigate when reading it for the first 211web page you might find easier to navigate when reading it for the first
210time: <http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod>. 212time: <http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod>.
211.PP 213.PP
214While this document tries to be as complete as possible in documenting
215libev, its usage and the rationale behind its design, it is not a tutorial
216on event-based programming, nor will it introduce event-based programming
217with libev.
218.PP
219Familarity with event based programming techniques in general is assumed
220throughout this document.
221.SH "ABOUT LIBEV"
222.IX Header "ABOUT LIBEV"
212Libev is an event loop: you register interest in certain events (such as a 223Libev is an event loop: you register interest in certain events (such as a
213file descriptor being readable or a timeout occurring), and it will manage 224file descriptor being readable or a timeout occurring), and it will manage
214these event sources and provide your program with events. 225these event sources and provide your program with events.
215.PP 226.PP
216To do this, it must take more or less complete control over your process 227To do this, it must take more or less complete control over your process
246for multiple event loops, then all functions taking an initial argument of 257for multiple event loops, then all functions taking an initial argument of
247name \f(CW\*(C`loop\*(C'\fR (which is always of type \f(CW\*(C`ev_loop *\*(C'\fR) will not have 258name \f(CW\*(C`loop\*(C'\fR (which is always of type \f(CW\*(C`ev_loop *\*(C'\fR) will not have
248this argument. 259this argument.
249.Sh "\s-1TIME\s0 \s-1REPRESENTATION\s0" 260.Sh "\s-1TIME\s0 \s-1REPRESENTATION\s0"
250.IX Subsection "TIME REPRESENTATION" 261.IX Subsection "TIME REPRESENTATION"
251Libev represents time as a single floating point number, representing the 262Libev represents time as a single floating point number, representing
252(fractional) number of seconds since the (\s-1POSIX\s0) epoch (somewhere near 263the (fractional) number of seconds since the (\s-1POSIX\s0) epoch (somewhere
253the beginning of 1970, details are complicated, don't ask). This type is 264near the beginning of 1970, details are complicated, don't ask). This
254called \f(CW\*(C`ev_tstamp\*(C'\fR, which is what you should use too. It usually aliases 265type is called \f(CW\*(C`ev_tstamp\*(C'\fR, which is what you should use too. It usually
255to the \f(CW\*(C`double\*(C'\fR type in C, and when you need to do any calculations on 266aliases to the \f(CW\*(C`double\*(C'\fR type in C. When you need to do any calculations
256it, you should treat it as some floating point value. Unlike the name 267on it, you should treat it as some floating point value. Unlike the name
257component \f(CW\*(C`stamp\*(C'\fR might indicate, it is also used for time differences 268component \f(CW\*(C`stamp\*(C'\fR might indicate, it is also used for time differences
258throughout libev. 269throughout libev.
259.SH "ERROR HANDLING" 270.SH "ERROR HANDLING"
260.IX Header "ERROR HANDLING" 271.IX Header "ERROR HANDLING"
261Libev knows three classes of errors: operating system errors, usage errors 272Libev knows three classes of errors: operating system errors, usage errors
760This function is rarely useful, but when some event callback runs for a 771This function is rarely useful, but when some event callback runs for a
761very long time without entering the event loop, updating libev's idea of 772very long time without entering the event loop, updating libev's idea of
762the current time is a good idea. 773the current time is a good idea.
763.Sp 774.Sp
764See also \*(L"The special problem of time updates\*(R" in the \f(CW\*(C`ev_timer\*(C'\fR section. 775See also \*(L"The special problem of time updates\*(R" in the \f(CW\*(C`ev_timer\*(C'\fR section.
776.IP "ev_suspend (loop)" 4
777.IX Item "ev_suspend (loop)"
778.PD 0
779.IP "ev_resume (loop)" 4
780.IX Item "ev_resume (loop)"
781.PD
782These two functions suspend and resume a loop, for use when the loop is
783not used for a while and timeouts should not be processed.
784.Sp
785A typical use case would be an interactive program such as a game: When
786the user presses \f(CW\*(C`^Z\*(C'\fR to suspend the game and resumes it an hour later it
787would be best to handle timeouts as if no time had actually passed while
788the program was suspended. This can be achieved by calling \f(CW\*(C`ev_suspend\*(C'\fR
789in your \f(CW\*(C`SIGTSTP\*(C'\fR handler, sending yourself a \f(CW\*(C`SIGSTOP\*(C'\fR and calling
790\&\f(CW\*(C`ev_resume\*(C'\fR directly afterwards to resume timer processing.
791.Sp
792Effectively, all \f(CW\*(C`ev_timer\*(C'\fR watchers will be delayed by the time spend
793between \f(CW\*(C`ev_suspend\*(C'\fR and \f(CW\*(C`ev_resume\*(C'\fR, and all \f(CW\*(C`ev_periodic\*(C'\fR watchers
794will be rescheduled (that is, they will lose any events that would have
795occured while suspended).
796.Sp
797After calling \f(CW\*(C`ev_suspend\*(C'\fR you \fBmust not\fR call \fIany\fR function on the
798given loop other than \f(CW\*(C`ev_resume\*(C'\fR, and you \fBmust not\fR call \f(CW\*(C`ev_resume\*(C'\fR
799without a previous call to \f(CW\*(C`ev_suspend\*(C'\fR.
800.Sp
801Calling \f(CW\*(C`ev_suspend\*(C'\fR/\f(CW\*(C`ev_resume\*(C'\fR has the side effect of updating the
802event loop time (see \f(CW\*(C`ev_now_update\*(C'\fR).
765.IP "ev_loop (loop, int flags)" 4 803.IP "ev_loop (loop, int flags)" 4
766.IX Item "ev_loop (loop, int flags)" 804.IX Item "ev_loop (loop, int flags)"
767Finally, this is it, the event handler. This function usually is called 805Finally, this is it, the event handler. This function usually is called
768after you initialised all your watchers and you want to start handling 806after you initialised all your watchers and you want to start handling
769events. 807events.
856.Sp 894.Sp
857If you have a watcher you never unregister that should not keep \f(CW\*(C`ev_loop\*(C'\fR 895If you have a watcher you never unregister that should not keep \f(CW\*(C`ev_loop\*(C'\fR
858from returning, call \fIev_unref()\fR after starting, and \fIev_ref()\fR before 896from returning, call \fIev_unref()\fR after starting, and \fIev_ref()\fR before
859stopping it. 897stopping it.
860.Sp 898.Sp
861As an example, libev itself uses this for its internal signal pipe: It is 899As an example, libev itself uses this for its internal signal pipe: It
862not visible to the libev user and should not keep \f(CW\*(C`ev_loop\*(C'\fR from exiting 900is not visible to the libev user and should not keep \f(CW\*(C`ev_loop\*(C'\fR from
863if no event watchers registered by it are active. It is also an excellent 901exiting if no event watchers registered by it are active. It is also an
864way to do this for generic recurring timers or from within third-party 902excellent way to do this for generic recurring timers or from within
865libraries. Just remember to \fIunref after start\fR and \fIref before stop\fR 903third-party libraries. Just remember to \fIunref after start\fR and \fIref
866(but only if the watcher wasn't active before, or was active before, 904before stop\fR (but only if the watcher wasn't active before, or was active
867respectively). 905before, respectively. Note also that libev might stop watchers itself
906(e.g. non-repeating timers) in which case you have to \f(CW\*(C`ev_ref\*(C'\fR
907in the callback).
868.Sp 908.Sp
869Example: Create a signal watcher, but keep it from keeping \f(CW\*(C`ev_loop\*(C'\fR 909Example: Create a signal watcher, but keep it from keeping \f(CW\*(C`ev_loop\*(C'\fR
870running when nothing else is active. 910running when nothing else is active.
871.Sp 911.Sp
872.Vb 4 912.Vb 4
1060\&\f(CW\*(C`ev_fork\*(C'\fR). 1100\&\f(CW\*(C`ev_fork\*(C'\fR).
1061.ie n .IP """EV_ASYNC""" 4 1101.ie n .IP """EV_ASYNC""" 4
1062.el .IP "\f(CWEV_ASYNC\fR" 4 1102.el .IP "\f(CWEV_ASYNC\fR" 4
1063.IX Item "EV_ASYNC" 1103.IX Item "EV_ASYNC"
1064The given async watcher has been asynchronously notified (see \f(CW\*(C`ev_async\*(C'\fR). 1104The given async watcher has been asynchronously notified (see \f(CW\*(C`ev_async\*(C'\fR).
1105.ie n .IP """EV_CUSTOM""" 4
1106.el .IP "\f(CWEV_CUSTOM\fR" 4
1107.IX Item "EV_CUSTOM"
1108Not ever sent (or otherwise used) by libev itself, but can be freely used
1109by libev users to signal watchers (e.g. via \f(CW\*(C`ev_feed_event\*(C'\fR).
1065.ie n .IP """EV_ERROR""" 4 1110.ie n .IP """EV_ERROR""" 4
1066.el .IP "\f(CWEV_ERROR\fR" 4 1111.el .IP "\f(CWEV_ERROR\fR" 4
1067.IX Item "EV_ERROR" 1112.IX Item "EV_ERROR"
1068An unspecified error has occurred, the watcher has been stopped. This might 1113An unspecified error has occurred, the watcher has been stopped. This might
1069happen because the watcher could not be properly started because libev 1114happen because the watcher could not be properly started because libev
1184integer between \f(CW\*(C`EV_MAXPRI\*(C'\fR (default: \f(CW2\fR) and \f(CW\*(C`EV_MINPRI\*(C'\fR 1229integer between \f(CW\*(C`EV_MAXPRI\*(C'\fR (default: \f(CW2\fR) and \f(CW\*(C`EV_MINPRI\*(C'\fR
1185(default: \f(CW\*(C`\-2\*(C'\fR). Pending watchers with higher priority will be invoked 1230(default: \f(CW\*(C`\-2\*(C'\fR). Pending watchers with higher priority will be invoked
1186before watchers with lower priority, but priority will not keep watchers 1231before watchers with lower priority, but priority will not keep watchers
1187from being executed (except for \f(CW\*(C`ev_idle\*(C'\fR watchers). 1232from being executed (except for \f(CW\*(C`ev_idle\*(C'\fR watchers).
1188.Sp 1233.Sp
1189This means that priorities are \fIonly\fR used for ordering callback
1190invocation after new events have been received. This is useful, for
1191example, to reduce latency after idling, or more often, to bind two
1192watchers on the same event and make sure one is called first.
1193.Sp
1194If you need to suppress invocation when higher priority events are pending 1234If you need to suppress invocation when higher priority events are pending
1195you need to look at \f(CW\*(C`ev_idle\*(C'\fR watchers, which provide this functionality. 1235you need to look at \f(CW\*(C`ev_idle\*(C'\fR watchers, which provide this functionality.
1196.Sp 1236.Sp
1197You \fImust not\fR change the priority of a watcher as long as it is active or 1237You \fImust not\fR change the priority of a watcher as long as it is active or
1198pending. 1238pending.
1199.Sp
1200The default priority used by watchers when no priority has been set is
1201always \f(CW0\fR, which is supposed to not be too high and not be too low :).
1202.Sp 1239.Sp
1203Setting a priority outside the range of \f(CW\*(C`EV_MINPRI\*(C'\fR to \f(CW\*(C`EV_MAXPRI\*(C'\fR is 1240Setting a priority outside the range of \f(CW\*(C`EV_MINPRI\*(C'\fR to \f(CW\*(C`EV_MAXPRI\*(C'\fR is
1204fine, as long as you do not mind that the priority value you query might 1241fine, as long as you do not mind that the priority value you query might
1205or might not have been clamped to the valid range. 1242or might not have been clamped to the valid range.
1243.Sp
1244The default priority used by watchers when no priority has been set is
1245always \f(CW0\fR, which is supposed to not be too high and not be too low :).
1246.Sp
1247See \*(L"\s-1WATCHER\s0 \s-1PRIORITY\s0 \s-1MODELS\s0\*(R", below, for a more thorough treatment of
1248priorities.
1206.IP "ev_invoke (loop, ev_TYPE *watcher, int revents)" 4 1249.IP "ev_invoke (loop, ev_TYPE *watcher, int revents)" 4
1207.IX Item "ev_invoke (loop, ev_TYPE *watcher, int revents)" 1250.IX Item "ev_invoke (loop, ev_TYPE *watcher, int revents)"
1208Invoke the \f(CW\*(C`watcher\*(C'\fR with the given \f(CW\*(C`loop\*(C'\fR and \f(CW\*(C`revents\*(C'\fR. Neither 1251Invoke the \f(CW\*(C`watcher\*(C'\fR with the given \f(CW\*(C`loop\*(C'\fR and \f(CW\*(C`revents\*(C'\fR. Neither
1209\&\f(CW\*(C`loop\*(C'\fR nor \f(CW\*(C`revents\*(C'\fR need to be valid as long as the watcher callback 1252\&\f(CW\*(C`loop\*(C'\fR nor \f(CW\*(C`revents\*(C'\fR need to be valid as long as the watcher callback
1210can deal with that fact, as both are simply passed through to the 1253can deal with that fact, as both are simply passed through to the
1287\& { 1330\& {
1288\& struct my_biggy big = (struct my_biggy * 1331\& struct my_biggy big = (struct my_biggy *
1289\& (((char *)w) \- offsetof (struct my_biggy, t2)); 1332\& (((char *)w) \- offsetof (struct my_biggy, t2));
1290\& } 1333\& }
1291.Ve 1334.Ve
1335.Sh "\s-1WATCHER\s0 \s-1PRIORITY\s0 \s-1MODELS\s0"
1336.IX Subsection "WATCHER PRIORITY MODELS"
1337Many event loops support \fIwatcher priorities\fR, which are usually small
1338integers that influence the ordering of event callback invocation
1339between watchers in some way, all else being equal.
1340.PP
1341In libev, Watcher priorities can be set using \f(CW\*(C`ev_set_priority\*(C'\fR. See its
1342description for the more technical details such as the actual priority
1343range.
1344.PP
1345There are two common ways how these these priorities are being interpreted
1346by event loops:
1347.PP
1348In the more common lock-out model, higher priorities \*(L"lock out\*(R" invocation
1349of lower priority watchers, which means as long as higher priority
1350watchers receive events, lower priority watchers are not being invoked.
1351.PP
1352The less common only-for-ordering model uses priorities solely to order
1353callback invocation within a single event loop iteration: Higher priority
1354watchers are invoked before lower priority ones, but they all get invoked
1355before polling for new events.
1356.PP
1357Libev uses the second (only-for-ordering) model for all its watchers
1358except for idle watchers (which use the lock-out model).
1359.PP
1360The rationale behind this is that implementing the lock-out model for
1361watchers is not well supported by most kernel interfaces, and most event
1362libraries will just poll for the same events again and again as long as
1363their callbacks have not been executed, which is very inefficient in the
1364common case of one high-priority watcher locking out a mass of lower
1365priority ones.
1366.PP
1367Static (ordering) priorities are most useful when you have two or more
1368watchers handling the same resource: a typical usage example is having an
1369\&\f(CW\*(C`ev_io\*(C'\fR watcher to receive data, and an associated \f(CW\*(C`ev_timer\*(C'\fR to handle
1370timeouts. Under load, data might be received while the program handles
1371other jobs, but since timers normally get invoked first, the timeout
1372handler will be executed before checking for data. In that case, giving
1373the timer a lower priority than the I/O watcher ensures that I/O will be
1374handled first even under adverse conditions (which is usually, but not
1375always, what you want).
1376.PP
1377Since idle watchers use the \*(L"lock-out\*(R" model, meaning that idle watchers
1378will only be executed when no same or higher priority watchers have
1379received events, they can be used to implement the \*(L"lock-out\*(R" model when
1380required.
1381.PP
1382For example, to emulate how many other event libraries handle priorities,
1383you can associate an \f(CW\*(C`ev_idle\*(C'\fR watcher to each such watcher, and in
1384the normal watcher callback, you just start the idle watcher. The real
1385processing is done in the idle watcher callback. This causes libev to
1386continously poll and process kernel event data for the watcher, but when
1387the lock-out case is known to be rare (which in turn is rare :), this is
1388workable.
1389.PP
1390Usually, however, the lock-out model implemented that way will perform
1391miserably under the type of load it was designed to handle. In that case,
1392it might be preferable to stop the real watcher before starting the
1393idle watcher, so the kernel will not have to process the event in case
1394the actual processing will be delayed for considerable time.
1395.PP
1396Here is an example of an I/O watcher that should run at a strictly lower
1397priority than the default, and which should only process data when no
1398other events are pending:
1399.PP
1400.Vb 2
1401\& ev_idle idle; // actual processing watcher
1402\& ev_io io; // actual event watcher
1403\&
1404\& static void
1405\& io_cb (EV_P_ ev_io *w, int revents)
1406\& {
1407\& // stop the I/O watcher, we received the event, but
1408\& // are not yet ready to handle it.
1409\& ev_io_stop (EV_A_ w);
1410\&
1411\& // start the idle watcher to ahndle the actual event.
1412\& // it will not be executed as long as other watchers
1413\& // with the default priority are receiving events.
1414\& ev_idle_start (EV_A_ &idle);
1415\& }
1416\&
1417\& static void
1418\& idle\-cb (EV_P_ ev_idle *w, int revents)
1419\& {
1420\& // actual processing
1421\& read (STDIN_FILENO, ...);
1422\&
1423\& // have to start the I/O watcher again, as
1424\& // we have handled the event
1425\& ev_io_start (EV_P_ &io);
1426\& }
1427\&
1428\& // initialisation
1429\& ev_idle_init (&idle, idle_cb);
1430\& ev_io_init (&io, io_cb, STDIN_FILENO, EV_READ);
1431\& ev_io_start (EV_DEFAULT_ &io);
1432.Ve
1433.PP
1434In the \*(L"real\*(R" world, it might also be beneficial to start a timer, so that
1435low-priority connections can not be locked out forever under load. This
1436enables your program to keep a lower latency for important connections
1437during short periods of high load, while not completely locking out less
1438important ones.
1292.SH "WATCHER TYPES" 1439.SH "WATCHER TYPES"
1293.IX Header "WATCHER TYPES" 1440.IX Header "WATCHER TYPES"
1294This section describes each watcher in detail, but will not repeat 1441This section describes each watcher in detail, but will not repeat
1295information given in the last section. Any initialisation/set macros, 1442information given in the last section. Any initialisation/set macros,
1296functions and members specific to the watcher type are explained. 1443functions and members specific to the watcher type are explained.
1319descriptors to non-blocking mode is also usually a good idea (but not 1466descriptors to non-blocking mode is also usually a good idea (but not
1320required if you know what you are doing). 1467required if you know what you are doing).
1321.PP 1468.PP
1322If you cannot use non-blocking mode, then force the use of a 1469If you cannot use non-blocking mode, then force the use of a
1323known-to-be-good backend (at the time of this writing, this includes only 1470known-to-be-good backend (at the time of this writing, this includes only
1324\&\f(CW\*(C`EVBACKEND_SELECT\*(C'\fR and \f(CW\*(C`EVBACKEND_POLL\*(C'\fR). 1471\&\f(CW\*(C`EVBACKEND_SELECT\*(C'\fR and \f(CW\*(C`EVBACKEND_POLL\*(C'\fR). The same applies to file
1472descriptors for which non-blocking operation makes no sense (such as
1473files) \- libev doesn't guarentee any specific behaviour in that case.
1325.PP 1474.PP
1326Another thing you have to watch out for is that it is quite easy to 1475Another thing you have to watch out for is that it is quite easy to
1327receive \*(L"spurious\*(R" readiness notifications, that is your callback might 1476receive \*(L"spurious\*(R" readiness notifications, that is your callback might
1328be called with \f(CW\*(C`EV_READ\*(C'\fR but a subsequent \f(CW\*(C`read\*(C'\fR(2) will actually block 1477be called with \f(CW\*(C`EV_READ\*(C'\fR but a subsequent \f(CW\*(C`read\*(C'\fR(2) will actually block
1329because there is no data. Not only are some backends known to create a 1478because there is no data. Not only are some backends known to create a
1451year, it will still time out after (roughly) one hour. \*(L"Roughly\*(R" because 1600year, it will still time out after (roughly) one hour. \*(L"Roughly\*(R" because
1452detecting time jumps is hard, and some inaccuracies are unavoidable (the 1601detecting time jumps is hard, and some inaccuracies are unavoidable (the
1453monotonic clock option helps a lot here). 1602monotonic clock option helps a lot here).
1454.PP 1603.PP
1455The callback is guaranteed to be invoked only \fIafter\fR its timeout has 1604The callback is guaranteed to be invoked only \fIafter\fR its timeout has
1456passed, but if multiple timers become ready during the same loop iteration 1605passed (not \fIat\fR, so on systems with very low-resolution clocks this
1457then order of execution is undefined. 1606might introduce a small delay). If multiple timers become ready during the
1607same loop iteration then the ones with earlier time-out values are invoked
1608before ones with later time-out values (but this is no longer true when a
1609callback calls \f(CW\*(C`ev_loop\*(C'\fR recursively).
1458.PP 1610.PP
1459\fIBe smart about timeouts\fR 1611\fIBe smart about timeouts\fR
1460.IX Subsection "Be smart about timeouts" 1612.IX Subsection "Be smart about timeouts"
1461.PP 1613.PP
1462Many real-world problems involve some kind of timeout, usually for error 1614Many real-world problems involve some kind of timeout, usually for error
1743.el .Sh "\f(CWev_periodic\fP \- to cron or not to cron?" 1895.el .Sh "\f(CWev_periodic\fP \- to cron or not to cron?"
1744.IX Subsection "ev_periodic - to cron or not to cron?" 1896.IX Subsection "ev_periodic - to cron or not to cron?"
1745Periodic watchers are also timers of a kind, but they are very versatile 1897Periodic watchers are also timers of a kind, but they are very versatile
1746(and unfortunately a bit complex). 1898(and unfortunately a bit complex).
1747.PP 1899.PP
1748Unlike \f(CW\*(C`ev_timer\*(C'\fR's, they are not based on real time (or relative time) 1900Unlike \f(CW\*(C`ev_timer\*(C'\fR, periodic watchers are not based on real time (or
1749but on wall clock time (absolute time). You can tell a periodic watcher 1901relative time, the physical time that passes) but on wall clock time
1750to trigger after some specific point in time. For example, if you tell a 1902(absolute time, the thing you can read on your calender or clock). The
1751periodic watcher to trigger in 10 seconds (by specifying e.g. \f(CW\*(C`ev_now () 1903difference is that wall clock time can run faster or slower than real
1752+ 10.\*(C'\fR, that is, an absolute time not a delay) and then reset your system 1904time, and time jumps are not uncommon (e.g. when you adjust your
1753clock to January of the previous year, then it will take more than year 1905wrist-watch).
1754to trigger the event (unlike an \f(CW\*(C`ev_timer\*(C'\fR, which would still trigger
1755roughly 10 seconds later as it uses a relative timeout).
1756.PP 1906.PP
1907You can tell a periodic watcher to trigger after some specific point
1908in time: for example, if you tell a periodic watcher to trigger \*(L"in 10
1909seconds\*(R" (by specifying e.g. \f(CW\*(C`ev_now () + 10.\*(C'\fR, that is, an absolute time
1910not a delay) and then reset your system clock to January of the previous
1911year, then it will take a year or more to trigger the event (unlike an
1912\&\f(CW\*(C`ev_timer\*(C'\fR, which would still trigger roughly 10 seconds after starting
1913it, as it uses a relative timeout).
1914.PP
1757\&\f(CW\*(C`ev_periodic\*(C'\fRs can also be used to implement vastly more complex timers, 1915\&\f(CW\*(C`ev_periodic\*(C'\fR watchers can also be used to implement vastly more complex
1758such as triggering an event on each \*(L"midnight, local time\*(R", or other 1916timers, such as triggering an event on each \*(L"midnight, local time\*(R", or
1759complicated rules. 1917other complicated rules. This cannot be done with \f(CW\*(C`ev_timer\*(C'\fR watchers, as
1918those cannot react to time jumps.
1760.PP 1919.PP
1761As with timers, the callback is guaranteed to be invoked only when the 1920As with timers, the callback is guaranteed to be invoked only when the
1762time (\f(CW\*(C`at\*(C'\fR) has passed, but if multiple periodic timers become ready 1921point in time where it is supposed to trigger has passed. If multiple
1763during the same loop iteration, then order of execution is undefined. 1922timers become ready during the same loop iteration then the ones with
1923earlier time-out values are invoked before ones with later time-out values
1924(but this is no longer true when a callback calls \f(CW\*(C`ev_loop\*(C'\fR recursively).
1764.PP 1925.PP
1765\fIWatcher-Specific Functions and Data Members\fR 1926\fIWatcher-Specific Functions and Data Members\fR
1766.IX Subsection "Watcher-Specific Functions and Data Members" 1927.IX Subsection "Watcher-Specific Functions and Data Members"
1767.IP "ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb)" 4 1928.IP "ev_periodic_init (ev_periodic *, callback, ev_tstamp offset, ev_tstamp interval, reschedule_cb)" 4
1768.IX Item "ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb)" 1929.IX Item "ev_periodic_init (ev_periodic *, callback, ev_tstamp offset, ev_tstamp interval, reschedule_cb)"
1769.PD 0 1930.PD 0
1770.IP "ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb)" 4 1931.IP "ev_periodic_set (ev_periodic *, ev_tstamp offset, ev_tstamp interval, reschedule_cb)" 4
1771.IX Item "ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb)" 1932.IX Item "ev_periodic_set (ev_periodic *, ev_tstamp offset, ev_tstamp interval, reschedule_cb)"
1772.PD 1933.PD
1773Lots of arguments, lets sort it out... There are basically three modes of 1934Lots of arguments, let's sort it out... There are basically three modes of
1774operation, and we will explain them from simplest to most complex: 1935operation, and we will explain them from simplest to most complex:
1775.RS 4 1936.RS 4
1776.IP "\(bu" 4 1937.IP "\(bu" 4
1777absolute timer (at = time, interval = reschedule_cb = 0) 1938absolute timer (offset = absolute time, interval = 0, reschedule_cb = 0)
1778.Sp 1939.Sp
1779In this configuration the watcher triggers an event after the wall clock 1940In this configuration the watcher triggers an event after the wall clock
1780time \f(CW\*(C`at\*(C'\fR has passed. It will not repeat and will not adjust when a time 1941time \f(CW\*(C`offset\*(C'\fR has passed. It will not repeat and will not adjust when a
1781jump occurs, that is, if it is to be run at January 1st 2011 then it will 1942time jump occurs, that is, if it is to be run at January 1st 2011 then it
1782only run when the system clock reaches or surpasses this time. 1943will be stopped and invoked when the system clock reaches or surpasses
1944this point in time.
1783.IP "\(bu" 4 1945.IP "\(bu" 4
1784repeating interval timer (at = offset, interval > 0, reschedule_cb = 0) 1946repeating interval timer (offset = offset within interval, interval > 0, reschedule_cb = 0)
1785.Sp 1947.Sp
1786In this mode the watcher will always be scheduled to time out at the next 1948In this mode the watcher will always be scheduled to time out at the next
1787\&\f(CW\*(C`at + N * interval\*(C'\fR time (for some integer N, which can also be negative) 1949\&\f(CW\*(C`offset + N * interval\*(C'\fR time (for some integer N, which can also be
1788and then repeat, regardless of any time jumps. 1950negative) and then repeat, regardless of any time jumps. The \f(CW\*(C`offset\*(C'\fR
1951argument is merely an offset into the \f(CW\*(C`interval\*(C'\fR periods.
1789.Sp 1952.Sp
1790This can be used to create timers that do not drift with respect to the 1953This can be used to create timers that do not drift with respect to the
1791system clock, for example, here is a \f(CW\*(C`ev_periodic\*(C'\fR that triggers each 1954system clock, for example, here is an \f(CW\*(C`ev_periodic\*(C'\fR that triggers each
1792hour, on the hour: 1955hour, on the hour (with respect to \s-1UTC\s0):
1793.Sp 1956.Sp
1794.Vb 1 1957.Vb 1
1795\& ev_periodic_set (&periodic, 0., 3600., 0); 1958\& ev_periodic_set (&periodic, 0., 3600., 0);
1796.Ve 1959.Ve
1797.Sp 1960.Sp
1800full hour (\s-1UTC\s0), or more correctly, when the system time is evenly divisible 1963full hour (\s-1UTC\s0), or more correctly, when the system time is evenly divisible
1801by 3600. 1964by 3600.
1802.Sp 1965.Sp
1803Another way to think about it (for the mathematically inclined) is that 1966Another way to think about it (for the mathematically inclined) is that
1804\&\f(CW\*(C`ev_periodic\*(C'\fR will try to run the callback in this mode at the next possible 1967\&\f(CW\*(C`ev_periodic\*(C'\fR will try to run the callback in this mode at the next possible
1805time where \f(CW\*(C`time = at (mod interval)\*(C'\fR, regardless of any time jumps. 1968time where \f(CW\*(C`time = offset (mod interval)\*(C'\fR, regardless of any time jumps.
1806.Sp 1969.Sp
1807For numerical stability it is preferable that the \f(CW\*(C`at\*(C'\fR value is near 1970For numerical stability it is preferable that the \f(CW\*(C`offset\*(C'\fR value is near
1808\&\f(CW\*(C`ev_now ()\*(C'\fR (the current time), but there is no range requirement for 1971\&\f(CW\*(C`ev_now ()\*(C'\fR (the current time), but there is no range requirement for
1809this value, and in fact is often specified as zero. 1972this value, and in fact is often specified as zero.
1810.Sp 1973.Sp
1811Note also that there is an upper limit to how often a timer can fire (\s-1CPU\s0 1974Note also that there is an upper limit to how often a timer can fire (\s-1CPU\s0
1812speed for example), so if \f(CW\*(C`interval\*(C'\fR is very small then timing stability 1975speed for example), so if \f(CW\*(C`interval\*(C'\fR is very small then timing stability
1813will of course deteriorate. Libev itself tries to be exact to be about one 1976will of course deteriorate. Libev itself tries to be exact to be about one
1814millisecond (if the \s-1OS\s0 supports it and the machine is fast enough). 1977millisecond (if the \s-1OS\s0 supports it and the machine is fast enough).
1815.IP "\(bu" 4 1978.IP "\(bu" 4
1816manual reschedule mode (at and interval ignored, reschedule_cb = callback) 1979manual reschedule mode (offset ignored, interval ignored, reschedule_cb = callback)
1817.Sp 1980.Sp
1818In this mode the values for \f(CW\*(C`interval\*(C'\fR and \f(CW\*(C`at\*(C'\fR are both being 1981In this mode the values for \f(CW\*(C`interval\*(C'\fR and \f(CW\*(C`offset\*(C'\fR are both being
1819ignored. Instead, each time the periodic watcher gets scheduled, the 1982ignored. Instead, each time the periodic watcher gets scheduled, the
1820reschedule callback will be called with the watcher as first, and the 1983reschedule callback will be called with the watcher as first, and the
1821current time as second argument. 1984current time as second argument.
1822.Sp 1985.Sp
1823\&\s-1NOTE:\s0 \fIThis callback \s-1MUST\s0 \s-1NOT\s0 stop or destroy any periodic watcher, 1986\&\s-1NOTE:\s0 \fIThis callback \s-1MUST\s0 \s-1NOT\s0 stop or destroy any periodic watcher, ever,
1824ever, or make \s-1ANY\s0 event loop modifications whatsoever\fR. 1987or make \s-1ANY\s0 other event loop modifications whatsoever, unless explicitly
1988allowed by documentation here\fR.
1825.Sp 1989.Sp
1826If you need to stop it, return \f(CW\*(C`now + 1e30\*(C'\fR (or so, fudge fudge) and stop 1990If you need to stop it, return \f(CW\*(C`now + 1e30\*(C'\fR (or so, fudge fudge) and stop
1827it afterwards (e.g. by starting an \f(CW\*(C`ev_prepare\*(C'\fR watcher, which is the 1991it afterwards (e.g. by starting an \f(CW\*(C`ev_prepare\*(C'\fR watcher, which is the
1828only event loop modification you are allowed to do). 1992only event loop modification you are allowed to do).
1829.Sp 1993.Sp
1860when you changed some parameters or the reschedule callback would return 2024when you changed some parameters or the reschedule callback would return
1861a different time than the last time it was called (e.g. in a crond like 2025a different time than the last time it was called (e.g. in a crond like
1862program when the crontabs have changed). 2026program when the crontabs have changed).
1863.IP "ev_tstamp ev_periodic_at (ev_periodic *)" 4 2027.IP "ev_tstamp ev_periodic_at (ev_periodic *)" 4
1864.IX Item "ev_tstamp ev_periodic_at (ev_periodic *)" 2028.IX Item "ev_tstamp ev_periodic_at (ev_periodic *)"
1865When active, returns the absolute time that the watcher is supposed to 2029When active, returns the absolute time that the watcher is supposed
1866trigger next. 2030to trigger next. This is not the same as the \f(CW\*(C`offset\*(C'\fR argument to
2031\&\f(CW\*(C`ev_periodic_set\*(C'\fR, but indeed works even in interval and manual
2032rescheduling modes.
1867.IP "ev_tstamp offset [read\-write]" 4 2033.IP "ev_tstamp offset [read\-write]" 4
1868.IX Item "ev_tstamp offset [read-write]" 2034.IX Item "ev_tstamp offset [read-write]"
1869When repeating, this contains the offset value, otherwise this is the 2035When repeating, this contains the offset value, otherwise this is the
1870absolute point in time (the \f(CW\*(C`at\*(C'\fR value passed to \f(CW\*(C`ev_periodic_set\*(C'\fR). 2036absolute point in time (the \f(CW\*(C`offset\*(C'\fR value passed to \f(CW\*(C`ev_periodic_set\*(C'\fR,
2037although libev might modify this value for better numerical stability).
1871.Sp 2038.Sp
1872Can be modified any time, but changes only take effect when the periodic 2039Can be modified any time, but changes only take effect when the periodic
1873timer fires or \f(CW\*(C`ev_periodic_again\*(C'\fR is being called. 2040timer fires or \f(CW\*(C`ev_periodic_again\*(C'\fR is being called.
1874.IP "ev_tstamp interval [read\-write]" 4 2041.IP "ev_tstamp interval [read\-write]" 4
1875.IX Item "ev_tstamp interval [read-write]" 2042.IX Item "ev_tstamp interval [read-write]"
2327\&\*(L"pseudo-background processing\*(R", or delay processing stuff to after the 2494\&\*(L"pseudo-background processing\*(R", or delay processing stuff to after the
2328event loop has handled all outstanding events. 2495event loop has handled all outstanding events.
2329.PP 2496.PP
2330\fIWatcher-Specific Functions and Data Members\fR 2497\fIWatcher-Specific Functions and Data Members\fR
2331.IX Subsection "Watcher-Specific Functions and Data Members" 2498.IX Subsection "Watcher-Specific Functions and Data Members"
2332.IP "ev_idle_init (ev_signal *, callback)" 4 2499.IP "ev_idle_init (ev_idle *, callback)" 4
2333.IX Item "ev_idle_init (ev_signal *, callback)" 2500.IX Item "ev_idle_init (ev_idle *, callback)"
2334Initialises and configures the idle watcher \- it has no parameters of any 2501Initialises and configures the idle watcher \- it has no parameters of any
2335kind. There is a \f(CW\*(C`ev_idle_set\*(C'\fR macro, but using it is utterly pointless, 2502kind. There is a \f(CW\*(C`ev_idle_set\*(C'\fR macro, but using it is utterly pointless,
2336believe me. 2503believe me.
2337.PP 2504.PP
2338\fIExamples\fR 2505\fIExamples\fR
2698event loop blocks next and before \f(CW\*(C`ev_check\*(C'\fR watchers are being called, 2865event loop blocks next and before \f(CW\*(C`ev_check\*(C'\fR watchers are being called,
2699and only in the child after the fork. If whoever good citizen calling 2866and only in the child after the fork. If whoever good citizen calling
2700\&\f(CW\*(C`ev_default_fork\*(C'\fR cheats and calls it in the wrong process, the fork 2867\&\f(CW\*(C`ev_default_fork\*(C'\fR cheats and calls it in the wrong process, the fork
2701handlers will be invoked, too, of course. 2868handlers will be invoked, too, of course.
2702.PP 2869.PP
2870\fIThe special problem of life after fork \- how is it possible?\fR
2871.IX Subsection "The special problem of life after fork - how is it possible?"
2872.PP
2873Most uses of \f(CW\*(C`fork()\*(C'\fR consist of forking, then some simple calls to ste
2874up/change the process environment, followed by a call to \f(CW\*(C`exec()\*(C'\fR. This
2875sequence should be handled by libev without any problems.
2876.PP
2877This changes when the application actually wants to do event handling
2878in the child, or both parent in child, in effect \*(L"continuing\*(R" after the
2879fork.
2880.PP
2881The default mode of operation (for libev, with application help to detect
2882forks) is to duplicate all the state in the child, as would be expected
2883when \fIeither\fR the parent \fIor\fR the child process continues.
2884.PP
2885When both processes want to continue using libev, then this is usually the
2886wrong result. In that case, usually one process (typically the parent) is
2887supposed to continue with all watchers in place as before, while the other
2888process typically wants to start fresh, i.e. without any active watchers.
2889.PP
2890The cleanest and most efficient way to achieve that with libev is to
2891simply create a new event loop, which of course will be \*(L"empty\*(R", and
2892use that for new watchers. This has the advantage of not touching more
2893memory than necessary, and thus avoiding the copy-on-write, and the
2894disadvantage of having to use multiple event loops (which do not support
2895signal watchers).
2896.PP
2897When this is not possible, or you want to use the default loop for
2898other reasons, then in the process that wants to start \*(L"fresh\*(R", call
2899\&\f(CW\*(C`ev_default_destroy ()\*(C'\fR followed by \f(CW\*(C`ev_default_loop (...)\*(C'\fR. Destroying
2900the default loop will \*(L"orphan\*(R" (not stop) all registered watchers, so you
2901have to be careful not to execute code that modifies those watchers. Note
2902also that in that case, you have to re-register any signal watchers.
2903.PP
2703\fIWatcher-Specific Functions and Data Members\fR 2904\fIWatcher-Specific Functions and Data Members\fR
2704.IX Subsection "Watcher-Specific Functions and Data Members" 2905.IX Subsection "Watcher-Specific Functions and Data Members"
2705.IP "ev_fork_init (ev_signal *, callback)" 4 2906.IP "ev_fork_init (ev_signal *, callback)" 4
2706.IX Item "ev_fork_init (ev_signal *, callback)" 2907.IX Item "ev_fork_init (ev_signal *, callback)"
2707Initialises and configures the fork watcher \- it has no parameters of any 2908Initialises and configures the fork watcher \- it has no parameters of any
2825an \f(CW\*(C`EV_ASYNC\*(C'\fR event on the watcher into the event loop. Unlike 3026an \f(CW\*(C`EV_ASYNC\*(C'\fR event on the watcher into the event loop. Unlike
2826\&\f(CW\*(C`ev_feed_event\*(C'\fR, this call is safe to do from other threads, signal or 3027\&\f(CW\*(C`ev_feed_event\*(C'\fR, this call is safe to do from other threads, signal or
2827similar contexts (see the discussion of \f(CW\*(C`EV_ATOMIC_T\*(C'\fR in the embedding 3028similar contexts (see the discussion of \f(CW\*(C`EV_ATOMIC_T\*(C'\fR in the embedding
2828section below on what exactly this means). 3029section below on what exactly this means).
2829.Sp 3030.Sp
3031Note that, as with other watchers in libev, multiple events might get
3032compressed into a single callback invocation (another way to look at this
3033is that \f(CW\*(C`ev_async\*(C'\fR watchers are level-triggered, set on \f(CW\*(C`ev_async_send\*(C'\fR,
3034reset when the event loop detects that).
3035.Sp
2830This call incurs the overhead of a system call only once per loop iteration, 3036This call incurs the overhead of a system call only once per event loop
2831so while the overhead might be noticeable, it doesn't apply to repeated 3037iteration, so while the overhead might be noticeable, it doesn't apply to
2832calls to \f(CW\*(C`ev_async_send\*(C'\fR. 3038repeated calls to \f(CW\*(C`ev_async_send\*(C'\fR for the same event loop.
2833.IP "bool = ev_async_pending (ev_async *)" 4 3039.IP "bool = ev_async_pending (ev_async *)" 4
2834.IX Item "bool = ev_async_pending (ev_async *)" 3040.IX Item "bool = ev_async_pending (ev_async *)"
2835Returns a non-zero value when \f(CW\*(C`ev_async_send\*(C'\fR has been called on the 3041Returns a non-zero value when \f(CW\*(C`ev_async_send\*(C'\fR has been called on the
2836watcher but the event has not yet been processed (or even noted) by the 3042watcher but the event has not yet been processed (or even noted) by the
2837event loop. 3043event loop.
2839\&\f(CW\*(C`ev_async_send\*(C'\fR sets a flag in the watcher and wakes up the loop. When 3045\&\f(CW\*(C`ev_async_send\*(C'\fR sets a flag in the watcher and wakes up the loop. When
2840the loop iterates next and checks for the watcher to have become active, 3046the loop iterates next and checks for the watcher to have become active,
2841it will reset the flag again. \f(CW\*(C`ev_async_pending\*(C'\fR can be used to very 3047it will reset the flag again. \f(CW\*(C`ev_async_pending\*(C'\fR can be used to very
2842quickly check whether invoking the loop might be a good idea. 3048quickly check whether invoking the loop might be a good idea.
2843.Sp 3049.Sp
2844Not that this does \fInot\fR check whether the watcher itself is pending, only 3050Not that this does \fInot\fR check whether the watcher itself is pending,
2845whether it has been requested to make this watcher pending. 3051only whether it has been requested to make this watcher pending: there
3052is a time window between the event loop checking and resetting the async
3053notification, and the callback being invoked.
2846.SH "OTHER FUNCTIONS" 3054.SH "OTHER FUNCTIONS"
2847.IX Header "OTHER FUNCTIONS" 3055.IX Header "OTHER FUNCTIONS"
2848There are some other functions of possible interest. Described. Here. Now. 3056There are some other functions of possible interest. Described. Here. Now.
2849.IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4 3057.IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4
2850.IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 3058.IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)"
3131It can be found and installed via \s-1CPAN\s0, its homepage is at 3339It can be found and installed via \s-1CPAN\s0, its homepage is at
3132<http://software.schmorp.de/pkg/EV>. 3340<http://software.schmorp.de/pkg/EV>.
3133.IP "Python" 4 3341.IP "Python" 4
3134.IX Item "Python" 3342.IX Item "Python"
3135Python bindings can be found at <http://code.google.com/p/pyev/>. It 3343Python bindings can be found at <http://code.google.com/p/pyev/>. It
3136seems to be quite complete and well-documented. Note, however, that the 3344seems to be quite complete and well-documented.
3137patch they require for libev is outright dangerous as it breaks the \s-1ABI\s0
3138for everybody else, and therefore, should never be applied in an installed
3139libev (if python requires an incompatible \s-1ABI\s0 then it needs to embed
3140libev).
3141.IP "Ruby" 4 3345.IP "Ruby" 4
3142.IX Item "Ruby" 3346.IX Item "Ruby"
3143Tony Arcieri has written a ruby extension that offers access to a subset 3347Tony Arcieri has written a ruby extension that offers access to a subset
3144of the libev \s-1API\s0 and adds file handle abstractions, asynchronous \s-1DNS\s0 and 3348of the libev \s-1API\s0 and adds file handle abstractions, asynchronous \s-1DNS\s0 and
3145more on top of it. It can be found via gem servers. Its homepage is at 3349more on top of it. It can be found via gem servers. Its homepage is at
3146<http://rev.rubyforge.org/>. 3350<http://rev.rubyforge.org/>.
3147.Sp 3351.Sp
3148Roger Pack reports that using the link order \f(CW\*(C`\-lws2_32 \-lmsvcrt\-ruby\-190\*(C'\fR 3352Roger Pack reports that using the link order \f(CW\*(C`\-lws2_32 \-lmsvcrt\-ruby\-190\*(C'\fR
3149makes rev work even on mingw. 3353makes rev work even on mingw.
3354.IP "Haskell" 4
3355.IX Item "Haskell"
3356A haskell binding to libev is available at
3357<http://hackage.haskell.org/cgi\-bin/hackage\-scripts/package/hlibev>.
3150.IP "D" 4 3358.IP "D" 4
3151.IX Item "D" 3359.IX Item "D"
3152Leandro Lucarella has written a D language binding (\fIev.d\fR) for libev, to 3360Leandro Lucarella has written a D language binding (\fIev.d\fR) for libev, to
3153be found at <http://proj.llucax.com.ar/wiki/evd>. 3361be found at <http://proj.llucax.com.ar/wiki/evd>.
3154.IP "Ocaml" 4 3362.IP "Ocaml" 4
3823way (note also that glib is the slowest event library known to man). 4031way (note also that glib is the slowest event library known to man).
3824.PP 4032.PP
3825There is no supported compilation method available on windows except 4033There is no supported compilation method available on windows except
3826embedding it into other applications. 4034embedding it into other applications.
3827.PP 4035.PP
4036Sensible signal handling is officially unsupported by Microsoft \- libev
4037tries its best, but under most conditions, signals will simply not work.
4038.PP
3828Not a libev limitation but worth mentioning: windows apparently doesn't 4039Not a libev limitation but worth mentioning: windows apparently doesn't
3829accept large writes: instead of resulting in a partial write, windows will 4040accept large writes: instead of resulting in a partial write, windows will
3830either accept everything or return \f(CW\*(C`ENOBUFS\*(C'\fR if the buffer is too large, 4041either accept everything or return \f(CW\*(C`ENOBUFS\*(C'\fR if the buffer is too large,
3831so make sure you only write small amounts into your sockets (less than a 4042so make sure you only write small amounts into your sockets (less than a
3832megabyte seems safe, but this apparently depends on the amount of memory 4043megabyte seems safe, but this apparently depends on the amount of memory
3836the abysmal performance of winsockets, using a large number of sockets 4047the abysmal performance of winsockets, using a large number of sockets
3837is not recommended (and not reasonable). If your program needs to use 4048is not recommended (and not reasonable). If your program needs to use
3838more than a hundred or so sockets, then likely it needs to use a totally 4049more than a hundred or so sockets, then likely it needs to use a totally
3839different implementation for windows, as libev offers the \s-1POSIX\s0 readiness 4050different implementation for windows, as libev offers the \s-1POSIX\s0 readiness
3840notification model, which cannot be implemented efficiently on windows 4051notification model, which cannot be implemented efficiently on windows
3841(Microsoft monopoly games). 4052(due to Microsoft monopoly games).
3842.PP 4053.PP
3843A typical way to use libev under windows is to embed it (see the embedding 4054A typical way to use libev under windows is to embed it (see the embedding
3844section for details) and use the following \fIevwrap.h\fR header file instead 4055section for details) and use the following \fIevwrap.h\fR header file instead
3845of \fIev.h\fR: 4056of \fIev.h\fR:
3846.PP 4057.PP
3884.Sp 4095.Sp
3885Early versions of winsocket's select only supported waiting for a maximum 4096Early versions of winsocket's select only supported waiting for a maximum
3886of \f(CW64\fR handles (probably owning to the fact that all windows kernels 4097of \f(CW64\fR handles (probably owning to the fact that all windows kernels
3887can only wait for \f(CW64\fR things at the same time internally; Microsoft 4098can only wait for \f(CW64\fR things at the same time internally; Microsoft
3888recommends spawning a chain of threads and wait for 63 handles and the 4099recommends spawning a chain of threads and wait for 63 handles and the
3889previous thread in each. Great). 4100previous thread in each. Sounds great!).
3890.Sp 4101.Sp
3891Newer versions support more handles, but you need to define \f(CW\*(C`FD_SETSIZE\*(C'\fR 4102Newer versions support more handles, but you need to define \f(CW\*(C`FD_SETSIZE\*(C'\fR
3892to some high number (e.g. \f(CW2048\fR) before compiling the winsocket select 4103to some high number (e.g. \f(CW2048\fR) before compiling the winsocket select
3893call (which might be in libev or elsewhere, for example, perl does its own 4104call (which might be in libev or elsewhere, for example, perl and many
3894select emulation on windows). 4105other interpreters do their own select emulation on windows).
3895.Sp 4106.Sp
3896Another limit is the number of file descriptors in the Microsoft runtime 4107Another limit is the number of file descriptors in the Microsoft runtime
3897libraries, which by default is \f(CW64\fR (there must be a hidden \fI64\fR fetish 4108libraries, which by default is \f(CW64\fR (there must be a hidden \fI64\fR
3898or something like this inside Microsoft). You can increase this by calling 4109fetish or something like this inside Microsoft). You can increase this
3899\&\f(CW\*(C`_setmaxstdio\*(C'\fR, which can increase this limit to \f(CW2048\fR (another 4110by calling \f(CW\*(C`_setmaxstdio\*(C'\fR, which can increase this limit to \f(CW2048\fR
3900arbitrary limit), but is broken in many versions of the Microsoft runtime 4111(another arbitrary limit), but is broken in many versions of the Microsoft
3901libraries.
3902.Sp
3903This might get you to about \f(CW512\fR or \f(CW2048\fR sockets (depending on 4112runtime libraries. This might get you to about \f(CW512\fR or \f(CW2048\fR sockets
3904windows version and/or the phase of the moon). To get more, you need to 4113(depending on windows version and/or the phase of the moon). To get more,
3905wrap all I/O functions and provide your own fd management, but the cost of 4114you need to wrap all I/O functions and provide your own fd management, but
3906calling select (O(nA\*^X)) will likely make this unworkable. 4115the cost of calling select (O(nA\*^X)) will likely make this unworkable.
3907.Sh "\s-1PORTABILITY\s0 \s-1REQUIREMENTS\s0" 4116.Sh "\s-1PORTABILITY\s0 \s-1REQUIREMENTS\s0"
3908.IX Subsection "PORTABILITY REQUIREMENTS" 4117.IX Subsection "PORTABILITY REQUIREMENTS"
3909In addition to a working ISO-C implementation and of course the 4118In addition to a working ISO-C implementation and of course the
3910backend-specific APIs, libev relies on a few additional extensions: 4119backend-specific APIs, libev relies on a few additional extensions:
3911.ie n .IP """void (*)(ev_watcher_type *, int revents)""\fR must have compatible calling conventions regardless of \f(CW""ev_watcher_type *""." 4 4120.ie n .IP """void (*)(ev_watcher_type *, int revents)""\fR must have compatible calling conventions regardless of \f(CW""ev_watcher_type *""." 4
4014.IX Item "Processing signals: O(max_signal_number)" 4223.IX Item "Processing signals: O(max_signal_number)"
4015.PD 4224.PD
4016Sending involves a system call \fIiff\fR there were no other \f(CW\*(C`ev_async_send\*(C'\fR 4225Sending involves a system call \fIiff\fR there were no other \f(CW\*(C`ev_async_send\*(C'\fR
4017calls in the current loop iteration. Checking for async and signal events 4226calls in the current loop iteration. Checking for async and signal events
4018involves iterating over all running async watchers or all signal numbers. 4227involves iterating over all running async watchers or all signal numbers.
4228.SH "GLOSSARY"
4229.IX Header "GLOSSARY"
4230.IP "active" 4
4231.IX Item "active"
4232A watcher is active as long as it has been started (has been attached to
4233an event loop) but not yet stopped (disassociated from the event loop).
4234.IP "application" 4
4235.IX Item "application"
4236In this document, an application is whatever is using libev.
4237.IP "callback" 4
4238.IX Item "callback"
4239The address of a function that is called when some event has been
4240detected. Callbacks are being passed the event loop, the watcher that
4241received the event, and the actual event bitset.
4242.IP "callback invocation" 4
4243.IX Item "callback invocation"
4244The act of calling the callback associated with a watcher.
4245.IP "event" 4
4246.IX Item "event"
4247A change of state of some external event, such as data now being available
4248for reading on a file descriptor, time having passed or simply not having
4249any other events happening anymore.
4250.Sp
4251In libev, events are represented as single bits (such as \f(CW\*(C`EV_READ\*(C'\fR or
4252\&\f(CW\*(C`EV_TIMEOUT\*(C'\fR).
4253.IP "event library" 4
4254.IX Item "event library"
4255A software package implementing an event model and loop.
4256.IP "event loop" 4
4257.IX Item "event loop"
4258An entity that handles and processes external events and converts them
4259into callback invocations.
4260.IP "event model" 4
4261.IX Item "event model"
4262The model used to describe how an event loop handles and processes
4263watchers and events.
4264.IP "pending" 4
4265.IX Item "pending"
4266A watcher is pending as soon as the corresponding event has been detected,
4267and stops being pending as soon as the watcher will be invoked or its
4268pending status is explicitly cleared by the application.
4269.Sp
4270A watcher can be pending, but not active. Stopping a watcher also clears
4271its pending status.
4272.IP "real time" 4
4273.IX Item "real time"
4274The physical time that is observed. It is apparently strictly monotonic :)
4275.IP "wall-clock time" 4
4276.IX Item "wall-clock time"
4277The time and date as shown on clocks. Unlike real time, it can actually
4278be wrong and jump forwards and backwards, e.g. when the you adjust your
4279clock.
4280.IP "watcher" 4
4281.IX Item "watcher"
4282A data structure that describes interest in certain events. Watchers need
4283to be started (attached to an event loop) before they can receive events.
4284.IP "watcher invocation" 4
4285.IX Item "watcher invocation"
4286The act of calling the callback associated with a watcher.
4019.SH "AUTHOR" 4287.SH "AUTHOR"
4020.IX Header "AUTHOR" 4288.IX Header "AUTHOR"
4021Marc Lehmann <libev@schmorp.de>, with repeated corrections by Mikael Magnusson. 4289Marc Lehmann <libev@schmorp.de>, with repeated corrections by Mikael Magnusson.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines