The Ev class
Ev is a static class providing access to the default loop and to some common operations.
Intro
Ev is a static class providing access to the default loop and to some common operations.
Class synopsis
Predefined Constants
Flags passed to create a loop:
Ev::FLAG_AUTOThe default flags value
Ev::FLAG_NOENVIf this flag used(or the program runs setuid or setgid),
libevwon't look at the environment variableLIBEV_FLAGS. Otherwise(by default),LIBEV_FLAGSwill override the flags completely if it is found. Useful for performance tests and searching for bugs.Ev::FLAG_FORKCHECKMakes libev check for a fork in each iteration, instead of calling
EvLoop::forkmanually. This works by callinggetpid()on every iteration of the loop, and thus this might slow down the event loop with lots of loop iterations, but usually is not noticeable. This flag setting cannot be overridden or specified in theLIBEV_FLAGSenvironment variable.Ev::FLAG_NOINOTIFYWhen this flag is specified,
libevwon't attempt to use theinotifyAPI for its ev_stat watchers. The flag can be useful to conserve inotify file descriptors, as otherwise each loop usingev_statwatchers consumes oneinotifyhandle.Ev::FLAG_SIGNALFDWhen this flag is specified,
libevwill attempt to use thesignalfdAPI for its ev_signal (and ev_child) watchers. This API delivers signals synchronously, which makes it both faster and might make it possible to get the queued signal data. It can also simplify signal handling with threads, as long as signals are properly blocked in threads.Signalfdwill not be used by default.Ev::FLAG_NOSIGMASKWhen this flag is specified,
libevwill avoid to modify the signal mask. Specifically, this means having to make sure signals are unblocked before receiving them.This behaviour is useful for custom signal handling, or handling signals only in specific threads.
Flags passed to Ev::run, or EvLoop::run
Ev::RUN_NOWAITMeans that event loop will look for new events, will handle those events and any already outstanding ones, but will not wait and block the process in case there are no events and will return after one iteration of the loop. This is sometimes useful to poll and handle new events while doing lengthy calculations, to keep the program responsive.
Ev::RUN_ONCEMeans that event loop will look for new events (waiting if necessary) and will handle those and any already outstanding ones. It will block the process until at least one new event arrives (which could be an event internal to libev itself, so there is no guarantee that a user-registered callback will be called), and will return after one iteration of the loop.
Flags passed to Ev::stop, or EvLoop::stop
Ev::BREAK_CANCELCancel the break operation.
Ev::BREAK_ONEMakes the innermost
Ev::run(orEvLoop::run) call return.Ev::BREAK_ALLMakes all nested
Ev::run(orEvLoop::run) calls return.
Watcher priorities:
Ev::MINPRIMinimum allowed watcher priority.
Ev::MAXPRIMaximum allowed watcher priority.
Bit masks of (received) events:
Ev::READThe file descriptor in the
EvIowatcher has become readable.Ev::WRITEThe file descriptor in the
EvIowatcher has become writable.Ev::TIMEREvTimerwatcher has been timed out.Ev::PERIODICEvPeriodicwatcher has been timed out.Ev::SIGNALA signal specified in
EvSignal::__constructhas been received.Ev::CHILDThe
pidspecified inEvChild::__constructhas received a status change.Ev::STATThe path specified in
EvStatwatcher changed its attributes.Ev::IDLEEvIdlewatcher works when there is nothing to do with other watchers.Ev::PREPAREAll
EvPreparewatchers are invoked just beforeEv::runstarts. Thus,EvPreparewatchers are the last watchers invoked before the event loop sleeps or polls for new events.Ev::CHECKAll
EvCheckwatchers are queued just afterEv::runhas gathered the new events, but before it queues any callbacks for any received events. Thus,EvCheckwatchers will be invoked before any other watchers of the same or lower priority within an event loop iteration.Ev::EMBEDThe embedded event loop specified in the
EvEmbedwatcher needs attention.Ev::CUSTOMNot ever sent(or otherwise used) by
libevitself, but can be freely used bylibevusers to signal watchers (e.g. viaEvWatcher::feed).Ev::ERRORAn unspecified error has occurred, the watcher has been stopped. This might happen because the watcher could not be properly started because
libevran out of memory, a file descriptor was found to be closed or any other problem.Libevconsiders these application bugs. See also ANATOMY OF A WATCHER
Backend flags:
Ev::BACKEND_SELECTselect(2) backendEv::BACKEND_POLLpoll(2) backendEv::BACKEND_EPOLLLinux-specific
epoll(7)backend for both pre- and post-2.6.9 kernelsEv::BACKEND_KQUEUEkqueuebackend used on most BSD systems.EvEmbedwatcher could be used to embed one loop(with kqueue backend) into another. For instance, one can try to create an event loop withkqueuebackend and use it for sockets only.Ev::BACKEND_DEVPOLLSolaris 8 backend. This is not implemented yet.
Ev::BACKEND_PORTSolaris 10 event port mechanism with a good scaling.
Ev::BACKEND_ALLTry all backends(even corrupted ones). It's not recommended to use it explicitly. Bitwise operators should be applied here(e.g.
Ev::BACKEND_ALL& ~Ev::BACKEND_KQUEUE) UseEv::recommendedBackends, or don't specify any backends at all.Ev::BACKEND_MASKNot a backend, but a mask to select all backend bits from
flagsvalue to mask out any backends(e.g. when modifying theLIBEV_FLAGSenvironment variable).
For the default loop during module initialization phase Ev registers ev_loop_fork call by means of pthread_atfork (if available).
There are methods providing access to the default event loop in Ev class(e.g. Ev::iteration, Ev::depth etc.) For custom loops (created with EvLoop::__construct) these values may be accessed via corresponding properties and methods of the EvLoop class.
The instance of the default event loop itself can be fetched by means of EvLoop::defaultLoop method.
Ev