Returns the next available frame from the connection, respecting the connect timeout.

@return null|Frame
@throws ConnectionException
@throws Exception\ErrorFrameException
166528
private function getConnectedFrame()
    {
        $deadline = microtime(true) + $this->getConnection()->getConnectTimeout();
        do {
            if ($frame = $this->connection->readFrame()) {
                return $frame;
            }
        } while (microtime(true) <= $deadline);

        return null;
    }
264668
protected function NextItem()
	{
		if ( $this->empty ) return null;

		/**
		 * @var int $index
		 */
		$index = $this->getCurrentPosition() + 1;
		if ( $index < count( $this->buffer ) )
		{
			return $this->buffer[ $index ];
		}
		else if ( ! $this->filled )
		{
			if ( ! $this->src->getIsFinished() )
			{
				if ( $this->src->MoveNext() )
				{
					$current = $this->src->getCurrent();
					$this->buffer[] = $current;
					return $current;
				}
				else
				{
					$this->filled = true;
				}
			}

			if ( ! count( $this->buffer ) )
			{
				$this->empty = true;
			}
		}

		return null;
	}
1296069
public function next()
    {
        if (!$this->isEnabled) {
            return;
        }
        // If the size limit exceeds the page size, and the next page would exceed the limit, reduce the page size...
        if ($this->sizeLimit && ($this->resultNumber + $this->pageSize) > $this->sizeLimit) {
            $this->pageSize = $this->sizeLimit - $this->resultNumber;
        }
        if (!@ldap_control_paged_result($this->connection->getResource(), $this->pageSize, false, $this->cookie)) {
            throw new LdapConnectionException(sprintf(
                'Unable to enable paged results (%s): %s',
                $this->connection->getLastErrorNumber(),
                $this->connection->getLastError()
            ), $this->connection->getLastErrorNumber());
        }
    }
885983
public function readFrame()
    {
        // first we try to check the parser for any leftover frames
        if ($frame = $this->parser->nextFrame()) {
            return $this->onFrame($frame);
        }

        if (!$this->hasDataToRead()) {
            return false;
        }

        do {
            $read = @fread($this->connection, $this->maxReadBytes);
            if ($read === false) {
                throw new ConnectionException(sprintf('Was not possible to read data from stream.'), $this->activeHost);
            }

            // this can be caused by different events on the stream, ex. new data or any kind of signal
            // it also happens when a ssl socket was closed on the other side... so we need to test
            if ($read === '') {
                $this->observers->emptyRead();
                // again we give some time here
                // as this path is most likely indicating that the socket is not working anymore
                time_nanosleep(0, 5000000); // 5ms / 0.005s
                return false;
            }

            $this->parser->addData($read);

            if ($frame = $this->parser->nextFrame()) {
                return $this->onFrame($frame);
            }
        } while ($this->isDataOnStream());

        return false;
    }
624784
public function next() {
        if (!isset($this->current)) {
            throw new BadMethodCallException('You need to call method "load()" first.');
        }

        for ($ipLong = $this->current; $ipLong <= $this->last; $ipLong++) {
            $this->current = $ipLong;

            if ($this->isUsed($ipLong) === false) {
                return long2ip($ipLong);
            }
        }

        throw new RuntimeException('No free IP addresses left');
    }
965722
function Next()
    {
    	if ($this->UnableToCache)
    	{
    		require_once("verysimple/Util/ExceptionFormatter.php");
    		$info = ExceptionFormatter::FormatTrace(debug_backtrace());
    		$this->_phreezer->Observe("(DataSet.Next: unable to cache query with cursor) " . $info . "  " . $this->_sql,OBSERVE_DEBUG);

    		// use this line to discover where an uncachable query is coming from
    		// throw new Exception("WTF");

    		// stop this warning from repeating on every next call for this dataset
    	    $this->UnableToCache = false;
    	}

        $this->_verifyRs();

		$this->_current = null;
		$this->_counter++;

        if ($this->_eof)
        {
			if (!$this->_no_exception)
				throw new Exception("EOF: This is a forward-only dataset.");
        }

        if ($row = $this->_phreezer->DataAdapter->Fetch($this->_rs))
        {
            $this->_current = $this->_getObject($row);
			$this->_last = $this->_current;
		}
        else
        {
            $this->_eof = true;
        }

		return $this->_current;
    }
532090
public function moveNext()
    {
        $this->peek = 0;
        $this->token = $this->next;
        $this->next = isset($this->tokens[++$this->i]) ? $this->tokens[$this->i] : null;

        return null !== $this->next;
    }
