package okhttp3.internal.connection;

import S4.q;
import androidx.navigation.C1134i;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.ProtocolException;
import java.net.Proxy;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownServiceException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import kotlin.jvm.internal.o;
import n2.AbstractC2613d;
import okhttp3.Address;
import okhttp3.Call;
import okhttp3.CertificatePinner;
import okhttp3.Connection;
import okhttp3.ConnectionSpec;
import okhttp3.EventListener;
import okhttp3.EventListener$Companion$NONE$1;
import okhttp3.Handshake;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;
import okhttp3.internal.Util;
import okhttp3.internal.concurrent.Task;
import okhttp3.internal.concurrent.TaskQueue;
import okhttp3.internal.concurrent.TaskRunner;
import okhttp3.internal.http.ExchangeCodec;
import okhttp3.internal.http.RealInterceptorChain;
import okhttp3.internal.http1.Http1ExchangeCodec;
import okhttp3.internal.http2.ErrorCode;
import okhttp3.internal.http2.Http2;
import okhttp3.internal.http2.Http2Connection;
import okhttp3.internal.http2.Http2ExchangeCodec;
import okhttp3.internal.http2.Http2Stream;
import okhttp3.internal.http2.Http2Writer;
import okhttp3.internal.http2.Settings;
import okhttp3.internal.platform.Platform;
import okhttp3.internal.tls.OkHostnameVerifier;
import p5.AbstractC2732b;
import p5.C2743m;
import p5.I;
import p5.J;
import x4.AbstractC3251q;

/* JADX INFO: loaded from: classes3.dex */
public final class RealConnection extends Http2Connection.Listener implements Connection {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Route f22337b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Socket f22338c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Socket f22339d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public Handshake f22340e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Protocol f22341f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public Http2Connection f22342g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public J f22343h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public I f22344i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f22345j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public boolean f22346k;
    public int l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int f22347m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public int f22348n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f22349o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final ArrayList f22350p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public long f22351q;

    public static final class Companion {
        public /* synthetic */ Companion(int i6) {
            this();
        }

        private Companion() {
        }
    }

