EvSignal
final class EvSignal extends EvWatcher (View source)
Class EvSignal
EvSignal watchers will trigger an event when the process receives a specific signal one or more times. Even though signals are very asynchronous, libev will try its best to deliver signals synchronously, i.e. as part of the normal event processing, like any other event.
There is no limit for the number of watchers for the same signal, but only within the same loop, i.e. one can watch for SIGINT in the default loop and for SIGIO in another loop, but it is not allowed to watch for SIGINT in both the default loop and another loop at the same time. At the moment, SIGCHLD is permanently tied to the default loop.
If possible and supported, libev will install its handlers with SA_RESTART (or equivalent) behaviour enabled, so system calls should not be unduly interrupted. In case of a problem with system calls getting interrupted by signals, all the signals can be blocked in an EvCheck watcher and unblocked in a EvPrepare watcher.
Properties
bool | $is_active | from EvWatcher | |
bool | $is_pending | from EvWatcher | |
mixed | $data | from EvWatcher | |
int | $priority | from EvWatcher | |
int | $signum |
Methods
Constructs EvSignal watcher object
Invokes the watcher callback with the given received events bit mask.
Configures the watcher.
Creates a stopped instance of EvSignal watcher.
Details
__construct(int $signum, callable $callback, mixed $data = null, int $priority = 0)
Constructs EvSignal watcher object
int
clear()
Clear watcher pending status.
If the watcher is pending, this method clears its pending status and returns its revents bitset (as if its callback was invoked). If the watcher isn't pending it does nothing and returns 0.
Sometimes it can be useful to "poll" a watcher instead of waiting for its callback to be invoked, which can be accomplished with this function.
feed(int $revents)
Feeds the given revents set into the event loop.
Feeds the given revents set into the event loop, as if the specified event had happened for the watcher.
EvLoop
getLoop()
Returns the loop responsible for the watcher.
invoke(int $revents)
Invokes the watcher callback with the given received events bit mask.
keepalive(bool $value = true)
Configures whether to keep the loop from returning.
Configures whether to keep the loop from returning. With keepalive value set to FALSE the watcher won't keep Ev::run() / EvLoop::run() from returning even though the watcher is active.
Watchers have keepalive value TRUE by default.
Clearing keepalive status is useful when returning from Ev::run() / EvLoop::run() just because of the watcher is undesirable. It could be a long running UDP socket watcher or so.
setCallback(callable $callback)
Sets new callback for the watcher.
start()
Starts the watcher.
Marks the watcher as active. Note that only active watchers will receive events.
stop()
Stops the watcher.
Marks the watcher as inactive. Note that only active watchers will receive events.
set(int $signum)
Configures the watcher.
final static EvSignal
createStopped(int $signum, mixed $callback, mixed $data = null, int $priority = 0)
Creates a stopped instance of EvSignal watcher.
Creates a stopped instance of EvSignal watcher. Unlike EvPrepare::__construct(), this method doesn't start the watcher automatically.