X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/80b007e04bb3f75ae92cf173ccb6af0510b214ba..5ac4bf0bc057e29b57d7e6f8fbd42f6d075efb21:/ev.pod diff --git a/ev.pod b/ev.pod index e409a03..45c9c60 100644 --- a/ev.pod +++ b/ev.pod @@ -10,7 +10,7 @@ libev - a high performance full-featured event loop written in C Libev is an event loop: you register interest in certain events (such as a file descriptor being readable or a timeout occuring), and it will manage -these event sources and provide your program events. +these event sources and provide your program with events. To do this, it must take more or less complete control over your process (or thread) by executing the I handler, and will then @@ -27,13 +27,15 @@ Libev supports select, poll, the linux-specific epoll and the bsd-specific kqueue mechanisms for file descriptor events, relative timers, absolute timers with customised rescheduling, signal events, process status change events (related to SIGCHLD), and event watchers dealing with the event -loop mechanism itself (idle, prepare and check watchers). +loop mechanism itself (idle, prepare and check watchers). It also is quite +fast (see this L comparing +it to libevent for example). =head1 CONVENTIONS Libev is very configurable. In this manual the default configuration will be described, which supports multiple event loops. For more info -about various configuraiton options please have a look at the file +about various configuration options please have a look at the file F in the libev distribution. If libev was configured without support for multiple event loops, then all functions taking an initial argument of name C (which is always of type C) @@ -41,7 +43,9 @@ will not have this argument. =head1 TIME AND OTHER GLOBAL FUNCTIONS -Libev represents time as a single floating point number. This type is +Libev represents time as a single floating point number, representing the +(fractional) number of seconds since the (POSIX) epoch (somewhere near +the beginning of 1970, details are complicated, don't ask). This type is called C, which is what you should use too. It usually aliases to the double type in C. @@ -69,10 +73,10 @@ not a problem. =item ev_set_allocator (void *(*cb)(void *ptr, long size)) Sets the allocation function to use (the prototype is similar to the -realloc function). It is used to allocate and free memory (no surprises -here). If it returns zero when memory needs to be allocated, the library -might abort or take some potentially destructive action. The default is -your system realloc function. +realloc C function, the semantics are identical). It is used to allocate +and free memory (no surprises here). If it returns zero when memory +needs to be allocated, the library might abort or take some potentially +destructive action. The default is your system realloc function. You could override this function in high-availability programs to, say, free some memory if it cannot allocate memory, to use a special allocator, @@ -84,7 +88,7 @@ Set the callback function to call on a retryable syscall error (such as failed select, poll, epoll_wait). The message is a printable string indicating the system call or subsystem causing the problem. If this callback is set, then libev will expect it to remedy the sitution, no -matter what, when it returns. That is, libev will geenrally retry the +matter what, when it returns. That is, libev will generally retry the requested operation, or, if the condition doesn't go away, do bad stuff (such as abort). @@ -98,9 +102,10 @@ events, and dynamically created loops which do not. If you use threads, a common model is to run the default event loop in your main thread (or in a separate thrad) and for each thread you -create, you also create another event loop. Libev itself does no lockign -whatsoever, so if you mix calls to different event loops, make sure you -lock (this is usually a bad idea, though, even if done right). +create, you also create another event loop. Libev itself does no locking +whatsoever, so if you mix calls to the same event loop in different +threads, make sure you lock (this is usually a bad idea, though, even if +done correctly, because its hideous and inefficient). =over 4 @@ -115,7 +120,7 @@ If you don't know what event loop to use, use the one returned from this function. The flags argument can be used to specify special behaviour or specific -backends to use, and is usually specified as 0 (or EVFLAG_AUTO) +backends to use, and is usually specified as 0 (or EVFLAG_AUTO). It supports the following flags: @@ -128,11 +133,12 @@ thing, believe me). =item EVFLAG_NOENV -If this flag bit is ored into the flag value then libev will I look -at the environment variable C. Otherwise (the default), this -environment variable will override the flags completely. This is useful -to try out specific backends to tets their performance, or to work around -bugs. +If this flag bit is ored into the flag value (or the program runs setuid +or setgid) then libev will I look at the environment variable +C. Otherwise (the default), this environment variable will +override the flags completely if it is found in the environment. This is +useful to try out specific backends to test their performance, or to work +around bugs. =item EVMETHOD_SELECT portable select backend @@ -293,8 +299,8 @@ As long as your watcher is active (has been started but not stopped) you must not touch the values stored in it. Most specifically you must never reinitialise it or call its set method. -You cna check wether an event is active by calling the C macro. To see wether an event is outstanding (but the +You cna check whether an event is active by calling the C macro. To see whether an event is outstanding (but the callback for it has not been called yet) you cna use the C macro. @@ -400,12 +406,26 @@ information given in the last section. =head2 struct ev_io - is my file descriptor readable or writable -I/O watchers check wether a file descriptor is readable or writable +I/O watchers check whether a file descriptor is readable or writable in each iteration of the event loop (This behaviour is called level-triggering because you keep receiving events as long as the condition persists. Remember you cna stop the watcher if you don't want to act on the event and neither want to receive future events). +In general you can register as many read and/or write event watchers oer +fd as you want (as long as you don't confuse yourself). Setting all file +descriptors to non-blocking mode is also usually a good idea (but not +required if you know what you are doing). + +You have to be careful with dup'ed file descriptors, though. Some backends +(the linux epoll backend is a notable example) cannot handle dup'ed file +descriptors correctly if you register interest in two or more fds pointing +to the same file/socket etc. description. + +If you must do this, then force the use of a known-to-be-good backend +(at the time of this writing, this includes only EVMETHOD_SELECT and +EVMETHOD_POLL). + =over 4 =item ev_io_init (ev_io *, callback, int fd, int events) @@ -467,7 +487,7 @@ the timer, and again will automatically restart it if need be. =back -=head2 ev_periodic +=head2 ev_periodic - to cron or not to cron it Periodic watchers are also timers of a kind, but they are very versatile (and unfortunately a bit complex).