public Route next() throws IOException { // Compute the next route to attempt. if (!hasNextConnectionSpec()) { if (!hasNextInetSocketAddress()) { if (!hasNextProxy()) { if (!hasNextPostponed()) { throw new NoSuchElementException(); } return nextPostponed(); } lastProxy = nextProxy(); } lastInetSocketAddress = nextInetSocketAddress(); } lastSpec = nextConnectionSpec(); final boolean shouldSendTlsFallbackIndicator = shouldSendTlsFallbackIndicator(lastSpec); Route route = new Route( address, lastProxy, lastInetSocketAddress, lastSpec, shouldSendTlsFallbackIndicator); if (routeDatabase.shouldPostpone(route)) { postponedRoutes.add(route); // We will only recurse in order to skip previously failed routes. They will be tried last. return next(); } return route; }
/** * Returns the next connection to attempt. * * @throws NoSuchElementException if there are no more routes to attempt. */ Connection nextUnconnected() throws IOException { // Always prefer pooled connections over new connections. for (Connection pooled; (pooled = pool.get(address)) != null; ) { if (request.method().equals("GET") || Internal.instance.isReadable(pooled)) return pooled; pooled.getSocket().close(); } // Compute the next route to attempt. if (!hasNextTlsVersion()) { if (!hasNextInetSocketAddress()) { if (!hasNextProxy()) { if (!hasNextPostponed()) { throw new NoSuchElementException(); } return new Connection(pool, nextPostponed()); } lastProxy = nextProxy(); resetNextInetSocketAddress(lastProxy); } lastInetSocketAddress = nextInetSocketAddress(); resetNextTlsVersion(); } String tlsVersion = nextTlsVersion(); Route route = new Route(address, lastProxy, lastInetSocketAddress, tlsVersion); if (routeDatabase.shouldPostpone(route)) { postponedRoutes.add(route); // We will only recurse in order to skip previously failed routes. They will be // tried last. return nextUnconnected(); } return new Connection(pool, route); }