/** * {@inheritdoc} */ protected function activate(array $watchers) { foreach ($watchers as $watcher) { if (!isset($this->events[$id = $watcher->id])) { switch ($watcher->type) { case Watcher::READABLE: $this->events[$id] = $this->handle->io($watcher->value, \Ev::READ, $this->ioCallback, $watcher); break; case Watcher::WRITABLE: $this->events[$id] = $this->handle->io($watcher->value, \Ev::WRITE, $this->ioCallback, $watcher); break; case Watcher::DELAY: case Watcher::REPEAT: $interval = $watcher->value / self::MILLISEC_PER_SEC; $this->events[$id] = $this->handle->timer($interval, $watcher->type & Watcher::REPEAT ? $interval : 0, $this->timerCallback, $watcher); break; case Watcher::SIGNAL: $this->events[$id] = $this->handle->signal($watcher->value, $this->signalCallback, $watcher); break; default: throw new \DomainException("Unknown watcher type"); } } else { $this->events[$id]->start(); } } }
/** * @param resource $stream * @param callable $listener */ public function addWriteStream($stream, callable $listener) { $callback = function () use($stream, $listener) { call_user_func($listener, $stream, $this); }; $event = $this->loop->io($stream, \Ev::WRITE, $callback); $this->writeEvents[(int) $stream] = $event; }
/** * {@inheritdoc} */ protected function enableWriteWatcher(StreamWatcher $watcher) { if ($watcher->event === null) { $watcher->event = $this->loop->io($watcher->stream, \Ev::WRITE, $this->streamCallback, $watcher); } else { $watcher->event->start(); } }
/** * {@inheritdoc} */ public function create($resource, callable $callback) : SocketEventInterface { $id = (int) $resource; if (isset($this->events[$id])) { throw new ResourceBusyError('A poll has already been created for that resource.'); } $socket = $this->factory->socket($this, $resource, $callback); $event = $this->loop->io($resource, $this->type, $this->socketCallback, $socket); $event->stop(); $this->events[$id] = $event; return $socket; }
/** * {@inheritdoc} */ public function create($resource, callable $callback, bool $persistent = false) : Io { $id = (int) $resource; if (isset($this->events[$id])) { throw new ResourceBusyError(); } $socket = new Io($this, $resource, $callback, $persistent); $event = $this->loop->io($resource, $this->type, $this->socketCallback, $socket); $event->stop(); $this->events[$id] = $event; return $socket; }