252152
protected function findAvailableConnection()
    {
        $servers = $this->credentials;
        shuffle($servers);
        $previous = null;

        foreach ($servers as $server) {
            try {
                $node = $this->getNodeConnection($server);
            } catch (ConnectionException $e) {
                $previous = $e;
                continue;
            }

            if ($node->isConnected()) {
                return $node;
            }
        }

        throw new ConnectionException('No servers available', 0, $previous);
    }
1177710
public function next()
    {
        if (count($this->data) > 0) {
            array_shift($this->data);
        }
        ++$this->position;

        if (count($this->data) == 0 && !is_null($this->resumptionToken)) {
            $this->fetchMore();
        }

        if (count($this->data) == 0) {
            return null;
        }
    }
1118610
public function NextLink()
    {
        if ($this->NotLastPage()) {
            return HTTP::setGetVar(
                $this->getPaginationGetVar(),
                $this->getPageStart() + $this->getPageLength(),
                ($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null
            );
        }
    }
417954
public function connect()
    {
        if ($this->state !== ClientStateEnum::NOT_CONNECTED) {
            return Promise\reject(new ClientException("Client already connected/connecting."));
        }

        $this->state = ClientStateEnum::CONNECTING;
        $this->writer->appendProtocolHeader($this->writeBuffer);

        try {
            $this->eventLoop->addReadStream($this->getStream(), [$this, "onDataAvailable"]);
        } catch (\Exception $e) {
            return Promise\reject($e);
        }

        return $this->flushWriteBuffer()->then(function () {
            return $this->awaitConnectionStart();

        })->then(function (MethodConnectionStartFrame $start) {
            return $this->authResponse($start);

        })->then(function () {
            return $this->awaitConnectionTune();

        })->then(function (MethodConnectionTuneFrame $tune) {
            $this->frameMax = $tune->frameMax;
            if ($tune->channelMax > 0) {
                $this->channelMax = $tune->channelMax;
            }
            return $this->connectionTuneOk($tune->channelMax, $tune->frameMax, $this->options["heartbeat"]);

        })->then(function () {
            return $this->connectionOpen($this->options["vhost"]);

        })->then(function () {
            $this->heartbeatTimer = $this->eventLoop->addTimer($this->options["heartbeat"], [$this, "onHeartbeat"]);

            $this->state = ClientStateEnum::CONNECTED;
            return $this;

        });
    }
1072086
protected function getCurrentFrame()
    {
        if (empty($this->frames)) {
            array_push($this->frames, $this->getFrame());
        }
        return end($this->frames);
    }
965197
public function getFrames()
    {
        if ($this->frames === null) {
            $frames = $this->exception->getTrace();

            // If we're handling an \ErrorException thrown by BooBoo,
            // get rid of the last frame, which matches the handleError method,
            // and do not add the current exception to trace. We ensure that
            // the next frame does have a filename / linenumber, though.
            if ($this->exception instanceof \ErrorException) {
                foreach ($frames as $k => $frame) {
                    if (isset($frame['class']) &&
                        strpos($frame['class'], 'BooBoo') !== false
                    ) {
                        unset($frames[$k]);
                    }
                }
            }

            $this->frames = new FrameCollection($frames);

            if ($previousInspector = $this->getPreviousExceptionInspector()) {
                // Keep outer frame on top of the inner one
                $outerFrames = $this->frames;
                $newFrames = clone $previousInspector->getFrames();
                $newFrames->prependFrames($outerFrames->topDiff($newFrames));
                $this->frames = $newFrames;
            }
        }

        return $this->frames;
    }
1135695
public function chosen() : ?Connection
    {
        if ($this->helperSet->has($this->helperName)) {
            $connectionHelper = $this->helperSet->get($this->helperName);

            if ($connectionHelper instanceof ConnectionHelper) {
                return $connectionHelper->getConnection();
            }
        }

        return null;
    }
440079
public function chosen() : ?Connection
    {
        foreach ($this->loaders as $loader) {
            $confObj = $loader->chosen();

            if ($confObj !== null) {
                return $confObj;
            }
        }

        return null;
    }
99741
public function getConn()
    {
        if ($this->conn === null) {
            $this->conn = Connection::connect($this->req->getUrlParam('conn'), $this);
            if ($this->conn === false) {
                $this->res->error = Connection::getLastError();
                $this->finish();
            } else {
                if ($this->conn !== null) {
                    $this->conn->addWriteData($this->getRequestBuf());
                }
            }
        }
        return $this->conn;
    }
1037856
private function getConnection() {
        if ($this->connection === null) {
            $this->connection = DriverManager::getConnection($this->params, new Configuration());
        }

        return $this->connection;
    }