示例#1
0
 public function setFD($readFD, $writeFD = NULL)
 {
     $this->readFD = $readFD;
     $this->writeFD = $writeFD;
     if (!is_resource($this->readFD)) {
         throw new BadStreamDescriptorException('wrong readFD', 1);
     }
     if ($this->readBuf === NULL) {
         if (!stream_set_blocking($this->readFD, 0)) {
             throw new Exception('setting blocking for read stream failed');
         }
         $this->readBuf = event_buffer_new($this->readFD, array($this, 'onReadEvent'), array($this, 'onWriteEvent'), array($this, 'onReadFailureEvent'), array());
         if (!$this->readBuf) {
             throw new Exception('creating read buffer failed');
         }
         if (!event_buffer_base_set($this->readBuf, Daemon::$worker->eventBase)) {
             throw new Exception('wrong base');
         }
         if (event_buffer_priority_set($this->readBuf, $this->readPriority) === FALSE && FALSE) {
             throw new Exception('setting priority for read buffer failed');
         }
     } else {
         if (!stream_set_blocking($this->readFD, 0)) {
             throw new Exception('setting blocking for read stream failed');
         }
         if (!event_buffer_fd_set($this->readBuf, $this->readFD)) {
             throw new Exception('setting descriptor for write buffer failed');
         }
     }
     if ($this->writeFD === NULL) {
         return $this;
     }
     if (!is_resource($this->writeFD)) {
         throw new BadStreamDescriptorException('wrong writeFD', 1);
     }
     if ($this->writeBuf === NULL) {
         if (!stream_set_blocking($this->writeFD, 0)) {
             throw new Exception('setting blocking for write stream failed');
         }
         $this->writeBuf = event_buffer_new($this->writeFD, NULL, array($this, 'onWriteEvent'), array($this, 'onWriteFailureEvent'), array());
         if (!$this->writeBuf) {
             throw new Exception('creating write buffer failed');
         }
         if (!event_buffer_base_set($this->writeBuf, Daemon::$worker->eventBase)) {
             throw new Exception('wrong base');
         }
         if (event_buffer_priority_set($this->writeBuf, $this->writePriority) === FALSE && FALSE) {
             throw new Exception('setting priority for write buffer failed');
         }
     } else {
         stream_set_blocking($this->writeFD, 0);
         event_buffer_fd_set($this->buf, $this->writeFD);
     }
     return $this;
 }
示例#2
0
 /**
  * Changes the stream on which the buffered event operates.
  *
  * @see event_buffer_fd_set
  *
  * @throws \InvalidArgumentException
  *
  * @param resource $stream Valid PHP stream, must be castable to file descriptor.
  *
  * @return EventBuffer
  */
 public function setStream($stream)
 {
     if (!is_resource($stream)) {
         throw new \InvalidArgumentException('Invalid fd set for buffer event.');
     }
     event_buffer_fd_set($this->resource, $stream);
     return $this;
 }