/** * @param \Icicle\Loop\UvLoop $loop * @param \Icicle\Loop\Events\EventFactoryInterface $factory */ public function __construct(UvLoop $loop, EventFactoryInterface $factory) { parent::__construct($loop, $factory); $loopHandle = $loop->getLoopHandle(); $signalCallback = $this->createSignalCallback(); $callback = function ($sigHandle, int $signo) use($signalCallback) { $signalCallback($signo); }; foreach ($this->getSignalList() as $signo) { $sigHandle = \uv_signal_init($loopHandle); \uv_signal_start($sigHandle, $callback, $signo); $this->sigHandles[$signo] = $sigHandle; } }
/** * {@inheritdoc} */ protected function enableSignalWatcher(SignalWatcher $watcher) { if ($watcher->event === null) { if (isset($this->signalEvents[$watcher->signo])) { $watcher->event = $this->signalEvents[$watcher->signo]; } else { $watcher->event = \uv_signal_init($this->loop); } } if (!\uv_is_active($watcher->event)) { \uv_signal_start($watcher->event, $this->signalCallback, $watcher->signo); } $this->signalWatchers[$watcher->signo][$watcher->id] = $watcher; }
/** * {@inheritDoc} */ public function enable($watcherId) { if (!isset($this->watchers[$watcherId])) { return; } $watcher = $this->watchers[$watcherId]; if ($watcher->isEnabled) { return; } $watcher->isEnabled = true; $this->keepAliveCount += $watcher->keepAlive; switch ($watcher->type) { case Watcher::TIMER_ONCE: // fallthrough // fallthrough case Watcher::TIMER_REPEAT: \uv_timer_start($watcher->uvHandle, $watcher->msDelay, $watcher->msInterval, $watcher->callback); break; case Watcher::IO_READER: // fallthrough // fallthrough case Watcher::IO_WRITER: $this->enablePollFromWatcher($watcher); break; case Watcher::SIGNAL: \uv_signal_start($watcher->uvHandle, $watcher->callback, $watcher->signo); break; case Watcher::IMMEDIATE: $this->immediates[$watcherId] = $watcher; break; default: throw new \RuntimeException("Unexpected Watcher type encountered"); } }