简介:
NAME名字
SYNOPSIS概要
EXAMPLE PROGRAM示例程序
ABOUT THIS DOCUMENT 关于文档
WHAT TO READ WHEN IN A HURRY 快速阅读
ABOUT LIBEV 关于libev
FEATURES 特点
CONVENTIONS 约定
TIME REPRESENTATION 时间描述
ERROR HANDLING 错误处理
GLOBAL FUNCTIONS 全局函数
ev_tstamp ev_time ()
ev_sleep (ev_tstamp interval)
int ev_version_major ()
int ev_version_minor ()
unsigned int ev_supported_backends ()
unsigned int ev_recommended_backends ()
unsigned int ev_embeddable_backends ()
ev_set_allocator (void *(*cb)(void *ptr, long size
ev_set_syserr_cb (void (*cb)(const char *msg))
ev_feed_signal (int signum)
FUNCTIONS CONTROLLING EVENT LOOPS
struct ev_loop *ev_default_loop (unsigned int flag
struct ev_loop *ev_loop_new (unsigned int flags)
EVFLAG_AUTO
EVFLAG_NOENV
EVFLAG_FORKCHECK
EVFLAG_NOINOTIFY
EVFLAG_SIGNALFD
EVFLAG_NOSIGMASK
EVBACKEND_SELECT (value 1, portable select backend
EVBACKEND_POLL (value 2, poll backend, available e
EVBACKEND_EPOLL (value 4, Linux)
EVBACKEND_KQUEUE (value 8, most BSD clones)
EVBACKEND_DEVPOLL (value 16, Solaris 8)
EVBACKEND_PORT (value 32, Solaris 10)
EVBACKEND_ALL
EVBACKEND_MASK
ev_loop_destroy (loop)
ev_loop_fork (loop)
int ev_is_default_loop (loop)
unsigned int ev_iteration (loop)
unsigned int ev_depth (loop)
unsigned int ev_backend (loop)
ev_tstamp ev_now (loop)
ev_now_update (loop)
ev_suspend (loop)
ev_resume (loop)
ev_run (loop, int flags)
ev_break (loop, how)
ev_ref (loop)
ev_unref (loop)
ev_set_io_collect_interval (loop, ev_tstamp interv
ev_set_timeout_collect_interval (loop, ev_tstamp i
ev_invoke_pending (loop)
int ev_pending_count (loop)
ev_set_invoke_pending_cb (loop, void (*invoke_pend
ev_set_loop_release_cb (loop, void (*release)(EV_P
ev_set_userdata (loop, void *data)
void *ev_userdata (loop)
ev_verify (loop)
ANATOMY OF A WATCHER
EV_READ
EV_WRITE
EV_TIMER
EV_PERIODIC
EV_SIGNAL
EV_CHILD
EV_STAT
EV_IDLE
EV_PREPARE
EV_CHECK
EV_EMBED
EV_FORK
EV_CLEANUP
EV_ASYNC
EV_CUSTOM
EV_ERROR
GENERIC WATCHER FUNCTIONS
ev_init (ev_TYPE *watcher, callback)
ev_TYPE_set (ev_TYPE *watcher, [args])
ev_TYPE_init (ev_TYPE *watcher, callback, [args])
ev_TYPE_start (loop, ev_TYPE *watcher)
ev_TYPE_stop (loop, ev_TYPE *watcher)
bool ev_is_active (ev_TYPE *watcher)
bool ev_is_pending (ev_TYPE *watcher)
callback ev_cb (ev_TYPE *watcher)
ev_cb_set (ev_TYPE *watcher, callback)
ev_set_priority (ev_TYPE *watcher, int priority)
int ev_priority (ev_TYPE *watcher)
ev_invoke (loop, ev_TYPE *watcher, int revents)
int ev_clear_pending (loop, ev_TYPE *watcher)
ev_feed_event (loop, ev_TYPE *watcher, int revents
WATCHER STATES
initialiased
started/running/active
pending
stopped
WATCHER PRIORITY MODELS
WATCHER TYPES
ev_io - is this file descriptor readable or writab
The special problem of disappearing file descripto
The special problem of dup'ed file descriptors
The special problem of files
The special problem of fork
The special problem of SIGPIPE
The special problem of accept()ing when you can't
Watcher-Specific Functions
ev_io_init (ev_io *, callback, int fd, int events)
ev_io_set (ev_io *, int fd, int events)
int fd [read-only]
int events [read-only]
Examples
ev_timer - relative and optionally repeating timeo
Be smart about timeouts
1. Use a timer and stop, reinitialise and start it
2. Use a timer and re-start it with ev_timer_again
3. Let the timer time out, but then re-arm it as r
4. Wee, just use a double-linked list for your tim
The special problem of being too early
The special problem of time updates
The special problem of unsynchronised clocks
The special problems of suspended animation
Watcher-Specific Functions and Data Members
ev_timer_init (ev_timer *, callback, ev_tstamp aft
ev_timer_set (ev_timer *, ev_tstamp after, ev_tsta
ev_timer_again (loop, ev_timer *)
ev_tstamp ev_timer_remaining (loop, ev_timer *)
ev_tstamp repeat [read-write]
Examples
ev_periodic - to cron or not to cron?
Watcher-Specific Functions and Data Members
ev_periodic_init (ev_periodic *, callback, ev_tsta
ev_periodic_set (ev_periodic *, ev_tstamp offset,
* absolute timer (offset = absolute time, interval
* repeating interval timer (offset = offset within
* manual reschedule mode (offset ignored, interval
ev_periodic_again (loop, ev_periodic *)
ev_tstamp ev_periodic_at (ev_periodic *)
ev_tstamp offset [read-write]
ev_tstamp interval [read-write]
ev_tstamp (*reschedule_cb)(ev_periodic *w, ev_tsta
Examples
ev_signal - signal me when a signal gets signalled
The special problem of inheritance over fork/execv
The special problem of threads signal handling
Watcher-Specific Functions and Data Members
ev_signal_init (ev_signal *, callback, int signum)
ev_signal_set (ev_signal *, int signum)
int signum [read-only]
Examples
ev_child - watch out for process status changes
Process Interaction
Overriding the Built-In Processing
Stopping the Child Watcher
Watcher-Specific Functions and Data Members
ev_child_init (ev_child *, callback, int pid, int
ev_child_set (ev_child *, int pid, int trace)
int pid [read-only]
int rpid [read-write]
int rstatus [read-write]
Examples
ev_stat - did the file attributes just change?
ABI Issues (Largefile Support)
Inotify and Kqueue
stat () is a synchronous operation
The special problem of stat time resolution
Watcher-Specific Functions and Data Members
ev_stat_init (ev_stat *, callback, const char *pat
ev_stat_set (ev_stat *, const char *path, ev_tstam
ev_stat_stat (loop, ev_stat *)
ev_statdata attr [read-only]
ev_statdata prev [read-only]
ev_tstamp interval [read-only]
const char *path [read-only]
Examples
ev_idle - when you've got nothing better to do...
Watcher-Specific Functions and Data Members
ev_idle_init (ev_idle *, callback)
Examples
ev_prepare and ev_check - customise your event loo
Watcher-Specific Functions and Data Members
ev_prepare_init (ev_prepare *, callback)
ev_check_init (ev_check *, callback)
Examples
ev_embed - when one backend isn't enough...
ev_embed and fork
Watcher-Specific Functions and Data Members
ev_embed_init (ev_embed *, callback, struct ev_loo
ev_embed_set (ev_embed *, callback, struct ev_loop
ev_embed_sweep (loop, ev_embed *)
struct ev_loop *other [read-only]
Examples
ev_fork - the audacity to resume the event loop af
The special problem of life after fork - how is it
Watcher-Specific Functions and Data Members
ev_fork_init (ev_fork *, callback)
ev_cleanup - even the best things end
Watcher-Specific Functions and Data Members
ev_cleanup_init (ev_cleanup *, callback)
ev_async - how to wake up an event loop
Queueing
queueing from a signal handler context
queueing from a thread context
Watcher-Specific Functions and Data Members
ev_async_init (ev_async *, callback)
ev_async_send (loop, ev_async *)
bool = ev_async_pending (ev_async *)
OTHER FUNCTIONS
ev_once (loop, int fd, int events, ev_tstamp timeo
ev_feed_fd_event (loop, int fd, int revents)
ev_feed_signal_event (loop, int signum)
COMMON OR USEFUL IDIOMS (OR BOTH)
ASSOCIATING CUSTOM DATA WITH A WATCHER
BUILDING YOUR OWN COMPOSITE WATCHERS
MODEL/NESTED EVENT LOOP INVOCATIONS AND EXIT CONDI
THREAD LOCKING EXAMPLE
THREADS, COROUTINES, CONTINUATIONS, QUEUES... INST
LIBEVENT EMULATION
C++ SUPPORT
ev::READ, ev::WRITE etc.
ev::tstamp, ev::now
ev::io, ev::timer, ev::periodic, ev::idle, ev::sig
ev::TYPE::TYPE ()
ev::TYPE::TYPE (loop)
ev::TYPE::~TYPE
w->set (object *)
w->set (object *)
w->set (void *data = 0)
w->set (loop)
w->set ([arguments])
w->start ()
w->start ([arguments])
w->stop ()
w->again () (ev::timer, ev::periodic only)
w->sweep () (ev::embed only)
w->update () (ev::stat only)
OTHER LANGUAGE BINDINGS
Perl
Python
Ruby
Haskell
D
Ocaml
Lua
MACRO MAGIC
EV_A, EV_A_
EV_P, EV_P_
EV_DEFAULT, EV_DEFAULT_
EV_DEFAULT_UC, EV_DEFAULT_UC_
EMBEDDING
FILESETS
CORE EVENT LOOP
LIBEVENT COMPATIBILITY API
AUTOCONF SUPPORT
PREPROCESSOR SYMBOLS/MACROS
EV_COMPAT3 (h)
EV_STANDALONE (h)
EV_USE_FLOOR
EV_USE_MONOTONIC
EV_USE_REALTIME
EV_USE_CLOCK_SYSCALL
EV_USE_NANOSLEEP
EV_USE_EVENTFD
EV_USE_SELECT
EV_SELECT_USE_FD_SET
EV_SELECT_IS_WINSOCKET
EV_FD_TO_WIN32_HANDLE(fd)
EV_WIN32_HANDLE_TO_FD(handle)
EV_WIN32_CLOSE_FD(fd)
EV_USE_POLL
EV_USE_EPOLL
EV_USE_KQUEUE
EV_USE_PORT
EV_USE_DEVPOLL
EV_USE_INOTIFY
EV_ATOMIC_T
EV_H (h)
EV_CONFIG_H (h)
EV_EVENT_H (h)
EV_PROTOTYPES (h)
EV_MULTIPLICITY
EV_MINPRI
EV_MAXPRI
EV_PERIODIC_ENABLE, EV_IDLE_ENABLE, EV_EMBED_ENABL
EV_FEATURES
1 - faster/larger code
2 - faster/larger data structures
4 - full API configuration
8 - full API
16 - enable all optional watcher types
32 - enable all backends
64 - enable OS-specific "helper" APIs
EV_AVOID_STDIO
EV_NSIG
EV_PID_HASHSIZE
EV_INOTIFY_HASHSIZE
EV_USE_4HEAP
EV_HEAP_CACHE_AT
EV_VERIFY
EV_COMMON
EV_CB_DECLARE (type)
EV_CB_INVOKE (watcher, revents)
ev_set_cb (ev, cb)
EXPORTED API SYMBOLS
EXAMPLES
INTERACTION WITH OTHER PROGRAMS, LIBRARIES OR THE
THREADS AND COROUTINES
THREADS
* most applications have a main thread: use the de
* one loop per thread is usually a good model.
* other models exist, such as the leader/follower
* often you need to talk to some other thread whic
COROUTINES
COMPILER WARNINGS
VALGRIND
PORTABILITY NOTES
GNU/LINUX 32 BIT LIMITATIONS
OS/X AND DARWIN BUGS
kqueue is buggy
poll is buggy
select is buggy
SOLARIS PROBLEMS AND WORKAROUNDS
errno reentrancy
Event port backend
AIX POLL BUG
WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS
General issues
The winsocket select function
Limited number of file descriptors
PORTABILITY REQUIREMENTS
void (*)(ev_watcher_type *, int revents) must have
pointer accesses must be thread-atomic
sig_atomic_t volatile must be thread-atomic as wel
sigprocmask must work in a threaded environment
long must be large enough for common memory alloca
double must hold a time value in seconds with enou
ALGORITHMIC COMPLEXITIES
Starting and stopping timer/periodic watchers: O(l
Changing timer/periodic watchers (by autorepeat or
Starting io/check/prepare/idle/signal/child/fork/a
Stopping check/prepare/idle/fork/async watchers: O
Stopping an io/signal/child watcher: O(number_of_w
Finding the next timer in each loop iteration: O(1
Each change on a file descriptor per loop iteratio
Activating one watcher (putting it into the pendin
Priority handling: O(number_of_priorities)
Sending an ev_async: O(1)
Processing ev_async_send: O(number_of_async_watche
Processing signals: O(max_signal_number)
PORTING FROM LIBEV 3.X TO 4.X
EV_COMPAT3 backwards compatibility mechanism
ev_default_destroy and ev_default_fork have been r
function/symbol renames
EV_MINIMAL mechanism replaced by EV_FEATURES
GLOSSARY
active
application
backend
callback
callback/watcher invocation
event
event library
event loop
event model
pending
real time
wall-clock time
watcher
AUTHOR