Search in sources :

Example 6 with Route

use of com.squareup.okhttp.Route in project cordova-android-chromeview by thedracle.

the class RouteSelector method next.

/**
   * Returns the next route address to attempt.
   *
   * @throws NoSuchElementException if there are no more routes to attempt.
   */
public Connection next() throws IOException {
    // Always prefer pooled connections over new connections.
    Connection pooled = pool.get(address);
    if (pooled != null) {
        return pooled;
    }
    // Compute the next route to attempt.
    if (!hasNextTlsMode()) {
        if (!hasNextInetSocketAddress()) {
            if (!hasNextProxy()) {
                if (!hasNextPostponed()) {
                    throw new NoSuchElementException();
                }
                return new Connection(nextPostponed());
            }
            lastProxy = nextProxy();
            resetNextInetSocketAddress(lastProxy);
        }
        lastInetSocketAddress = nextInetSocketAddress();
        resetNextTlsMode();
    }
    boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
    Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
    if (failedRoutes.contains(route)) {
        postponedRoutes.add(route);
        // tried last.
        return next();
    }
    return new Connection(route);
}
Also used : Connection(com.squareup.okhttp.Connection) NoSuchElementException(java.util.NoSuchElementException) Route(com.squareup.okhttp.Route)

Aggregations

Route (com.squareup.okhttp.Route)6 Connection (com.squareup.okhttp.Connection)3 NoSuchElementException (java.util.NoSuchElementException)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2