/** * @see \Components\Io_Channel_Writable::write() \Components\Io_Channel_Writable::write() */ public function write(Io_Buffer $buffer_) { $offset = $buffer_->position(); if ($buffer_ instanceof Io_Buffer_String) { if (false === @fwrite($this->m_pipe, (string) $buffer_)) { throw new Io_Exception('io/pipe/sink', sprintf('Unable to write to pipe [%s].', $this)); } $buffer_->position($buffer_->limit()); } else { if (false === @fwrite($this->m_pipe, implode('', $buffer_->arrayValue()))) { throw new Io_Exception('io/pipe/sink', sprintf('Unable to write to pipe [%s].', $this)); } $buffer_->position($buffer_->limit()); } return $buffer_->position() - $offset; }
/** * @see \Components\Io_Channel_Readable::read() \Components\Io_Channel_Readable::read() */ public function read(Io_Buffer $buffer_, $interrupt_ = null) { $offset = $buffer_->position(); if ($buffer_ instanceof Io_Buffer_String) { // TODO Implement $interrupt_. while ($buffer_->limit() > $buffer_->position()) { if (false === ($read = @fread($this->m_pipe, $buffer_->limit()))) { throw new Io_Exception('io/pipe/source', sprintf('Unable to read from pipe [%s].', $this)); } $buffer_->append($read); } } else { while ($buffer_->limit() > $buffer_->position()) { if (false === ($read = @fread($this->m_pipe, 1))) { throw new Io_Exception('io/pipe/source', sprintf('Unable to read from pipe [%s].', $this)); } $buffer_->append($read = ord($read)); if ($interrupt_ === $read) { break; } } } return $buffer_->position() - $offset; }