/** * Open the stream and return the associated resource. * * @param string $streamName Socket URI. * @param \Hoa\Stream\Context $context Context. * @return resource * @throws \Hoa\Socket\Exception */ protected function &_open($streamName, Stream\Context $context = null) { if (null === $context) { $connection = @stream_socket_client($streamName, $errno, $errstr, $this->getTimeout(), $this->getFlag()); } else { $connection = @stream_socket_client($streamName, $errno, $errstr, $this->getTimeout(), $this->getFlag(), $context->getContext()); } if (false === $connection) { if ($errno === 0) { throw new Exception('Client cannot join %s.', 0, $streamName); } else { throw new Exception('Client returns an error (number %d): %s while trying ' . 'to join %s.', 1, [$errno, $errstr, $streamName]); } } $this->_stack[] = $connection; $id = $this->getNodeId($connection); $this->_node = Consistency\Autoloader::dnew($this->getNodeName(), [$id, $connection, $this]); $this->_nodes[$id] = $this->_node; return $connection; }
/** * Open the stream and return the associated resource. * * @param string $streamName Socket URI. * @param \Hoa\Stream\Context $context Context. * @return resource * @throws \Hoa\Socket\Exception */ protected function &_open($streamName, Stream\Context $context = null) { if (null === $context) { $this->_master = @stream_socket_server($streamName, $errno, $errstr, $this->getFlag()); } else { $this->_master = @stream_socket_server($streamName, $errno, $errstr, $this->getFlag(), $context->getContext()); } if (false === $this->_master) { throw new Exception('Server cannot join %s and returns an error (number %d): %s.', 1, [$streamName, $errno, $errstr]); } $i = count($this->_masters); $this->_masters[$i] = $this->_master; $this->_servers[$i] = $this; $this->_stack[] = $this->_masters[$i]; return $this->_master; }
/** * Open the stream and return the associated resource. * * @access protected * @param string $streamName Stream name (e.g. path or URL). * @param \Hoa\Stream\Context $context Context. * @return resource * @throw \Hoa\File\Exception\FileDoesNotExist * @throw \Hoa\File\Exception */ protected function &_open($streamName, \Hoa\Stream\Context $context = null) { if (substr($streamName, 0, 4) == 'file' && false === is_dir(dirname($streamName))) { throw new Exception('Directory %s does not exist. Could not open file %s.', 0, array(dirname($streamName), basename($streamName))); } if (null === $context) { if (false === ($out = @fopen($streamName, $this->getMode(), true))) { throw new Exception('Failed to open stream %s.', 1, $streamName); } return $out; } $out = @fopen($streamName, $this->getMode(), true, $context->getContext()); if (false === $out) { throw new Exception('Failed to open stream %s.', 2, $streamName); } return $out; }
/** * Open the stream and return the associated resource. * * @param string $streamName Stream name (e.g. path or URL). * @param \Hoa\Stream\Context $context Context. * @return resource * @throws \Hoa\File\Exception\FileDoesNotExist * @throws \Hoa\File\Exception */ protected function &_open($streamName, Stream\Context $context = null) { if (false === is_dir($streamName)) { if ($this->getMode() == self::MODE_READ) { throw new Exception\FileDoesNotExist('Directory %s does not exist.', 0, $streamName); } else { self::create($streamName, $this->getMode(), null !== $context ? $context->getContext() : null); } } $out = null; return $out; }