PHPDaemon\Core\ShellCommand::setFd PHP Method

setFd() public method

Sets fd
public setFd ( resource $fd, EventBufferEvent $bev = null ) : void
$fd resource File descriptor
$bev EventBufferEvent
return void
    public function setFd($fd, $bev = null)
    {
        $this->fd = $fd;
        if ($fd === false) {
            $this->finish();
            return;
        }
        $this->fdWrite = $this->pipes[0];
        $flags = !is_resource($this->fd) ? \EventBufferEvent::OPT_CLOSE_ON_FREE : 0;
        $flags |= \EventBufferEvent::OPT_DEFER_CALLBACKS;
        // buggy option
        if ($this->eventLoop === null) {
            $this->eventLoop = EventLoop::$instance;
        }
        $this->bev = $this->eventLoop->bufferEvent($this->fd, 0, [$this, 'onReadEv'], null, [$this, 'onStateEv']);
        $this->bevWrite = $this->eventLoop->bufferEvent($this->fdWrite, 0, null, [$this, 'onWriteEv'], null);
        if (!$this->bev || !$this->bevWrite) {
            $this->finish();
            return;
        }
        if ($this->priority !== null) {
            $this->bev->priority = $this->priority;
        }
        if ($this->timeout !== null) {
            $this->setTimeout($this->timeout);
        }
        if (!$this->bev->enable(\Event::READ | \Event::TIMEOUT | \Event::PERSIST)) {
            $this->finish();
            return;
        }
        if (!$this->bevWrite->enable(\Event::WRITE | \Event::TIMEOUT | \Event::PERSIST)) {
            $this->finish();
            return;
        }
        $this->bev->setWatermark(\Event::READ, $this->lowMark, $this->highMark);
        init:
        if (!$this->inited) {
            $this->inited = true;
            $this->init();
        }
    }