    public /* synthetic */ class WhenMappings {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f22352a;

        static {
            int[] iArr = new int[Proxy.Type.values().length];
            try {
                iArr[Proxy.Type.DIRECT.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[Proxy.Type.HTTP.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            f22352a = iArr;
        }
    }

    static {
        new Companion(0);
    }

    public RealConnection(RealConnectionPool connectionPool, Route route) {
        o.h(connectionPool, "connectionPool");
        o.h(route, "route");
        this.f22337b = route;
        this.f22349o = 1;
        this.f22350p = new ArrayList();
        this.f22351q = Long.MAX_VALUE;
    }

    public static void d(OkHttpClient client, Route failedRoute, IOException failure) {
        o.h(client, "client");
        o.h(failedRoute, "failedRoute");
        o.h(failure, "failure");
        if (failedRoute.f22169b.type() != Proxy.Type.DIRECT) {
            Address address = failedRoute.f22168a;
            address.f21895g.connectFailed(address.f21896h.g(), failedRoute.f22169b.address(), failure);
        }
        RouteDatabase routeDatabase = client.f22071D;
        synchronized (routeDatabase) {
            routeDatabase.f22363a.add(failedRoute);
        }
    }

    @Override // okhttp3.internal.http2.Http2Connection.Listener
    public final synchronized void a(Http2Connection connection, Settings settings) {
        o.h(connection, "connection");
        o.h(settings, "settings");
        this.f22349o = (settings.f22592a & 16) != 0 ? settings.f22593b[4] : Integer.MAX_VALUE;
    }

    @Override // okhttp3.internal.http2.Http2Connection.Listener
    public final void b(Http2Stream http2Stream) {
        http2Stream.c(ErrorCode.REFUSED_STREAM, null);
    }

    public final void c(int i6, int i7, int i8, boolean z6, Call call, EventListener eventListener) throws Throwable {
        o.h(call, "call");
        o.h(eventListener, "eventListener");
        if (this.f22341f != null) {
            throw new IllegalStateException("already connected");
        }
        Route route = this.f22337b;
        Address address = route.f22168a;
        InetSocketAddress inetSocketAddress = route.f22170c;
        List list = address.f21898j;
        ConnectionSpecSelector connectionSpecSelector = new ConnectionSpecSelector(list);
        Address address2 = route.f22168a;
        if (address2.f21891c != null) {
            if (address2.f21897i.contains(Protocol.H2_PRIOR_KNOWLEDGE)) {
                throw new RouteException(new UnknownServiceException("H2_PRIOR_KNOWLEDGE cannot be used with HTTPS"));
            }
        } else {
            if (!list.contains(ConnectionSpec.f21977f)) {
                throw new RouteException(new UnknownServiceException("CLEARTEXT communication not enabled for client"));
            }
            String str = address2.f21896h.f22027d;
            if (!Platform.Companion.get().isCleartextTrafficPermitted(str)) {
                throw new RouteException(new UnknownServiceException(Z0.o.o("CLEARTEXT communication to ", str, " not permitted by network security policy")));
            }
        }
        RouteException routeException = null;
        do {
            try {
                SSLSocketFactory sSLSocketFactory = address2.f21891c;
                Proxy proxy = route.f22169b;
                if (sSLSocketFactory != null && proxy.type() == Proxy.Type.HTTP) {
                    f(i6, i7, i8, call, eventListener);
                    if (this.f22338c == null) {
                        if (address2.f21891c == null && proxy.type() == Proxy.Type.HTTP && this.f22338c == null) {
                            throw new RouteException(new ProtocolException("Too many tunnel connections attempted: 21"));
                        }
                        this.f22351q = System.nanoTime();
                        return;
                    }
                } else {
                    try {
                        e(i6, i7, call, eventListener);
                    } catch (IOException e6) {
                        e = e6;
                        Socket socket = this.f22339d;
                        if (socket != null) {
                            Util.d(socket);
                        }
                        Socket socket2 = this.f22338c;
                        if (socket2 != null) {
                            Util.d(socket2);
                        }
                        this.f22339d = null;
                        this.f22338c = null;
                        this.f22343h = null;
                        this.f22344i = null;
                        this.f22340e = null;
                        this.f22341f = null;
                        this.f22342g = null;
                        this.f22349o = 1;
                        o.h(inetSocketAddress, "inetSocketAddress");
                        if (routeException == null) {
                            routeException = new RouteException(e);
                        } else {
                            AbstractC2613d.b(routeException.f22364a, e);
                            routeException.f22365b = e;
                        }
                        if (!z6) {
                            throw routeException;
                        }
                        connectionSpecSelector.f22289d = true;
                        if (!connectionSpecSelector.f22288c) {
                            throw routeException;
                        }
                        if (e instanceof ProtocolException) {
                            throw routeException;
                        }
                        if (e instanceof InterruptedIOException) {
                            throw routeException;
                        }
                        if ((e instanceof SSLHandshakeException) && (e.getCause() instanceof CertificateException)) {
                            throw routeException;
                        }
                        if (e instanceof SSLPeerUnverifiedException) {
                            throw routeException;
                        }
                    }
                }
                g(connectionSpecSelector, call, eventListener);
                EventListener$Companion$NONE$1 eventListener$Companion$NONE$1 = EventListener.f22010a;
                o.h(inetSocketAddress, "inetSocketAddress");
                if (address2.f21891c == null) {
                }
                this.f22351q = System.nanoTime();
                return;
            } catch (IOException e7) {
                e = e7;
            }
        } while (e instanceof SSLException);
        throw routeException;
    }

    public final void e(int i6, int i7, Call call, EventListener eventListener) throws IOException {
        Socket socketCreateSocket;
        Route route = this.f22337b;
        Proxy proxy = route.f22169b;
        Address address = route.f22168a;
        Proxy.Type type = proxy.type();
        int i8 = type == null ? -1 : WhenMappings.f22352a[type.ordinal()];
        if (i8 == 1 || i8 == 2) {
            socketCreateSocket = address.f21890b.createSocket();
            o.e(socketCreateSocket);
        } else {
            socketCreateSocket = new Socket(proxy);
        }
        this.f22338c = socketCreateSocket;
        eventListener.getClass();
        o.h(call, "call");
        InetSocketAddress inetSocketAddress = route.f22170c;
        o.h(inetSocketAddress, "inetSocketAddress");
        socketCreateSocket.setSoTimeout(i7);
        try {
            Platform.Companion.get().connectSocket(socketCreateSocket, inetSocketAddress, i6);
            try {
                this.f22343h = AbstractC2732b.c(AbstractC2732b.l(socketCreateSocket));
                this.f22344i = AbstractC2732b.b(AbstractC2732b.i(socketCreateSocket));
            } catch (NullPointerException e6) {
                if (o.c(e6.getMessage(), "throw with null exception")) {
                    throw new IOException(e6);
                }
            }
        } catch (ConnectException e7) {
            ConnectException connectException = new ConnectException("Failed to connect to " + inetSocketAddress);
            connectException.initCause(e7);
            throw connectException;
        }
    }

    public final void f(int i6, int i7, int i8, Call call, EventListener eventListener) throws IOException {
        Request.Builder builder = new Request.Builder();
        Route route = this.f22337b;
        HttpUrl url = route.f22168a.f21896h;
        o.h(url, "url");
        builder.f22131a = url;
        builder.g("CONNECT", null);
        Address address = route.f22168a;
        builder.e("Host", Util.x(address.f21896h, true));
        builder.e("Proxy-Connection", "Keep-Alive");
        builder.e("User-Agent", "okhttp/4.12.0");
        Request requestB = builder.b();
        Response.Builder builder2 = new Response.Builder();
        builder2.f22153a = requestB;
        builder2.f22154b = Protocol.HTTP_1_1;
        builder2.f22155c = 407;
        builder2.f22156d = "Preemptive Authenticate";
        builder2.f22159g = Util.f22181c;
        builder2.f22163k = -1L;
        builder2.l = -1L;
        builder2.f22158f.h("Proxy-Authenticate", "OkHttp-Preemptive");
        Request requestA = address.f21894f.a(route, builder2.a());
        if (requestA != null) {
            requestB = requestA;
        }
        e(i6, i7, call, eventListener);
        String str = "CONNECT " + Util.x(requestB.f22125a, true) + " HTTP/1.1";
        while (true) {
            J j4 = this.f22343h;
            o.e(j4);
            I i9 = this.f22344i;
            o.e(i9);
            Http1ExchangeCodec http1ExchangeCodec = new Http1ExchangeCodec(null, this, j4, i9);
            TimeUnit timeUnit = TimeUnit.MILLISECONDS;
            j4.f23058a.timeout().g(i7, timeUnit);
            i9.f23055a.timeout().g(i8, timeUnit);
            http1ExchangeCodec.k(requestB.f22127c, str);
            http1ExchangeCodec.a();
            Response.Builder builderD = http1ExchangeCodec.d(false);
            o.e(builderD);
            builderD.f22153a = requestB;
            Response responseA = builderD.a();
            http1ExchangeCodec.j(responseA);
            int i10 = responseA.f22143d;
            if (i10 == 200) {
                if (!j4.f23059b.d() || !i9.f23056b.d()) {
                    throw new IOException("TLS tunnel buffered too many bytes!");
                }
                return;
            } else {
                if (i10 != 407) {
                    throw new IOException(Z0.o.l("Unexpected response code for CONNECT: ", i10));
                }
                Request requestA2 = address.f21894f.a(route, responseA);
                if (requestA2 == null) {
                    throw new IOException("Failed to authenticate with proxy");
                }
                if ("close".equalsIgnoreCase(Response.b("Connection", responseA))) {
                    return;
                } else {
                    requestB = requestA2;
                }
            }
        }
    }

    public final void g(ConnectionSpecSelector connectionSpecSelector, Call call, EventListener eventListener) throws Throwable {
        Protocol protocolA;
        Route route = this.f22337b;
        Address address = route.f22168a;
        if (address.f21891c == null) {
            Protocol protocol = Protocol.H2_PRIOR_KNOWLEDGE;
            if (!address.f21897i.contains(protocol)) {
                this.f22339d = this.f22338c;
                this.f22341f = Protocol.HTTP_1_1;
                return;
            } else {
                this.f22339d = this.f22338c;
                this.f22341f = protocol;
                l();
                return;
            }
        }
        eventListener.getClass();
        o.h(call, "call");
        Address address2 = route.f22168a;
        SSLSocketFactory sSLSocketFactory = address2.f21891c;
        HttpUrl httpUrl = address2.f21896h;
        SSLSocket sSLSocket = null;
        try {
            o.e(sSLSocketFactory);
            Socket socketCreateSocket = sSLSocketFactory.createSocket(this.f22338c, httpUrl.f22027d, httpUrl.f22028e, true);
            o.f(socketCreateSocket, "null cannot be cast to non-null type javax.net.ssl.SSLSocket");
            SSLSocket sSLSocket2 = (SSLSocket) socketCreateSocket;
            try {
                ConnectionSpec connectionSpecA = connectionSpecSelector.a(sSLSocket2);
                String str = httpUrl.f22027d;
                boolean z6 = connectionSpecA.f21979b;
                if (z6) {
                    Platform.Companion.get().configureTlsExtensions(sSLSocket2, str, address2.f21897i);
                }
                sSLSocket2.startHandshake();
                SSLSession sslSocketSession = sSLSocket2.getSession();
                Handshake.Companion companion = Handshake.f22012e;
                o.g(sslSocketSession, "sslSocketSession");
                companion.getClass();
                Handshake handshakeA = Handshake.Companion.a(sslSocketSession);
                HostnameVerifier hostnameVerifier = address2.f21892d;
                o.e(hostnameVerifier);
                if (hostnameVerifier.verify(str, sslSocketSession)) {
                    CertificatePinner certificatePinner = address2.f21893e;
                    o.e(certificatePinner);
                    this.f22340e = new Handshake(handshakeA.f22013a, handshakeA.f22014b, handshakeA.f22015c, new RealConnection$connectTls$1(certificatePinner, handshakeA, address2));
                    certificatePinner.b(str, new RealConnection$connectTls$2(this));
                    String selectedProtocol = z6 ? Platform.Companion.get().getSelectedProtocol(sSLSocket2) : null;
                    this.f22339d = sSLSocket2;
                    this.f22343h = AbstractC2732b.c(AbstractC2732b.l(sSLSocket2));
                    this.f22344i = AbstractC2732b.b(AbstractC2732b.i(sSLSocket2));
                    if (selectedProtocol != null) {
                        Protocol.f22117b.getClass();
                        protocolA = Protocol.Companion.a(selectedProtocol);
                    } else {
                        protocolA = Protocol.HTTP_1_1;
                    }
                    this.f22341f = protocolA;
                    Platform.Companion.get().afterHandshake(sSLSocket2);
                    if (this.f22341f == Protocol.HTTP_2) {
                        l();
                        return;
                    }
                    return;
                }
                List listA = handshakeA.a();
                if (listA.isEmpty()) {
                    throw new SSLPeerUnverifiedException("Hostname " + str + " not verified (no certificates)");
                }
                Object obj = listA.get(0);
                o.f(obj, "null cannot be cast to non-null type java.security.cert.X509Certificate");
                X509Certificate x509Certificate = (X509Certificate) obj;
                StringBuilder sb = new StringBuilder("\n              |Hostname ");
                sb.append(str);
                sb.append(" not verified:\n              |    certificate: ");
                CertificatePinner.f21946c.getClass();
                StringBuilder sb2 = new StringBuilder("sha256/");
                C2743m c2743m = C2743m.f23101d;
                byte[] encoded = x509Certificate.getPublicKey().getEncoded();
                o.g(encoded, "publicKey.encoded");
                sb2.append(C1134i.s(encoded).c("SHA-256").a());
                sb.append(sb2.toString());
                sb.append("\n              |    DN: ");
                sb.append(x509Certificate.getSubjectDN().getName());
                sb.append("\n              |    subjectAltNames: ");
                OkHostnameVerifier.f22608a.getClass();
                sb.append(AbstractC3251q.s0(OkHostnameVerifier.a(x509Certificate, 2), OkHostnameVerifier.a(x509Certificate, 7)));
                sb.append("\n              ");
                throw new SSLPeerUnverifiedException(q.q0(sb.toString()));
            } catch (Throwable th) {
                th = th;
                sSLSocket = sSLSocket2;
                if (sSLSocket != null) {
                    Platform.Companion.get().afterHandshake(sSLSocket);
                }
                if (sSLSocket != null) {
                    Util.d(sSLSocket);
                }
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:50:0x00b0 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean h(Address address, ArrayList arrayList) {
        Handshake handshake;
        byte[] bArr = Util.f22179a;
        if (this.f22350p.size() < this.f22349o && !this.f22345j) {
            Route route = this.f22337b;
            if (route.f22168a.a(address)) {
                HttpUrl httpUrl = address.f21896h;
                String str = httpUrl.f22027d;
                Address address2 = route.f22168a;
                if (o.c(str, address2.f21896h.f22027d)) {
                    return true;
                }
                if (this.f22342g != null && arrayList != null && !arrayList.isEmpty()) {
                    Iterator it = arrayList.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            break;
                        }
                        Route route2 = (Route) it.next();
                        Proxy.Type type = route2.f22169b.type();
                        Proxy.Type type2 = Proxy.Type.DIRECT;
                        if (type == type2 && route.f22169b.type() == type2) {
                            if (o.c(route.f22170c, route2.f22170c)) {
                                OkHostnameVerifier okHostnameVerifier = OkHostnameVerifier.f22608a;
                                if (address.f21892d == okHostnameVerifier) {
                                    byte[] bArr2 = Util.f22179a;
                                    HttpUrl httpUrl2 = address2.f21896h;
                                    if (httpUrl.f22028e == httpUrl2.f22028e) {
                                        String str2 = httpUrl2.f22027d;
                                        String str3 = httpUrl.f22027d;
                                        if (!o.c(str3, str2)) {
                                            if (!this.f22346k && (handshake = this.f22340e) != null) {
                                                List listA = handshake.a();
                                                if (!listA.isEmpty()) {
                                                    Object obj = listA.get(0);
                                                    o.f(obj, "null cannot be cast to non-null type java.security.cert.X509Certificate");
                                                    okHostnameVerifier.getClass();
                                                    if (OkHostnameVerifier.c(str3, (X509Certificate) obj)) {
                                                        try {
                                                            CertificatePinner certificatePinner = address.f21893e;
                                                            o.e(certificatePinner);
                                                            Handshake handshake2 = this.f22340e;
                                                            o.e(handshake2);
                                                            certificatePinner.a(str3, handshake2.a());
                                                            return true;
                                                        } catch (SSLPeerUnverifiedException unused) {
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return false;
    }

    public final boolean i(boolean z6) {
        long j4;
        byte[] bArr = Util.f22179a;
        long jNanoTime = System.nanoTime();
        Socket socket = this.f22338c;
        o.e(socket);
        Socket socket2 = this.f22339d;
        o.e(socket2);
        o.e(this.f22343h);
        if (socket.isClosed() || socket2.isClosed() || socket2.isInputShutdown() || socket2.isOutputShutdown()) {
            return false;
        }
        Http2Connection http2Connection = this.f22342g;
        if (http2Connection != null) {
            synchronized (http2Connection) {
                if (http2Connection.f22478f) {
                    return false;
                }
                if (http2Connection.f22486r < http2Connection.f22485q) {
                    if (jNanoTime >= http2Connection.f22487s) {
                        return false;
                    }
                }
                return true;
            }
        }
        synchronized (this) {
            j4 = jNanoTime - this.f22351q;
        }
        if (j4 < 10000000000L || !z6) {
            return true;
        }
        try {
            int soTimeout = socket2.getSoTimeout();
            try {
                socket2.setSoTimeout(1);
                return !r4.a();
            } finally {
                socket2.setSoTimeout(soTimeout);
            }
        } catch (SocketTimeoutException unused) {
            return true;
        } catch (IOException unused2) {
            return false;
        }
    }

    public final ExchangeCodec j(OkHttpClient client, RealInterceptorChain realInterceptorChain) throws SocketException {
        o.h(client, "client");
        Socket socket = this.f22339d;
        o.e(socket);
        J j4 = this.f22343h;
        o.e(j4);
        I i6 = this.f22344i;
        o.e(i6);
        Http2Connection http2Connection = this.f22342g;
        if (http2Connection != null) {
            return new Http2ExchangeCodec(client, this, realInterceptorChain, http2Connection);
        }
        int i7 = realInterceptorChain.f22390g;
        socket.setSoTimeout(i7);
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        j4.f23058a.timeout().g(i7, timeUnit);
        i6.f23055a.timeout().g(realInterceptorChain.f22391h, timeUnit);
        return new Http1ExchangeCodec(client, this, j4, i6);
    }

    public final synchronized void k() {
        this.f22345j = true;
    }

    public final void l() throws SocketException {
        Socket socket = this.f22339d;
        o.e(socket);
        J j4 = this.f22343h;
        o.e(j4);
        I i6 = this.f22344i;
        o.e(i6);
        socket.setSoTimeout(0);
        TaskRunner taskRunner = TaskRunner.f22274i;
        Http2Connection.Builder builder = new Http2Connection.Builder(taskRunner);
        String peerName = this.f22337b.f22168a.f21896h.f22027d;
        o.h(peerName, "peerName");
        builder.f22496b = socket;
        String str = Util.f22185g + ' ' + peerName;
        o.h(str, "<set-?>");
        builder.f22497c = str;
        builder.f22498d = j4;
        builder.f22499e = i6;
        builder.f22500f = this;
        Http2Connection http2Connection = new Http2Connection(builder);
        this.f22342g = http2Connection;
        Http2Connection.f22468D.getClass();
        Settings settings = Http2Connection.f22469E;
        this.f22349o = (settings.f22592a & 16) != 0 ? settings.f22593b[4] : Integer.MAX_VALUE;
        Http2Writer http2Writer = http2Connection.f22470A;
        synchronized (http2Writer) {
            try {
                if (http2Writer.f22581d) {
                    throw new IOException("closed");
                }
                Logger logger = Http2Writer.f22577f;
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine(Util.h(">> CONNECTION " + Http2.f22464b.e(), new Object[0]));
                }
                http2Writer.f22578a.j(Http2.f22464b);
                http2Writer.f22578a.flush();
            } finally {
            }
        }
        Http2Writer http2Writer2 = http2Connection.f22470A;
        Settings settings2 = http2Connection.f22488t;
        synchronized (http2Writer2) {
            try {
                o.h(settings2, "settings");
                if (http2Writer2.f22581d) {
                    throw new IOException("closed");
                }
                http2Writer2.c(0, Integer.bitCount(settings2.f22592a) * 6, 4, 0);
                int i7 = 0;
                while (i7 < 10) {
                    boolean z6 = true;
                    if (((1 << i7) & settings2.f22592a) == 0) {
                        z6 = false;
                    }
                    if (z6) {
                        http2Writer2.f22578a.c(i7 != 4 ? i7 != 7 ? i7 : 4 : 3);
                        http2Writer2.f22578a.b(settings2.f22593b[i7]);
                    }
                    i7++;
                }
                http2Writer2.f22578a.flush();
            } finally {
            }
        }
        if (http2Connection.f22488t.a() != 65535) {
            http2Connection.f22470A.t(0, r1 - 65535);
        }
        TaskQueue taskQueueE = taskRunner.e();
        final String str2 = http2Connection.f22475c;
        final Http2Connection.ReaderRunnable readerRunnable = http2Connection.f22471B;
        taskQueueE.c(new Task(str2) { // from class: okhttp3.internal.concurrent.TaskQueue$execute$1
            @Override // okhttp3.internal.concurrent.Task
            public final long a() throws Throwable {
                readerRunnable.invoke();
                return -1L;
            }
        }, 0L);
    }

    public final String toString() {
        Object obj;
        StringBuilder sb = new StringBuilder("Connection{");
        Route route = this.f22337b;
        sb.append(route.f22168a.f21896h.f22027d);
        sb.append(':');
        sb.append(route.f22168a.f21896h.f22028e);
        sb.append(", proxy=");
        sb.append(route.f22169b);
        sb.append(" hostAddress=");
        sb.append(route.f22170c);
        sb.append(" cipherSuite=");
        Handshake handshake = this.f22340e;
        if (handshake == null || (obj = handshake.f22014b) == null) {
            obj = "none";
        }
        sb.append(obj);
        sb.append(" protocol=");
        sb.append(this.f22341f);
        sb.append('}');
        return sb.toString();
    }
}
