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

Comparing libev/ev.3 (file contents):
Revision 1.63 by root, Wed Apr 2 15:23:11 2008 UTC vs.
Revision 1.66 by root, Sun May 18 10:36:38 2008 UTC

129. ds Ae AE 129. ds Ae AE
130.\} 130.\}
131.rm #[ #] #H #V #F C 131.rm #[ #] #H #V #F C
132.\" ======================================================================== 132.\" ========================================================================
133.\" 133.\"
134.IX Title "EV 1" 134.IX Title "LIBEV 3"
135.TH EV 1 "2008-04-02" "perl v5.10.0" "User Contributed Perl Documentation" 135.TH LIBEV 3 "2008-05-11" "libev-3.33" "libev - high perfromance 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"
203.Ve 203.Ve
204.SH "DESCRIPTION" 204.SH "DESCRIPTION"
205.IX Header "DESCRIPTION" 205.IX Header "DESCRIPTION"
206The newest version of this document is also available as an html-formatted 206The newest version of this document is also available as an html-formatted
207web page you might find easier to navigate when reading it for the first 207web page you might find easier to navigate when reading it for the first
208time: <http://cvs.schmorp.de/libev/ev.html>. 208time: <http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod>.
209.PP 209.PP
210Libev is an event loop: you register interest in certain events (such as a 210Libev is an event loop: you register interest in certain events (such as a
211file descriptor being readable or a timeout occurring), and it will manage 211file descriptor being readable or a timeout occurring), and it will manage
212these event sources and provide your program with events. 212these event sources and provide your program with events.
213.PP 213.PP
328.Sp 328.Sp
329See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. 329See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info.
330.IP "ev_set_allocator (void *(*cb)(void *ptr, long size))" 4 330.IP "ev_set_allocator (void *(*cb)(void *ptr, long size))" 4
331.IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size))" 331.IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size))"
332Sets the allocation function to use (the prototype is similar \- the 332Sets the allocation function to use (the prototype is similar \- the
333semantics is identical \- to the realloc C function). It is used to 333semantics are identical to the \f(CW\*(C`realloc\*(C'\fR C89/SuS/POSIX function). It is
334allocate and free memory (no surprises here). If it returns zero when 334used to allocate and free memory (no surprises here). If it returns zero
335memory needs to be allocated, the library might abort or take some 335when memory needs to be allocated (\f(CW\*(C`size != 0\*(C'\fR), the library might abort
336potentially destructive action. The default is your system realloc 336or take some potentially destructive action.
337function. 337.Sp
338Since some systems (at least OpenBSD and Darwin) fail to implement
339correct \f(CW\*(C`realloc\*(C'\fR semantics, libev will use a wrapper around the system
340\&\f(CW\*(C`realloc\*(C'\fR and \f(CW\*(C`free\*(C'\fR functions by default.
338.Sp 341.Sp
339You could override this function in high-availability programs to, say, 342You could override this function in high-availability programs to, say,
340free some memory if it cannot allocate memory, to use a special allocator, 343free some memory if it cannot allocate memory, to use a special allocator,
341or even to sleep a while and retry until some memory is available. 344or even to sleep a while and retry until some memory is available.
342.Sp 345.Sp
343Example: Replace the libev allocator with one that waits a bit and then 346Example: Replace the libev allocator with one that waits a bit and then
344retries). 347retries (example requires a standards-compliant \f(CW\*(C`realloc\*(C'\fR).
345.Sp 348.Sp
346.Vb 6 349.Vb 6
347\& static void * 350\& static void *
348\& persistent_realloc (void *ptr, size_t size) 351\& persistent_realloc (void *ptr, size_t size)
349\& { 352\& {
387.SH "FUNCTIONS CONTROLLING THE EVENT LOOP" 390.SH "FUNCTIONS CONTROLLING THE EVENT LOOP"
388.IX Header "FUNCTIONS CONTROLLING THE EVENT LOOP" 391.IX Header "FUNCTIONS CONTROLLING THE EVENT LOOP"
389An event loop is described by a \f(CW\*(C`struct ev_loop *\*(C'\fR. The library knows two 392An event loop is described by a \f(CW\*(C`struct ev_loop *\*(C'\fR. The library knows two
390types of such loops, the \fIdefault\fR loop, which supports signals and child 393types of such loops, the \fIdefault\fR loop, which supports signals and child
391events, and dynamically created loops which do not. 394events, and dynamically created loops which do not.
392.PP
393If you use threads, a common model is to run the default event loop
394in your main thread (or in a separate thread) and for each thread you
395create, you also create another event loop. Libev itself does no locking
396whatsoever, so if you mix calls to the same event loop in different
397threads, make sure you lock (this is usually a bad idea, though, even if
398done correctly, because it's hideous and inefficient).
399.IP "struct ev_loop *ev_default_loop (unsigned int flags)" 4 395.IP "struct ev_loop *ev_default_loop (unsigned int flags)" 4
400.IX Item "struct ev_loop *ev_default_loop (unsigned int flags)" 396.IX Item "struct ev_loop *ev_default_loop (unsigned int flags)"
401This will initialise the default event loop if it hasn't been initialised 397This will initialise the default event loop if it hasn't been initialised
402yet and return it. If the default loop could not be initialised, returns 398yet and return it. If the default loop could not be initialised, returns
403false. If it already was initialised it simply returns it (and ignores the 399false. If it already was initialised it simply returns it (and ignores the
486For few fds, this backend is a bit little slower than poll and select, 482For few fds, this backend is a bit little slower than poll and select,
487but it scales phenomenally better. While poll and select usually scale 483but it scales phenomenally better. While poll and select usually scale
488like O(total_fds) where n is the total number of fds (or the highest fd), 484like O(total_fds) where n is the total number of fds (or the highest fd),
489epoll scales either O(1) or O(active_fds). The epoll design has a number 485epoll scales either O(1) or O(active_fds). The epoll design has a number
490of shortcomings, such as silently dropping events in some hard-to-detect 486of shortcomings, such as silently dropping events in some hard-to-detect
491cases and rewiring a syscall per fd change, no fork support and bad 487cases and requiring a syscall per fd change, no fork support and bad
492support for dup. 488support for dup.
493.Sp 489.Sp
494While stopping, setting and starting an I/O watcher in the same iteration 490While stopping, setting and starting an I/O watcher in the same iteration
495will result in some caching, there is still a syscall per such incident 491will result in some caching, there is still a syscall per such incident
496(because the fd could point to a different file description now), so its 492(because the fd could point to a different file description now), so its
1515.IX Item "ev_periodic_again (loop, ev_periodic *)" 1511.IX Item "ev_periodic_again (loop, ev_periodic *)"
1516Simply stops and restarts the periodic watcher again. This is only useful 1512Simply stops and restarts the periodic watcher again. This is only useful
1517when you changed some parameters or the reschedule callback would return 1513when you changed some parameters or the reschedule callback would return
1518a different time than the last time it was called (e.g. in a crond like 1514a different time than the last time it was called (e.g. in a crond like
1519program when the crontabs have changed). 1515program when the crontabs have changed).
1516.IP "ev_tstamp ev_periodic_at (ev_periodic *)" 4
1517.IX Item "ev_tstamp ev_periodic_at (ev_periodic *)"
1518When active, returns the absolute time that the watcher is supposed to
1519trigger next.
1520.IP "ev_tstamp offset [read\-write]" 4 1520.IP "ev_tstamp offset [read\-write]" 4
1521.IX Item "ev_tstamp offset [read-write]" 1521.IX Item "ev_tstamp offset [read-write]"
1522When repeating, this contains the offset value, otherwise this is the 1522When repeating, this contains the offset value, otherwise this is the
1523absolute point in time (the \f(CW\*(C`at\*(C'\fR value passed to \f(CW\*(C`ev_periodic_set\*(C'\fR). 1523absolute point in time (the \f(CW\*(C`at\*(C'\fR value passed to \f(CW\*(C`ev_periodic_set\*(C'\fR).
1524.Sp 1524.Sp
1532.IP "ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) [read\-write]" 4 1532.IP "ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) [read\-write]" 4
1533.IX Item "ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) [read-write]" 1533.IX Item "ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) [read-write]"
1534The current reschedule callback, or \f(CW0\fR, if this functionality is 1534The current reschedule callback, or \f(CW0\fR, if this functionality is
1535switched off. Can be changed any time, but changes only take effect when 1535switched off. Can be changed any time, but changes only take effect when
1536the periodic timer fires or \f(CW\*(C`ev_periodic_again\*(C'\fR is being called. 1536the periodic timer fires or \f(CW\*(C`ev_periodic_again\*(C'\fR is being called.
1537.IP "ev_tstamp at [read\-only]" 4
1538.IX Item "ev_tstamp at [read-only]"
1539When active, contains the absolute time that the watcher is supposed to
1540trigger next.
1541.PP 1537.PP
1542\fIExamples\fR 1538\fIExamples\fR
1543.IX Subsection "Examples" 1539.IX Subsection "Examples"
1544.PP 1540.PP
1545Example: Call a callback every hour, or, more precisely, whenever the 1541Example: Call a callback every hour, or, more precisely, whenever the
1751as even with OS-supported change notifications, this can be 1747as even with OS-supported change notifications, this can be
1752resource-intensive. 1748resource-intensive.
1753.PP 1749.PP
1754At the time of this writing, only the Linux inotify interface is 1750At the time of this writing, only the Linux inotify interface is
1755implemented (implementing kqueue support is left as an exercise for the 1751implemented (implementing kqueue support is left as an exercise for the
1752reader, note, however, that the author sees no way of implementing ev_stat
1756reader). Inotify will be used to give hints only and should not change the 1753semantics with kqueue). Inotify will be used to give hints only and should
1757semantics of \f(CW\*(C`ev_stat\*(C'\fR watchers, which means that libev sometimes needs 1754not change the semantics of \f(CW\*(C`ev_stat\*(C'\fR watchers, which means that libev
1758to fall back to regular polling again even with inotify, but changes are 1755sometimes needs to fall back to regular polling again even with inotify,
1759usually detected immediately, and if the file exists there will be no 1756but changes are usually detected immediately, and if the file exists there
1760polling. 1757will be no polling.
1761.PP 1758.PP
1762\fI\s-1ABI\s0 Issues (Largefile Support)\fR 1759\fI\s-1ABI\s0 Issues (Largefile Support)\fR
1763.IX Subsection "ABI Issues (Largefile Support)" 1760.IX Subsection "ABI Issues (Largefile Support)"
1764.PP 1761.PP
1765Libev by default (unless the user overrides this) uses the default 1762Libev by default (unless the user overrides this) uses the default
1777When \f(CW\*(C`inotify (7)\*(C'\fR support has been compiled into libev (generally only 1774When \f(CW\*(C`inotify (7)\*(C'\fR support has been compiled into libev (generally only
1778available on Linux) and present at runtime, it will be used to speed up 1775available on Linux) and present at runtime, it will be used to speed up
1779change detection where possible. The inotify descriptor will be created lazily 1776change detection where possible. The inotify descriptor will be created lazily
1780when the first \f(CW\*(C`ev_stat\*(C'\fR watcher is being started. 1777when the first \f(CW\*(C`ev_stat\*(C'\fR watcher is being started.
1781.PP 1778.PP
1782Inotify presense does not change the semantics of \f(CW\*(C`ev_stat\*(C'\fR watchers 1779Inotify presence does not change the semantics of \f(CW\*(C`ev_stat\*(C'\fR watchers
1783except that changes might be detected earlier, and in some cases, to avoid 1780except that changes might be detected earlier, and in some cases, to avoid
1784making regular \f(CW\*(C`stat\*(C'\fR calls. Even in the presense of inotify support 1781making regular \f(CW\*(C`stat\*(C'\fR calls. Even in the presence of inotify support
1785there are many cases where libev has to resort to regular \f(CW\*(C`stat\*(C'\fR polling. 1782there are many cases where libev has to resort to regular \f(CW\*(C`stat\*(C'\fR polling.
1786.PP 1783.PP
1787(There is no support for kqueue, as apparently it cannot be used to 1784(There is no support for kqueue, as apparently it cannot be used to
1788implement this functionality, due to the requirement of having a file 1785implement this functionality, due to the requirement of having a file
1789descriptor open on the object at all times). 1786descriptor open on the object at all times).
1793.PP 1790.PP
1794The \f(CW\*(C`stat ()\*(C'\fR syscall only supports full-second resolution portably, and 1791The \f(CW\*(C`stat ()\*(C'\fR syscall only supports full-second resolution portably, and
1795even on systems where the resolution is higher, many filesystems still 1792even on systems where the resolution is higher, many filesystems still
1796only support whole seconds. 1793only support whole seconds.
1797.PP 1794.PP
1798That means that, if the time is the only thing that changes, you might 1795That means that, if the time is the only thing that changes, you can
1799miss updates: on the first update, \f(CW\*(C`ev_stat\*(C'\fR detects a change and calls 1796easily miss updates: on the first update, \f(CW\*(C`ev_stat\*(C'\fR detects a change and
1800your callback, which does something. When there is another update within 1797calls your callback, which does something. When there is another update
1801the same second, \f(CW\*(C`ev_stat\*(C'\fR will be unable to detect it. 1798within the same second, \f(CW\*(C`ev_stat\*(C'\fR will be unable to detect it as the stat
1799data does not change.
1802.PP 1800.PP
1803The solution to this is to delay acting on a change for a second (or till 1801The solution to this is to delay acting on a change for slightly more
1804the next second boundary), using a roughly one-second delay \f(CW\*(C`ev_timer\*(C'\fR 1802than second (or till slightly after the next full second boundary), using
1805(\f(CW\*(C`ev_timer_set (w, 0., 1.01); ev_timer_again (loop, w)\*(C'\fR). The \f(CW.01\fR 1803a roughly one-second-delay \f(CW\*(C`ev_timer\*(C'\fR (e.g. \f(CW\*(C`ev_timer_set (w, 0., 1.02);
1806is added to work around small timing inconsistencies of some operating 1804ev_timer_again (loop, w)\*(C'\fR).
1807systems. 1805.PP
1806The \f(CW.02\fR offset is added to work around small timing inconsistencies
1807of some operating systems (where the second counter of the current time
1808might be be delayed. One such system is the Linux kernel, where a call to
1809\&\f(CW\*(C`gettimeofday\*(C'\fR might return a timestamp with a full second later than
1810a subsequent \f(CW\*(C`time\*(C'\fR call \- if the equivalent of \f(CW\*(C`time ()\*(C'\fR is used to
1811update file times then there will be a small window where the kernel uses
1812the previous second to update file times but libev might already execute
1813the timer callback).
1808.PP 1814.PP
1809\fIWatcher-Specific Functions and Data Members\fR 1815\fIWatcher-Specific Functions and Data Members\fR
1810.IX Subsection "Watcher-Specific Functions and Data Members" 1816.IX Subsection "Watcher-Specific Functions and Data Members"
1811.IP "ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)" 4 1817.IP "ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)" 4
1812.IX Item "ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)" 1818.IX Item "ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)"
1818\&\f(CW\*(C`path\*(C'\fR. The \f(CW\*(C`interval\*(C'\fR is a hint on how quickly a change is expected to 1824\&\f(CW\*(C`path\*(C'\fR. The \f(CW\*(C`interval\*(C'\fR is a hint on how quickly a change is expected to
1819be detected and should normally be specified as \f(CW0\fR to let libev choose 1825be detected and should normally be specified as \f(CW0\fR to let libev choose
1820a suitable value. The memory pointed to by \f(CW\*(C`path\*(C'\fR must point to the same 1826a suitable value. The memory pointed to by \f(CW\*(C`path\*(C'\fR must point to the same
1821path for as long as the watcher is active. 1827path for as long as the watcher is active.
1822.Sp 1828.Sp
1823The callback will be receive \f(CW\*(C`EV_STAT\*(C'\fR when a change was detected, 1829The callback will receive \f(CW\*(C`EV_STAT\*(C'\fR when a change was detected, relative
1824relative to the attributes at the time the watcher was started (or the 1830to the attributes at the time the watcher was started (or the last change
1825last change was detected). 1831was detected).
1826.IP "ev_stat_stat (loop, ev_stat *)" 4 1832.IP "ev_stat_stat (loop, ev_stat *)" 4
1827.IX Item "ev_stat_stat (loop, ev_stat *)" 1833.IX Item "ev_stat_stat (loop, ev_stat *)"
1828Updates the stat buffer immediately with new values. If you change the 1834Updates the stat buffer immediately with new values. If you change the
1829watched path in your callback, you could call this fucntion to avoid 1835watched path in your callback, you could call this function to avoid
1830detecting this change (while introducing a race condition). Can also be 1836detecting this change (while introducing a race condition if you are not
1831useful simply to find out the new values. 1837the only one changing the path). Can also be useful simply to find out the
1838new values.
1832.IP "ev_statdata attr [read\-only]" 4 1839.IP "ev_statdata attr [read\-only]" 4
1833.IX Item "ev_statdata attr [read-only]" 1840.IX Item "ev_statdata attr [read-only]"
1834The most-recently detected attributes of the file. Although the type is of 1841The most-recently detected attributes of the file. Although the type is
1835\&\f(CW\*(C`ev_statdata\*(C'\fR, this is usually the (or one of the) \f(CW\*(C`struct stat\*(C'\fR types 1842\&\f(CW\*(C`ev_statdata\*(C'\fR, this is usually the (or one of the) \f(CW\*(C`struct stat\*(C'\fR types
1843suitable for your system, but you can only rely on the POSIX-standardised
1836suitable for your system. If the \f(CW\*(C`st_nlink\*(C'\fR member is \f(CW0\fR, then there 1844members to be present. If the \f(CW\*(C`st_nlink\*(C'\fR member is \f(CW0\fR, then there was
1837was some error while \f(CW\*(C`stat\*(C'\fRing the file. 1845some error while \f(CW\*(C`stat\*(C'\fRing the file.
1838.IP "ev_statdata prev [read\-only]" 4 1846.IP "ev_statdata prev [read\-only]" 4
1839.IX Item "ev_statdata prev [read-only]" 1847.IX Item "ev_statdata prev [read-only]"
1840The previous attributes of the file. The callback gets invoked whenever 1848The previous attributes of the file. The callback gets invoked whenever
1841\&\f(CW\*(C`prev\*(C'\fR != \f(CW\*(C`attr\*(C'\fR. 1849\&\f(CW\*(C`prev\*(C'\fR != \f(CW\*(C`attr\*(C'\fR, or, more precisely, one or more of these members
1850differ: \f(CW\*(C`st_dev\*(C'\fR, \f(CW\*(C`st_ino\*(C'\fR, \f(CW\*(C`st_mode\*(C'\fR, \f(CW\*(C`st_nlink\*(C'\fR, \f(CW\*(C`st_uid\*(C'\fR,
1851\&\f(CW\*(C`st_gid\*(C'\fR, \f(CW\*(C`st_rdev\*(C'\fR, \f(CW\*(C`st_size\*(C'\fR, \f(CW\*(C`st_atime\*(C'\fR, \f(CW\*(C`st_mtime\*(C'\fR, \f(CW\*(C`st_ctime\*(C'\fR.
1842.IP "ev_tstamp interval [read\-only]" 4 1852.IP "ev_tstamp interval [read\-only]" 4
1843.IX Item "ev_tstamp interval [read-only]" 1853.IX Item "ev_tstamp interval [read-only]"
1844The specified interval. 1854The specified interval.
1845.IP "const char *path [read\-only]" 4 1855.IP "const char *path [read\-only]" 4
1846.IX Item "const char *path [read-only]" 1856.IX Item "const char *path [read-only]"
1900\& } 1910\& }
1901\& 1911\&
1902\& ... 1912\& ...
1903\& ev_stat_init (&passwd, stat_cb, "/etc/passwd", 0.); 1913\& ev_stat_init (&passwd, stat_cb, "/etc/passwd", 0.);
1904\& ev_stat_start (loop, &passwd); 1914\& ev_stat_start (loop, &passwd);
1905\& ev_timer_init (&timer, timer_cb, 0., 1.01); 1915\& ev_timer_init (&timer, timer_cb, 0., 1.02);
1906.Ve 1916.Ve
1907.ie n .Sh """ev_idle"" \- when you've got nothing better to do..." 1917.ie n .Sh """ev_idle"" \- when you've got nothing better to do..."
1908.el .Sh "\f(CWev_idle\fP \- when you've got nothing better to do..." 1918.el .Sh "\f(CWev_idle\fP \- when you've got nothing better to do..."
1909.IX Subsection "ev_idle - when you've got nothing better to do..." 1919.IX Subsection "ev_idle - when you've got nothing better to do..."
1910Idle watchers trigger events when no other events of the same or higher 1920Idle watchers trigger events when no other events of the same or higher
1996.PP 2006.PP
1997It is recommended to give \f(CW\*(C`ev_check\*(C'\fR watchers highest (\f(CW\*(C`EV_MAXPRI\*(C'\fR) 2007It is recommended to give \f(CW\*(C`ev_check\*(C'\fR watchers highest (\f(CW\*(C`EV_MAXPRI\*(C'\fR)
1998priority, to ensure that they are being run before any other watchers 2008priority, to ensure that they are being run before any other watchers
1999after the poll. Also, \f(CW\*(C`ev_check\*(C'\fR watchers (and \f(CW\*(C`ev_prepare\*(C'\fR watchers, 2009after the poll. Also, \f(CW\*(C`ev_check\*(C'\fR watchers (and \f(CW\*(C`ev_prepare\*(C'\fR watchers,
2000too) should not activate (\*(L"feed\*(R") events into libev. While libev fully 2010too) should not activate (\*(L"feed\*(R") events into libev. While libev fully
2001supports this, they will be called before other \f(CW\*(C`ev_check\*(C'\fR watchers 2011supports this, they might get executed before other \f(CW\*(C`ev_check\*(C'\fR watchers
2002did their job. As \f(CW\*(C`ev_check\*(C'\fR watchers are often used to embed other 2012did their job. As \f(CW\*(C`ev_check\*(C'\fR watchers are often used to embed other
2003(non-libev) event loops those other event loops might be in an unusable 2013(non-libev) event loops those other event loops might be in an unusable
2004state until their \f(CW\*(C`ev_check\*(C'\fR watcher ran (always remind yourself to 2014state until their \f(CW\*(C`ev_check\*(C'\fR watcher ran (always remind yourself to
2005coexist peacefully with others). 2015coexist peacefully with others).
2006.PP 2016.PP
2020.IX Subsection "Examples" 2030.IX Subsection "Examples"
2021.PP 2031.PP
2022There are a number of principal ways to embed other event loops or modules 2032There are a number of principal ways to embed other event loops or modules
2023into libev. Here are some ideas on how to include libadns into libev 2033into libev. Here are some ideas on how to include libadns into libev
2024(there is a Perl module named \f(CW\*(C`EV::ADNS\*(C'\fR that does this, which you could 2034(there is a Perl module named \f(CW\*(C`EV::ADNS\*(C'\fR that does this, which you could
2025use for an actually working example. Another Perl module named \f(CW\*(C`EV::Glib\*(C'\fR 2035use as a working example. Another Perl module named \f(CW\*(C`EV::Glib\*(C'\fR embeds a
2026embeds a Glib main context into libev, and finally, \f(CW\*(C`Glib::EV\*(C'\fR embeds \s-1EV\s0 2036Glib main context into libev, and finally, \f(CW\*(C`Glib::EV\*(C'\fR embeds \s-1EV\s0 into the
2027into the Glib event loop). 2037Glib event loop).
2028.PP 2038.PP
2029Method 1: Add \s-1IO\s0 watchers and a timeout watcher in a prepare handler, 2039Method 1: Add \s-1IO\s0 watchers and a timeout watcher in a prepare handler,
2030and in a check watcher, destroy them and call into libadns. What follows 2040and in a check watcher, destroy them and call into libadns. What follows
2031is pseudo-code only of course. This requires you to either use a low 2041is pseudo-code only of course. This requires you to either use a low
2032priority for the check watcher or use \f(CW\*(C`ev_clear_pending\*(C'\fR explicitly, as 2042priority for the check watcher or use \f(CW\*(C`ev_clear_pending\*(C'\fR explicitly, as
2495it a private \s-1API\s0). 2505it a private \s-1API\s0).
2496.IP "\(bu" 4 2506.IP "\(bu" 4
2497Priorities are not currently supported. Initialising priorities 2507Priorities are not currently supported. Initialising priorities
2498will fail and all watchers will have the same priority, even though there 2508will fail and all watchers will have the same priority, even though there
2499is an ev_pri field. 2509is an ev_pri field.
2510.IP "\(bu" 4
2511In libevent, the last base created gets the signals, in libev, the
2512first base created (== the default loop) gets the signals.
2500.IP "\(bu" 4 2513.IP "\(bu" 4
2501Other members are not supported. 2514Other members are not supported.
2502.IP "\(bu" 4 2515.IP "\(bu" 4
2503The libev emulation is \fInot\fR \s-1ABI\s0 compatible to libevent, you need 2516The libev emulation is \fInot\fR \s-1ABI\s0 compatible to libevent, you need
2504to use the libev header file and library. 2517to use the libev header file and library.
2733.ie n .IP """EV_DEFAULT""\fR, \f(CW""EV_DEFAULT_""" 4 2746.ie n .IP """EV_DEFAULT""\fR, \f(CW""EV_DEFAULT_""" 4
2734.el .IP "\f(CWEV_DEFAULT\fR, \f(CWEV_DEFAULT_\fR" 4 2747.el .IP "\f(CWEV_DEFAULT\fR, \f(CWEV_DEFAULT_\fR" 4
2735.IX Item "EV_DEFAULT, EV_DEFAULT_" 2748.IX Item "EV_DEFAULT, EV_DEFAULT_"
2736Similar to the other two macros, this gives you the value of the default 2749Similar to the other two macros, this gives you the value of the default
2737loop, if multiple loops are supported (\*(L"ev loop default\*(R"). 2750loop, if multiple loops are supported (\*(L"ev loop default\*(R").
2751.ie n .IP """EV_DEFAULT_UC""\fR, \f(CW""EV_DEFAULT_UC_""" 4
2752.el .IP "\f(CWEV_DEFAULT_UC\fR, \f(CWEV_DEFAULT_UC_\fR" 4
2753.IX Item "EV_DEFAULT_UC, EV_DEFAULT_UC_"
2754Usage identical to \f(CW\*(C`EV_DEFAULT\*(C'\fR and \f(CW\*(C`EV_DEFAULT_\*(C'\fR, but requires that the
2755default loop has been initialised (\f(CW\*(C`UC\*(C'\fR == unchecked). Their behaviour
2756is undefined when the default loop has not been initialised by a previous
2757execution of \f(CW\*(C`EV_DEFAULT\*(C'\fR, \f(CW\*(C`EV_DEFAULT_\*(C'\fR or \f(CW\*(C`ev_default_init (...)\*(C'\fR.
2758.Sp
2759It is often prudent to use \f(CW\*(C`EV_DEFAULT\*(C'\fR when initialising the first
2760watcher in a function but use \f(CW\*(C`EV_DEFAULT_UC\*(C'\fR afterwards.
2738.PP 2761.PP
2739Example: Declare and initialise a check watcher, utilising the above 2762Example: Declare and initialise a check watcher, utilising the above
2740macros so it will work regardless of whether multiple loops are supported 2763macros so it will work regardless of whether multiple loops are supported
2741or not. 2764or not.
2742.PP 2765.PP
2852.Vb 1 2875.Vb 1
2853\& libev.m4 2876\& libev.m4
2854.Ve 2877.Ve
2855.Sh "\s-1PREPROCESSOR\s0 \s-1SYMBOLS/MACROS\s0" 2878.Sh "\s-1PREPROCESSOR\s0 \s-1SYMBOLS/MACROS\s0"
2856.IX Subsection "PREPROCESSOR SYMBOLS/MACROS" 2879.IX Subsection "PREPROCESSOR SYMBOLS/MACROS"
2857Libev can be configured via a variety of preprocessor symbols you have to define 2880Libev can be configured via a variety of preprocessor symbols you have to
2858before including any of its files. The default is not to build for multiplicity 2881define before including any of its files. The default in the absense of
2859and only include the select backend. 2882autoconf is noted for every option.
2860.IP "\s-1EV_STANDALONE\s0" 4 2883.IP "\s-1EV_STANDALONE\s0" 4
2861.IX Item "EV_STANDALONE" 2884.IX Item "EV_STANDALONE"
2862Must always be \f(CW1\fR if you do not use autoconf configuration, which 2885Must always be \f(CW1\fR if you do not use autoconf configuration, which
2863keeps libev from including \fIconfig.h\fR, and it also defines dummy 2886keeps libev from including \fIconfig.h\fR, and it also defines dummy
2864implementations for some libevent functions (such as logging, which is not 2887implementations for some libevent functions (such as logging, which is not
2883note about libraries in the description of \f(CW\*(C`EV_USE_MONOTONIC\*(C'\fR, though. 2906note about libraries in the description of \f(CW\*(C`EV_USE_MONOTONIC\*(C'\fR, though.
2884.IP "\s-1EV_USE_NANOSLEEP\s0" 4 2907.IP "\s-1EV_USE_NANOSLEEP\s0" 4
2885.IX Item "EV_USE_NANOSLEEP" 2908.IX Item "EV_USE_NANOSLEEP"
2886If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available 2909If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available
2887and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR. 2910and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR.
2911.IP "\s-1EV_USE_EVENTFD\s0" 4
2912.IX Item "EV_USE_EVENTFD"
2913If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is
2914available and will probe for kernel support at runtime. This will improve
2915\&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption.
2916If undefined, it will be enabled if the headers indicate GNU/Linux + Glibc
29172.7 or newer, otherwise disabled.
2888.IP "\s-1EV_USE_SELECT\s0" 4 2918.IP "\s-1EV_USE_SELECT\s0" 4
2889.IX Item "EV_USE_SELECT" 2919.IX Item "EV_USE_SELECT"
2890If undefined or defined to be \f(CW1\fR, libev will compile in support for the 2920If undefined or defined to be \f(CW1\fR, libev will compile in support for the
2891\&\f(CW\*(C`select\*(C'\fR(2) backend. No attempt at autodetection will be done: if no 2921\&\f(CW\*(C`select\*(C'\fR(2) backend. No attempt at autodetection will be done: if no
2892other method takes over, select will be it. Otherwise the select backend 2922other method takes over, select will be it. Otherwise the select backend
2923takes precedence over select. 2953takes precedence over select.
2924.IP "\s-1EV_USE_EPOLL\s0" 4 2954.IP "\s-1EV_USE_EPOLL\s0" 4
2925.IX Item "EV_USE_EPOLL" 2955.IX Item "EV_USE_EPOLL"
2926If defined to be \f(CW1\fR, libev will compile in support for the Linux 2956If defined to be \f(CW1\fR, libev will compile in support for the Linux
2927\&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime, 2957\&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime,
2928otherwise another method will be used as fallback. This is the 2958otherwise another method will be used as fallback. This is the preferred
2929preferred backend for GNU/Linux systems. 2959backend for GNU/Linux systems. If undefined, it will be enabled if the
2960headers indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled.
2930.IP "\s-1EV_USE_KQUEUE\s0" 4 2961.IP "\s-1EV_USE_KQUEUE\s0" 4
2931.IX Item "EV_USE_KQUEUE" 2962.IX Item "EV_USE_KQUEUE"
2932If defined to be \f(CW1\fR, libev will compile in support for the \s-1BSD\s0 style 2963If defined to be \f(CW1\fR, libev will compile in support for the \s-1BSD\s0 style
2933\&\f(CW\*(C`kqueue\*(C'\fR(2) backend. Its actual availability will be detected at runtime, 2964\&\f(CW\*(C`kqueue\*(C'\fR(2) backend. Its actual availability will be detected at runtime,
2934otherwise another method will be used as fallback. This is the preferred 2965otherwise another method will be used as fallback. This is the preferred
2949reserved for future expansion, works like the \s-1USE\s0 symbols above. 2980reserved for future expansion, works like the \s-1USE\s0 symbols above.
2950.IP "\s-1EV_USE_INOTIFY\s0" 4 2981.IP "\s-1EV_USE_INOTIFY\s0" 4
2951.IX Item "EV_USE_INOTIFY" 2982.IX Item "EV_USE_INOTIFY"
2952If defined to be \f(CW1\fR, libev will compile in support for the Linux inotify 2983If defined to be \f(CW1\fR, libev will compile in support for the Linux inotify
2953interface to speed up \f(CW\*(C`ev_stat\*(C'\fR watchers. Its actual availability will 2984interface to speed up \f(CW\*(C`ev_stat\*(C'\fR watchers. Its actual availability will
2954be detected at runtime. 2985be detected at runtime. If undefined, it will be enabled if the headers
2986indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled.
2955.IP "\s-1EV_ATOMIC_T\s0" 4 2987.IP "\s-1EV_ATOMIC_T\s0" 4
2956.IX Item "EV_ATOMIC_T" 2988.IX Item "EV_ATOMIC_T"
2957Libev requires an integer type (suitable for storing \f(CW0\fR or \f(CW1\fR) whose 2989Libev requires an integer type (suitable for storing \f(CW0\fR or \f(CW1\fR) whose
2958access is atomic with respect to other threads or signal contexts. No such 2990access is atomic with respect to other threads or signal contexts. No such
2959type is easily found in the C language, so you can provide your own type 2991type is easily found in the C language, so you can provide your own type
3034If undefined or defined to be \f(CW1\fR, then async watchers are supported. If 3066If undefined or defined to be \f(CW1\fR, then async watchers are supported. If
3035defined to be \f(CW0\fR, then they are not. 3067defined to be \f(CW0\fR, then they are not.
3036.IP "\s-1EV_MINIMAL\s0" 4 3068.IP "\s-1EV_MINIMAL\s0" 4
3037.IX Item "EV_MINIMAL" 3069.IX Item "EV_MINIMAL"
3038If you need to shave off some kilobytes of code at the expense of some 3070If you need to shave off some kilobytes of code at the expense of some
3039speed, define this symbol to \f(CW1\fR. Currently only used for gcc to override 3071speed, define this symbol to \f(CW1\fR. Currently this is used to override some
3040some inlining decisions, saves roughly 30% codesize of amd64. 3072inlining decisions, saves roughly 30% codesize of amd64. It also selects a
3073much smaller 2\-heap for timer management over the default 4\-heap.
3041.IP "\s-1EV_PID_HASHSIZE\s0" 4 3074.IP "\s-1EV_PID_HASHSIZE\s0" 4
3042.IX Item "EV_PID_HASHSIZE" 3075.IX Item "EV_PID_HASHSIZE"
3043\&\f(CW\*(C`ev_child\*(C'\fR watchers use a small hash table to distribute workload by 3076\&\f(CW\*(C`ev_child\*(C'\fR watchers use a small hash table to distribute workload by
3044pid. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_MINIMAL\*(C'\fR), usually more 3077pid. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_MINIMAL\*(C'\fR), usually more
3045than enough. If you need to manage thousands of children you might want to 3078than enough. If you need to manage thousands of children you might want to
3049\&\f(CW\*(C`ev_stat\*(C'\fR watchers use a small hash table to distribute workload by 3082\&\f(CW\*(C`ev_stat\*(C'\fR watchers use a small hash table to distribute workload by
3050inotify watch id. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_MINIMAL\*(C'\fR), 3083inotify watch id. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_MINIMAL\*(C'\fR),
3051usually more than enough. If you need to manage thousands of \f(CW\*(C`ev_stat\*(C'\fR 3084usually more than enough. If you need to manage thousands of \f(CW\*(C`ev_stat\*(C'\fR
3052watchers you might want to increase this value (\fImust\fR be a power of 3085watchers you might want to increase this value (\fImust\fR be a power of
3053two). 3086two).
3087.IP "\s-1EV_USE_4HEAP\s0" 4
3088.IX Item "EV_USE_4HEAP"
3089Heaps are not very cache-efficient. To improve the cache-efficiency of the
3090timer and periodics heap, libev uses a 4\-heap when this symbol is defined
3091to \f(CW1\fR. The 4\-heap uses more complicated (longer) code but has a
3092noticable after performance with many (thousands) of watchers.
3093.Sp
3094The default is \f(CW1\fR unless \f(CW\*(C`EV_MINIMAL\*(C'\fR is set in which case it is \f(CW0\fR
3095(disabled).
3096.IP "\s-1EV_HEAP_CACHE_AT\s0" 4
3097.IX Item "EV_HEAP_CACHE_AT"
3098Heaps are not very cache-efficient. To improve the cache-efficiency of the
3099timer and periodics heap, libev can cache the timestamp (\fIat\fR) within
3100the heap structure (selected by defining \f(CW\*(C`EV_HEAP_CACHE_AT\*(C'\fR to \f(CW1\fR),
3101which uses 8\-12 bytes more per watcher and a few hundred bytes more code,
3102but avoids random read accesses on heap changes. This noticably improves
3103performance noticably with with many (hundreds) of watchers.
3104.Sp
3105The default is \f(CW1\fR unless \f(CW\*(C`EV_MINIMAL\*(C'\fR is set in which case it is \f(CW0\fR
3106(disabled).
3054.IP "\s-1EV_COMMON\s0" 4 3107.IP "\s-1EV_COMMON\s0" 4
3055.IX Item "EV_COMMON" 3108.IX Item "EV_COMMON"
3056By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining 3109By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining
3057this macro to a something else you can include more and other types of 3110this macro to a something else you can include more and other types of
3058members. You have to define it each time you include one of the files, 3111members. You have to define it each time you include one of the files,
3140.PP 3193.PP
3141.Vb 2 3194.Vb 2
3142\& #include "ev_cpp.h" 3195\& #include "ev_cpp.h"
3143\& #include "ev.c" 3196\& #include "ev.c"
3144.Ve 3197.Ve
3198.SH "THREADS AND COROUTINES"
3199.IX Header "THREADS AND COROUTINES"
3200.Sh "\s-1THREADS\s0"
3201.IX Subsection "THREADS"
3202Libev itself is completely threadsafe, but it uses no locking. This
3203means that you can use as many loops as you want in parallel, as long as
3204only one thread ever calls into one libev function with the same loop
3205parameter.
3206.PP
3207Or put differently: calls with different loop parameters can be done in
3208parallel from multiple threads, calls with the same loop parameter must be
3209done serially (but can be done from different threads, as long as only one
3210thread ever is inside a call at any point in time, e.g. by using a mutex
3211per loop).
3212.PP
3213If you want to know which design is best for your problem, then I cannot
3214help you but by giving some generic advice:
3215.IP "\(bu" 4
3216most applications have a main thread: use the default libev loop
3217in that thread, or create a seperate thread running only the default loop.
3218.Sp
3219This helps integrating other libraries or software modules that use libev
3220themselves and don't care/know about threading.
3221.IP "\(bu" 4
3222one loop per thread is usually a good model.
3223.Sp
3224Doing this is almost never wrong, sometimes a better-performance model
3225exists, but it is always a good start.
3226.IP "\(bu" 4
3227other models exist, such as the leader/follower pattern, where one
3228loop is handed through multiple threads in a kind of round-robbin fashion.
3229.Sp
3230Chosing a model is hard \- look around, learn, know that usually you cna do
3231better than you currently do :\-)
3232.IP "\(bu" 4
3233often you need to talk to some other thread which blocks in the
3234event loop \- \f(CW\*(C`ev_async\*(C'\fR watchers can be used to wake them up from other
3235threads safely (or from signal contexts...).
3236.Sh "\s-1COROUTINES\s0"
3237.IX Subsection "COROUTINES"
3238Libev is much more accomodating to coroutines (\*(L"cooperative threads\*(R"):
3239libev fully supports nesting calls to it's functions from different
3240coroutines (e.g. you can call \f(CW\*(C`ev_loop\*(C'\fR on the same loop from two
3241different coroutines and switch freely between both coroutines running the
3242loop, as long as you don't confuse yourself). The only exception is that
3243you must not do this from \f(CW\*(C`ev_periodic\*(C'\fR reschedule callbacks.
3244.PP
3245Care has been invested into making sure that libev does not keep local
3246state inside \f(CW\*(C`ev_loop\*(C'\fR, and other calls do not usually allow coroutine
3247switches.
3145.SH "COMPLEXITIES" 3248.SH "COMPLEXITIES"
3146.IX Header "COMPLEXITIES" 3249.IX Header "COMPLEXITIES"
3147In this section the complexities of (many of) the algorithms used inside 3250In this section the complexities of (many of) the algorithms used inside
3148libev will be explained. For complexity discussions about backends see the 3251libev will be explained. For complexity discussions about backends see the
3149documentation for \f(CW\*(C`ev_default_init\*(C'\fR. 3252documentation for \f(CW\*(C`ev_default_init\*(C'\fR.
3174These watchers are stored in lists then need to be walked to find the 3277These watchers are stored in lists then need to be walked to find the
3175correct watcher to remove. The lists are usually short (you don't usually 3278correct watcher to remove. The lists are usually short (you don't usually
3176have many watchers waiting for the same fd or signal). 3279have many watchers waiting for the same fd or signal).
3177.IP "Finding the next timer in each loop iteration: O(1)" 4 3280.IP "Finding the next timer in each loop iteration: O(1)" 4
3178.IX Item "Finding the next timer in each loop iteration: O(1)" 3281.IX Item "Finding the next timer in each loop iteration: O(1)"
3179By virtue of using a binary heap, the next timer is always found at the 3282By virtue of using a binary or 4\-heap, the next timer is always found at a
3180beginning of the storage array. 3283fixed position in the storage array.
3181.IP "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" 4 3284.IP "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" 4
3182.IX Item "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" 3285.IX Item "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)"
3183A change means an I/O watcher gets started or stopped, which requires 3286A change means an I/O watcher gets started or stopped, which requires
3184libev to recalculate its status (and possibly tell the kernel, depending 3287libev to recalculate its status (and possibly tell the kernel, depending
3185on backend and wether \f(CW\*(C`ev_io_set\*(C'\fR was used). 3288on backend and wether \f(CW\*(C`ev_io_set\*(C'\fR was used).
3211model. Libev still offers limited functionality on this platform in 3314model. Libev still offers limited functionality on this platform in
3212the form of the \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR backend, and only supports socket 3315the form of the \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR backend, and only supports socket
3213descriptors. This only applies when using Win32 natively, not when using 3316descriptors. This only applies when using Win32 natively, not when using
3214e.g. cygwin. 3317e.g. cygwin.
3215.PP 3318.PP
3319Lifting these limitations would basically require the full
3320re-implementation of the I/O system. If you are into these kinds of
3321things, then note that glib does exactly that for you in a very portable
3322way (note also that glib is the slowest event library known to man).
3323.PP
3216There is no supported compilation method available on windows except 3324There is no supported compilation method available on windows except
3217embedding it into other applications. 3325embedding it into other applications.
3218.PP 3326.PP
3219Due to the many, low, and arbitrary limits on the win32 platform and the 3327Due to the many, low, and arbitrary limits on the win32 platform and
3220abysmal performance of winsockets, using a large number of sockets is not 3328the abysmal performance of winsockets, using a large number of sockets
3221recommended (and not reasonable). If your program needs to use more than 3329is not recommended (and not reasonable). If your program needs to use
3222a hundred or so sockets, then likely it needs to use a totally different 3330more than a hundred or so sockets, then likely it needs to use a totally
3223implementation for windows, as libev offers the \s-1POSIX\s0 model, which cannot 3331different implementation for windows, as libev offers the \s-1POSIX\s0 readyness
3224be implemented efficiently on windows (microsoft monopoly games). 3332notification model, which cannot be implemented efficiently on windows
3333(microsoft monopoly games).
3225.IP "The winsocket select function" 4 3334.IP "The winsocket select function" 4
3226.IX Item "The winsocket select function" 3335.IX Item "The winsocket select function"
3227The winsocket \f(CW\*(C`select\*(C'\fR function doesn't follow \s-1POSIX\s0 in that it requires 3336The winsocket \f(CW\*(C`select\*(C'\fR function doesn't follow \s-1POSIX\s0 in that it requires
3228socket \fIhandles\fR and not socket \fIfile descriptors\fR. This makes select 3337socket \fIhandles\fR and not socket \fIfile descriptors\fR. This makes select
3229very inefficient, and also requires a mapping from file descriptors 3338very inefficient, and also requires a mapping from file descriptors
3241.Sp 3350.Sp
3242Note that winsockets handling of fd sets is O(n), so you can easily get a 3351Note that winsockets handling of fd sets is O(n), so you can easily get a
3243complexity in the O(nA\*^X) range when using win32. 3352complexity in the O(nA\*^X) range when using win32.
3244.IP "Limited number of file descriptors" 4 3353.IP "Limited number of file descriptors" 4
3245.IX Item "Limited number of file descriptors" 3354.IX Item "Limited number of file descriptors"
3246Windows has numerous arbitrary (and low) limits on things. Early versions 3355Windows has numerous arbitrary (and low) limits on things.
3247of winsocket's select only supported waiting for a max. of \f(CW64\fR handles 3356.Sp
3248(probably owning to the fact that all windows kernels can only wait for 3357Early versions of winsocket's select only supported waiting for a maximum
3249\&\f(CW64\fR things at the same time internally; microsoft recommends spawning a 3358of \f(CW64\fR handles (probably owning to the fact that all windows kernels
3250chain of threads and wait for 63 handles and the previous thread in each). 3359can only wait for \f(CW64\fR things at the same time internally; microsoft
3360recommends spawning a chain of threads and wait for 63 handles and the
3361previous thread in each. Great).
3251.Sp 3362.Sp
3252Newer versions support more handles, but you need to define \f(CW\*(C`FD_SETSIZE\*(C'\fR 3363Newer versions support more handles, but you need to define \f(CW\*(C`FD_SETSIZE\*(C'\fR
3253to some high number (e.g. \f(CW2048\fR) before compiling the winsocket select 3364to some high number (e.g. \f(CW2048\fR) before compiling the winsocket select
3254call (which might be in libev or elsewhere, for example, perl does its own 3365call (which might be in libev or elsewhere, for example, perl does its own
3255select emulation on windows). 3366select emulation on windows).
3263.Sp 3374.Sp
3264This might get you to about \f(CW512\fR or \f(CW2048\fR sockets (depending on 3375This might get you to about \f(CW512\fR or \f(CW2048\fR sockets (depending on
3265windows version and/or the phase of the moon). To get more, you need to 3376windows version and/or the phase of the moon). To get more, you need to
3266wrap all I/O functions and provide your own fd management, but the cost of 3377wrap all I/O functions and provide your own fd management, but the cost of
3267calling select (O(nA\*^X)) will likely make this unworkable. 3378calling select (O(nA\*^X)) will likely make this unworkable.
3379.SH "PORTABILITY REQUIREMENTS"
3380.IX Header "PORTABILITY REQUIREMENTS"
3381In addition to a working ISO-C implementation, libev relies on a few
3382additional extensions:
3383.ie n .IP """sig_atomic_t volatile"" must be thread-atomic as well" 4
3384.el .IP "\f(CWsig_atomic_t volatile\fR must be thread-atomic as well" 4
3385.IX Item "sig_atomic_t volatile must be thread-atomic as well"
3386The type \f(CW\*(C`sig_atomic_t volatile\*(C'\fR (or whatever is defined as
3387\&\f(CW\*(C`EV_ATOMIC_T\*(C'\fR) must be atomic w.r.t. accesses from different
3388threads. This is not part of the specification for \f(CW\*(C`sig_atomic_t\*(C'\fR, but is
3389believed to be sufficiently portable.
3390.ie n .IP """sigprocmask"" must work in a threaded environment" 4
3391.el .IP "\f(CWsigprocmask\fR must work in a threaded environment" 4
3392.IX Item "sigprocmask must work in a threaded environment"
3393Libev uses \f(CW\*(C`sigprocmask\*(C'\fR to temporarily block signals. This is not
3394allowed in a threaded program (\f(CW\*(C`pthread_sigmask\*(C'\fR has to be used). Typical
3395pthread implementations will either allow \f(CW\*(C`sigprocmask\*(C'\fR in the \*(L"main
3396thread\*(R" or will block signals process-wide, both behaviours would
3397be compatible with libev. Interaction between \f(CW\*(C`sigprocmask\*(C'\fR and
3398\&\f(CW\*(C`pthread_sigmask\*(C'\fR could complicate things, however.
3399.Sp
3400The most portable way to handle signals is to block signals in all threads
3401except the initial one, and run the default loop in the initial thread as
3402well.
3403.ie n .IP """long"" must be large enough for common memory allocation sizes" 4
3404.el .IP "\f(CWlong\fR must be large enough for common memory allocation sizes" 4
3405.IX Item "long must be large enough for common memory allocation sizes"
3406To improve portability and simplify using libev, libev uses \f(CW\*(C`long\*(C'\fR
3407internally instead of \f(CW\*(C`size_t\*(C'\fR when allocating its data structures. On
3408non-POSIX systems (Microsoft...) this might be unexpectedly low, but
3409is still at least 31 bits everywhere, which is enough for hundreds of
3410millions of watchers.
3411.ie n .IP """double"" must hold a time value in seconds with enough accuracy" 4
3412.el .IP "\f(CWdouble\fR must hold a time value in seconds with enough accuracy" 4
3413.IX Item "double must hold a time value in seconds with enough accuracy"
3414The type \f(CW\*(C`double\*(C'\fR is used to represent timestamps. It is required to
3415have at least 51 bits of mantissa (and 9 bits of exponent), which is good
3416enough for at least into the year 4000. This requirement is fulfilled by
3417implementations implementing \s-1IEEE\s0 754 (basically all existing ones).
3418.PP
3419If you know of other additional requirements drop me a note.
3268.SH "AUTHOR" 3420.SH "AUTHOR"
3269.IX Header "AUTHOR" 3421.IX Header "AUTHOR"
3270Marc Lehmann <libev@schmorp.de>. 3422Marc Lehmann <libev@schmorp.de>.
3271.SH "POD ERRORS" 3423.SH "POD ERRORS"
3272.IX Header "POD ERRORS" 3424.IX Header "POD ERRORS"
3273Hey! \fBThe above document had some coding errors, which are explained below:\fR 3425Hey! \fBThe above document had some coding errors, which are explained below:\fR
3274.IP "Around line 2996:" 4 3426.IP "Around line 3052:" 4
3275.IX Item "Around line 2996:" 3427.IX Item "Around line 3052:"
3276You forgot a '=back' before '=head2' 3428You forgot a '=back' before '=head2'

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines