package okhttp3.n0.connection;

import g.h.a.i;
import io.netty.handler.codec.rtsp.RtspHeaders;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.net.Socket;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import kotlin.Metadata;
import kotlin.jvm.internal.o;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Dispatcher;
import okhttp3.EventListener;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.n0.platform.Platform;
import okio.AsyncTimeout;

/* JADX INFO: renamed from: y.n0.g.e, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000§\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\u0000\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u000b\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u000b\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006*\u0001.\u0018\u00002\u00020\u0001:\u0002deB\u001d\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bJ\u000e\u00101\u001a\u0002022\u0006\u0010\u0010\u001a\u00020\u000fJ!\u00103\u001a\u0002H4\"\n\b\u0000\u00104*\u0004\u0018\u0001052\u0006\u00106\u001a\u0002H4H\u0002¢\u0006\u0002\u00107J\b\u00108\u001a\u000202H\u0002J\b\u00109\u001a\u000202H\u0016J\b\u0010:\u001a\u00020\u0000H\u0016J\u0010\u0010;\u001a\u00020<2\u0006\u0010=\u001a\u00020>H\u0002J\u0010\u0010?\u001a\u0002022\u0006\u0010@\u001a\u00020AH\u0016J\u0016\u0010B\u001a\u0002022\u0006\u0010C\u001a\u00020\u00052\u0006\u0010D\u001a\u00020\u0007J\b\u0010E\u001a\u00020FH\u0016J\u0015\u0010G\u001a\u0002022\u0006\u0010H\u001a\u00020\u0007H\u0000¢\u0006\u0002\bIJ\r\u0010J\u001a\u00020FH\u0000¢\u0006\u0002\bKJ\u0015\u0010L\u001a\u00020\u001e2\u0006\u0010M\u001a\u00020NH\u0000¢\u0006\u0002\bOJ\b\u0010P\u001a\u00020\u0007H\u0016J\b\u0010Q\u001a\u00020\u0007H\u0016J;\u0010R\u001a\u0002H4\"\n\b\u0000\u00104*\u0004\u0018\u0001052\u0006\u0010\u001d\u001a\u00020\u001e2\u0006\u0010S\u001a\u00020\u00072\u0006\u0010T\u001a\u00020\u00072\u0006\u00106\u001a\u0002H4H\u0000¢\u0006\u0004\bU\u0010VJ\u0019\u0010W\u001a\u0004\u0018\u0001052\b\u00106\u001a\u0004\u0018\u000105H\u0000¢\u0006\u0002\bXJ\r\u0010Y\u001a\u00020ZH\u0000¢\u0006\u0002\b[J\u000f\u0010\\\u001a\u0004\u0018\u00010]H\u0000¢\u0006\u0002\b^J\b\u0010C\u001a\u00020\u0005H\u0016J\u0006\u0010_\u001a\u00020\u0007J\b\u0010-\u001a\u00020`H\u0016J\u0006\u00100\u001a\u000202J!\u0010a\u001a\u0002H4\"\n\b\u0000\u00104*\u0004\u0018\u0001052\u0006\u0010b\u001a\u0002H4H\u0002¢\u0006\u0002\u00107J\b\u0010c\u001a\u00020ZH\u0002R\u0010\u0010\t\u001a\u0004\u0018\u00010\nX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u000b\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\f\u0010\rR\"\u0010\u0010\u001a\u0004\u0018\u00010\u000f2\b\u0010\u000e\u001a\u0004\u0018\u00010\u000f@BX\u0086\u000e¢\u0006\b\n\u0000\u001a\u0004\b\u0011\u0010\u0012R\u000e\u0010\u0013\u001a\u00020\u0014X\u0082\u0004¢\u0006\u0002\n\u0000R\u001c\u0010\u0015\u001a\u0004\u0018\u00010\u000fX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0016\u0010\u0012\"\u0004\b\u0017\u0010\u0018R\u0014\u0010\u0019\u001a\u00020\u001aX\u0080\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u001b\u0010\u001cR\u0010\u0010\u001d\u001a\u0004\u0018\u00010\u001eX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u001f\u001a\u0004\u0018\u00010 X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010!\u001a\u00020\"X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010#\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u0011\u0010\u0006\u001a\u00020\u0007¢\u0006\b\n\u0000\u001a\u0004\b$\u0010%R\"\u0010&\u001a\u0004\u0018\u00010\u001e2\b\u0010\u000e\u001a\u0004\u0018\u00010\u001e@BX\u0080\u000e¢\u0006\b\n\u0000\u001a\u0004\b'\u0010(R\u0011\u0010\u0004\u001a\u00020\u0005¢\u0006\b\n\u0000\u001a\u0004\b)\u0010*R\u000e\u0010+\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010,\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010-\u001a\u00020.X\u0082\u0004¢\u0006\u0004\n\u0002\u0010/R\u000e\u00100\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000¨\u0006f"}, d2 = {"Lokhttp3/internal/connection/RealCall;", "Lokhttp3/Call;", "client", "Lokhttp3/OkHttpClient;", "originalRequest", "Lokhttp3/Request;", "forWebSocket", "", "(Lokhttp3/OkHttpClient;Lokhttp3/Request;Z)V", "callStackTrace", "", "canceled", "getClient", "()Lokhttp3/OkHttpClient;", "<set-?>", "Lokhttp3/internal/connection/RealConnection;", "connection", "getConnection", "()Lokhttp3/internal/connection/RealConnection;", "connectionPool", "Lokhttp3/internal/connection/RealConnectionPool;", "connectionToCancel", "getConnectionToCancel", "setConnectionToCancel", "(Lokhttp3/internal/connection/RealConnection;)V", "eventListener", "Lokhttp3/EventListener;", "getEventListener$okhttp", "()Lokhttp3/EventListener;", "exchange", "Lokhttp3/internal/connection/Exchange;", "exchangeFinder", "Lokhttp3/internal/connection/ExchangeFinder;", "executed", "Ljava/util/concurrent/atomic/AtomicBoolean;", "expectMoreExchanges", "getForWebSocket", "()Z", "interceptorScopedExchange", "getInterceptorScopedExchange$okhttp", "()Lokhttp3/internal/connection/Exchange;", "getOriginalRequest", "()Lokhttp3/Request;", "requestBodyOpen", "responseBodyOpen", RtspHeaders.Values.TIMEOUT, "okhttp3/internal/connection/RealCall$timeout$1", "Lokhttp3/internal/connection/RealCall$timeout$1;", "timeoutEarlyExit", "acquireConnectionNoEvents", "", "callDone", "E", "Ljava/io/IOException;", "e", "(Ljava/io/IOException;)Ljava/io/IOException;", "callStart", "cancel", "clone", "createAddress", "Lokhttp3/Address;", RtspHeaders.Values.URL, "Lokhttp3/HttpUrl;", "enqueue", "responseCallback", "Lokhttp3/Callback;", "enterNetworkInterceptorExchange", "request", "newExchangeFinder", "execute", "Lokhttp3/Response;", "exitNetworkInterceptorExchange", "closeExchange", "exitNetworkInterceptorExchange$okhttp", "getResponseWithInterceptorChain", "getResponseWithInterceptorChain$okhttp", "initExchange", "chain", "Lokhttp3/internal/http/RealInterceptorChain;", "initExchange$okhttp", "isCanceled", "isExecuted", "messageDone", "requestDone", "responseDone", "messageDone$okhttp", "(Lokhttp3/internal/connection/Exchange;ZZLjava/io/IOException;)Ljava/io/IOException;", "noMoreExchanges", "noMoreExchanges$okhttp", "redactedUrl", "", "redactedUrl$okhttp", "releaseConnectionNoEvents", "Ljava/net/Socket;", "releaseConnectionNoEvents$okhttp", "retryAfterFailure", "Lokio/AsyncTimeout;", "timeoutExit", "cause", "toLoggableString", "AsyncCall", "CallReference", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class RealCall implements Call {
    public volatile boolean A;
    public volatile Exchange B;
    public volatile RealConnection C;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final OkHttpClient f9769f;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final Request f9770m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final boolean f9771n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final RealConnectionPool f9772o;

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

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final c f9774q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final AtomicBoolean f9775r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public Object f9776s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public ExchangeFinder f9777t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public RealConnection f9778u;

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

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public Exchange f9780w;

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

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

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

    /* JADX INFO: renamed from: y.n0.g.e$a */
    @Metadata(d1 = {"\u0000@\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0080\u0004\u0018\u00002\u00020\u0001B\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u000e\u0010\u0016\u001a\u00020\u00172\u0006\u0010\u0018\u001a\u00020\u0019J\u0012\u0010\u001a\u001a\u00020\u00172\n\u0010\u001b\u001a\u00060\u0000R\u00020\u0006J\b\u0010\u001c\u001a\u00020\u0017H\u0016R\u0011\u0010\u0005\u001a\u00020\u00068F¢\u0006\u0006\u001a\u0004\b\u0007\u0010\bR\u001e\u0010\u000b\u001a\u00020\n2\u0006\u0010\t\u001a\u00020\n@BX\u0086\u000e¢\u0006\b\n\u0000\u001a\u0004\b\f\u0010\rR\u0011\u0010\u000e\u001a\u00020\u000f8F¢\u0006\u0006\u001a\u0004\b\u0010\u0010\u0011R\u0011\u0010\u0012\u001a\u00020\u00138F¢\u0006\u0006\u001a\u0004\b\u0014\u0010\u0015R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u001d"}, d2 = {"Lokhttp3/internal/connection/RealCall$AsyncCall;", "Ljava/lang/Runnable;", "responseCallback", "Lokhttp3/Callback;", "(Lokhttp3/internal/connection/RealCall;Lokhttp3/Callback;)V", "call", "Lokhttp3/internal/connection/RealCall;", "getCall", "()Lokhttp3/internal/connection/RealCall;", "<set-?>", "Ljava/util/concurrent/atomic/AtomicInteger;", "callsPerHost", "getCallsPerHost", "()Ljava/util/concurrent/atomic/AtomicInteger;", "host", "", "getHost", "()Ljava/lang/String;", "request", "Lokhttp3/Request;", "getRequest", "()Lokhttp3/Request;", "executeOn", "", "executorService", "Ljava/util/concurrent/ExecutorService;", "reuseCallsPerHostFrom", "other", "run", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public final class a implements Runnable {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public final Callback f9784f;

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public volatile AtomicInteger f9785m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public final /* synthetic */ RealCall f9786n;

        public a(RealCall realCall, Callback callback) {
            o.f(realCall, "this$0");
            o.f(callback, "responseCallback");
            this.f9786n = realCall;
            this.f9784f = callback;
            this.f9785m = new AtomicInteger(0);
        }

        public final String a() {
            return this.f9786n.f9770m.a.f10091f;
        }

        @Override // java.lang.Runnable
        public void run() {
            OkHttpClient okHttpClient;
            String strL = o.l("OkHttp ", this.f9786n.f9770m.a.f());
            RealCall realCall = this.f9786n;
            Thread threadCurrentThread = Thread.currentThread();
            String name = threadCurrentThread.getName();
            threadCurrentThread.setName(strL);
            try {
                realCall.f9774q.h();
                boolean z2 = false;
                try {
                    try {
                        try {
                            this.f9784f.onResponse(realCall, realCall.l());
                            okHttpClient = realCall.f9769f;
                        } catch (IOException e2) {
                            e = e2;
                            z2 = true;
                            if (z2) {
                                Platform.a aVar = Platform.a;
                                Platform.f10049b.i(o.l("Callback failure for ", RealCall.b(realCall)), 4, e);
                            } else {
                                this.f9784f.onFailure(realCall, e);
                            }
                            okHttpClient = realCall.f9769f;
                        } catch (Throwable th) {
                            th = th;
                            z2 = true;
                            realCall.g();
                            if (!z2) {
                                IOException iOException = new IOException(o.l("canceled due to ", th));
                                i.p(iOException, th);
                                this.f9784f.onFailure(realCall, iOException);
                            }
                            throw th;
                        }
                    } catch (Throwable th2) {
                        realCall.f9769f.f9563o.b(this);
                        throw th2;
                    }
                } catch (IOException e3) {
                    e = e3;
                } catch (Throwable th3) {
                    th = th3;
                }
                okHttpClient.f9563o.b(this);
            } finally {
                threadCurrentThread.setName(name);
            }
        }
    }

    /* JADX INFO: renamed from: y.n0.g.e$b */
    @Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0000\n\u0002\b\u0004\b\u0000\u0018\u00002\b\u0012\u0004\u0012\u00020\u00020\u0001B\u0017\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\b\u0010\u0004\u001a\u0004\u0018\u00010\u0005¢\u0006\u0002\u0010\u0006R\u0013\u0010\u0004\u001a\u0004\u0018\u00010\u0005¢\u0006\b\n\u0000\u001a\u0004\b\u0007\u0010\b¨\u0006\t"}, d2 = {"Lokhttp3/internal/connection/RealCall$CallReference;", "Ljava/lang/ref/WeakReference;", "Lokhttp3/internal/connection/RealCall;", "referent", "callStackTrace", "", "(Lokhttp3/internal/connection/RealCall;Ljava/lang/Object;)V", "getCallStackTrace", "()Ljava/lang/Object;", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public static final class b extends WeakReference<RealCall> {
        public final Object a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public b(RealCall realCall, Object obj) {
            super(realCall);
            o.f(realCall, "referent");
            this.a = obj;
        }
    }

    /* JADX INFO: renamed from: y.n0.g.e$c */
    @Metadata(d1 = {"\u0000\u0011\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000*\u0001\u0000\b\n\u0018\u00002\u00020\u0001J\b\u0010\u0002\u001a\u00020\u0003H\u0014¨\u0006\u0004"}, d2 = {"okhttp3/internal/connection/RealCall$timeout$1", "Lokio/AsyncTimeout;", "timedOut", "", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public static final class c extends AsyncTimeout {
        public c() {
        }

        @Override // okio.AsyncTimeout
        public void k() {
            RealCall.this.g();
        }
    }

    public RealCall(OkHttpClient okHttpClient, Request request, boolean z2) {
        o.f(okHttpClient, "client");
        o.f(request, "originalRequest");
        this.f9769f = okHttpClient;
        this.f9770m = request;
        this.f9771n = z2;
        this.f9772o = okHttpClient.f9564p.a;
        EventListener eventListener = ((okhttp3.n0.b) okHttpClient.f9567s).a;
        o.f(eventListener, "$this_asFactory");
        o.f(this, "it");
        this.f9773p = eventListener;
        c cVar = new c();
        Objects.requireNonNull(okHttpClient);
        cVar.g(0, TimeUnit.MILLISECONDS);
        this.f9774q = cVar;
        this.f9775r = new AtomicBoolean();
        this.f9783z = true;
    }

    public static final String b(RealCall realCall) {
        StringBuilder sb = new StringBuilder();
        sb.append(realCall.A ? "canceled " : "");
        sb.append(realCall.f9771n ? "web socket" : "call");
        sb.append(" to ");
        sb.append(realCall.f9770m.a.f());
        return sb.toString();
    }

    public final void c(RealConnection realConnection) {
        o.f(realConnection, "connection");
        byte[] bArr = okhttp3.n0.c.a;
        if (!(this.f9778u == null)) {
            throw new IllegalStateException("Check failed.".toString());
        }
        this.f9778u = realConnection;
        realConnection.f9802p.add(new b(this, this.f9776s));
    }

    public Object clone() {
        return new RealCall(this.f9769f, this.f9770m, this.f9771n);
    }

    public final <E extends IOException> E d(E e2) {
        E interruptedIOException;
        Socket socketO;
        byte[] bArr = okhttp3.n0.c.a;
        RealConnection realConnection = this.f9778u;
        if (realConnection != null) {
            synchronized (realConnection) {
                socketO = o();
            }
            if (this.f9778u == null) {
                if (socketO != null) {
                    okhttp3.n0.c.f(socketO);
                }
                Objects.requireNonNull(this.f9773p);
                o.f(this, "call");
                o.f(realConnection, "connection");
            } else {
                if (!(socketO == null)) {
                    throw new IllegalStateException("Check failed.".toString());
                }
            }
        }
        if (!this.f9779v && this.f9774q.i()) {
            interruptedIOException = new InterruptedIOException(RtspHeaders.Values.TIMEOUT);
            if (e2 != null) {
                interruptedIOException.initCause(e2);
            }
        } else {
            interruptedIOException = e2;
        }
        if (e2 != null) {
            EventListener eventListener = this.f9773p;
            o.c(interruptedIOException);
            Objects.requireNonNull(eventListener);
            o.f(this, "call");
            o.f(interruptedIOException, "ioe");
        } else {
            Objects.requireNonNull(this.f9773p);
            o.f(this, "call");
        }
        return interruptedIOException;
    }

    @Override // okhttp3.Call
    /* JADX INFO: renamed from: e, reason: from getter */
    public Request getF9770m() {
        return this.f9770m;
    }

    public final void f() {
        Platform.a aVar = Platform.a;
        this.f9776s = Platform.f10049b.g("response.body().close()");
        Objects.requireNonNull(this.f9773p);
        o.f(this, "call");
    }

    public void g() {
        Socket socket;
        if (this.A) {
            return;
        }
        this.A = true;
        Exchange exchange = this.B;
        if (exchange != null) {
            exchange.f9745d.cancel();
        }
        RealConnection realConnection = this.C;
        if (realConnection != null && (socket = realConnection.f9789c) != null) {
            okhttp3.n0.c.f(socket);
        }
        Objects.requireNonNull(this.f9773p);
        o.f(this, "call");
    }

    public void i(Callback callback) {
        a next;
        o.f(callback, "responseCallback");
        if (!this.f9775r.compareAndSet(false, true)) {
            throw new IllegalStateException("Already Executed".toString());
        }
        f();
        Dispatcher dispatcher = this.f9769f.f9563o;
        a aVar = new a(this, callback);
        Objects.requireNonNull(dispatcher);
        o.f(aVar, "call");
        synchronized (dispatcher) {
            dispatcher.f10077b.add(aVar);
            if (!aVar.f9786n.f9771n) {
                String strA = aVar.a();
                Iterator<a> it = dispatcher.f10078c.iterator();
                while (true) {
                    if (!it.hasNext()) {
                        Iterator<a> it2 = dispatcher.f10077b.iterator();
                        while (true) {
                            if (!it2.hasNext()) {
                                next = null;
                                break;
                            } else {
                                next = it2.next();
                                if (o.a(next.a(), strA)) {
                                    break;
                                }
                            }
                        }
                    } else {
                        next = it.next();
                        if (o.a(next.a(), strA)) {
                            break;
                        }
                    }
                }
                if (next != null) {
                    o.f(next, "other");
                    aVar.f9785m = next.f9785m;
                }
            }
        }
        dispatcher.c();
    }

    public Response j() {
        if (!this.f9775r.compareAndSet(false, true)) {
            throw new IllegalStateException("Already Executed".toString());
        }
        this.f9774q.h();
        f();
        try {
            Dispatcher dispatcher = this.f9769f.f9563o;
            synchronized (dispatcher) {
                o.f(this, "call");
                dispatcher.f10079d.add(this);
            }
            return l();
        } finally {
            Dispatcher dispatcher2 = this.f9769f.f9563o;
            Objects.requireNonNull(dispatcher2);
            o.f(this, "call");
            dispatcher2.a(dispatcher2.f10079d, this);
        }
    }

    public final void k(boolean z2) {
        Exchange exchange;
        synchronized (this) {
            if (!this.f9783z) {
                throw new IllegalStateException("released".toString());
            }
        }
        if (z2 && (exchange = this.B) != null) {
            exchange.f9745d.cancel();
            exchange.a.m(exchange, true, true, null);
        }
        this.f9780w = null;
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x0090  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final okhttp3.Response l() throws java.lang.Throwable {
        /*
            r11 = this;
            java.util.ArrayList r2 = new java.util.ArrayList
            r2.<init>()
            y.c0 r0 = r11.f9769f
            java.util.List<y.z> r0 = r0.f9565q
            kotlin.collections.j.b(r2, r0)
            y.n0.h.i r0 = new y.n0.h.i
            y.c0 r1 = r11.f9769f
            r0.<init>(r1)
            r2.add(r0)
            y.n0.h.a r0 = new y.n0.h.a
            y.c0 r1 = r11.f9769f
            y.q r1 = r1.f9572x
            r0.<init>(r1)
            r2.add(r0)
            y.n0.e.a r0 = new y.n0.e.a
            y.c0 r1 = r11.f9769f
            java.util.Objects.requireNonNull(r1)
            r0.<init>()
            r2.add(r0)
            y.n0.g.a r0 = okhttp3.n0.connection.ConnectInterceptor.a
            r2.add(r0)
            boolean r0 = r11.f9771n
            if (r0 != 0) goto L3f
            y.c0 r0 = r11.f9769f
            java.util.List<y.z> r0 = r0.f9566r
            kotlin.collections.j.b(r2, r0)
        L3f:
            y.n0.h.b r0 = new y.n0.h.b
            boolean r1 = r11.f9771n
            r0.<init>(r1)
            r2.add(r0)
            y.n0.h.g r9 = new y.n0.h.g
            r3 = 0
            r4 = 0
            y.e0 r5 = r11.f9770m
            y.c0 r0 = r11.f9769f
            int r6 = r0.J
            int r7 = r0.K
            int r8 = r0.L
            r0 = r9
            r1 = r11
            r0.<init>(r1, r2, r3, r4, r5, r6, r7, r8)
            r0 = 0
            r1 = 0
            y.e0 r2 = r11.f9770m     // Catch: java.lang.Throwable -> L77 java.io.IOException -> L79
            y.i0 r2 = r9.a(r2)     // Catch: java.lang.Throwable -> L77 java.io.IOException -> L79
            boolean r3 = r11.A     // Catch: java.lang.Throwable -> L77 java.io.IOException -> L79
            if (r3 != 0) goto L6c
            r11.n(r1)
            return r2
        L6c:
            okhttp3.n0.c.e(r2)     // Catch: java.lang.Throwable -> L77 java.io.IOException -> L79
            java.io.IOException r2 = new java.io.IOException     // Catch: java.lang.Throwable -> L77 java.io.IOException -> L79
            java.lang.String r3 = "Canceled"
            r2.<init>(r3)     // Catch: java.lang.Throwable -> L77 java.io.IOException -> L79
            throw r2     // Catch: java.lang.Throwable -> L77 java.io.IOException -> L79
        L77:
            r2 = move-exception
            goto L8e
        L79:
            r0 = move-exception
            r2 = 1
            java.io.IOException r0 = r11.n(r0)     // Catch: java.lang.Throwable -> L8a
            if (r0 != 0) goto L89
            java.lang.NullPointerException r0 = new java.lang.NullPointerException     // Catch: java.lang.Throwable -> L8a
            java.lang.String r3 = "null cannot be cast to non-null type kotlin.Throwable"
            r0.<init>(r3)     // Catch: java.lang.Throwable -> L8a
            throw r0     // Catch: java.lang.Throwable -> L8a
        L89:
            throw r0     // Catch: java.lang.Throwable -> L8a
        L8a:
            r0 = move-exception
            r10 = r2
            r2 = r0
            r0 = r10
        L8e:
            if (r0 != 0) goto L93
            r11.n(r1)
        L93:
            throw r2
        */
        throw new UnsupportedOperationException("Method not decompiled: okhttp3.n0.connection.RealCall.l():y.i0");
    }

    public final <E extends IOException> E m(Exchange exchange, boolean z2, boolean z3, E e2) {
        boolean z4;
        boolean z5;
        o.f(exchange, "exchange");
        if (!o.a(exchange, this.B)) {
            return e2;
        }
        synchronized (this) {
            z4 = false;
            if (z2) {
                try {
                    if (!this.f9781x) {
                        if (z3 || !this.f9782y) {
                            z5 = false;
                        }
                    }
                    if (z2) {
                        this.f9781x = false;
                    }
                    if (z3) {
                        this.f9782y = false;
                    }
                    boolean z6 = this.f9781x;
                    boolean z7 = (z6 || this.f9782y) ? false : true;
                    if (!z6 && !this.f9782y) {
                        if (!this.f9783z) {
                            z4 = true;
                        }
                    }
                    z5 = z4;
                    z4 = z7;
                } catch (Throwable th) {
                    throw th;
                }
            } else {
                if (z3) {
                }
                z5 = false;
            }
        }
        if (z4) {
            this.B = null;
            RealConnection realConnection = this.f9778u;
            if (realConnection != null) {
                synchronized (realConnection) {
                    realConnection.f9799m++;
                }
            }
        }
        return z5 ? (E) d(e2) : e2;
    }

    public final IOException n(IOException iOException) {
        boolean z2;
        synchronized (this) {
            z2 = false;
            if (this.f9783z) {
                this.f9783z = false;
                if (!this.f9781x) {
                    if (!this.f9782y) {
                        z2 = true;
                    }
                }
            }
        }
        return z2 ? d(iOException) : iOException;
    }

    public final Socket o() {
        RealConnection realConnection = this.f9778u;
        o.c(realConnection);
        byte[] bArr = okhttp3.n0.c.a;
        List<Reference<RealCall>> list = realConnection.f9802p;
        Iterator<Reference<RealCall>> it = list.iterator();
        boolean z2 = false;
        int i2 = 0;
        while (true) {
            if (!it.hasNext()) {
                i2 = -1;
                break;
            }
            if (o.a(it.next().get(), this)) {
                break;
            }
            i2++;
        }
        if (!(i2 != -1)) {
            throw new IllegalStateException("Check failed.".toString());
        }
        list.remove(i2);
        this.f9778u = null;
        if (list.isEmpty()) {
            realConnection.f9803q = System.nanoTime();
            RealConnectionPool realConnectionPool = this.f9772o;
            Objects.requireNonNull(realConnectionPool);
            o.f(realConnection, "connection");
            byte[] bArr2 = okhttp3.n0.c.a;
            if (realConnection.f9796j || realConnectionPool.a == 0) {
                realConnection.f9796j = true;
                realConnectionPool.f9811e.remove(realConnection);
                if (realConnectionPool.f9811e.isEmpty()) {
                    realConnectionPool.f9809c.a();
                }
                z2 = true;
            } else {
                realConnectionPool.f9809c.c(realConnectionPool.f9810d, 0L);
            }
            if (z2) {
                Socket socket = realConnection.f9790d;
                o.c(socket);
                return socket;
            }
        }
        return null;
    }
}
