package p447.p448.p452;

import java.io.Closeable;
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.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import kotlin.TypeCastException;
import okhttp3.internal.connection.RouteException;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.InterfaceC6540;
import p402.p411.p413.C6635;
import p447.AbstractC6894;
import p447.C6890;
import p447.C6921;
import p447.C6926;
import p447.C6933;
import p447.InterfaceC6868;
import p447.InterfaceC6870;
import p447.p448.C6943;
import p447.p448.p450.C6946;
import p447.p448.p453.C6980;
import p447.p448.p453.C6981;
import p447.p448.p453.C6987;
import p447.p448.p453.C6989;
import p447.p448.p453.InterfaceC6984;
import p447.p448.p457.C7069;
import p461.C7098;

/* JADX INFO: renamed from: ސ.ޣ.ބ.ނ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C6964 implements InterfaceC6868 {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final C6973 f20261;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final AbstractC6894 f20262;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final C6967 f20263;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public Object f20264;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public C6963 f20265;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public C6968 f20266;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public C6960 f20267;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public boolean f20268;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public boolean f20269;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public boolean f20270;

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public boolean f20271;

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public boolean f20272;

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public boolean f20273;

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public C6960 f20274;

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public final C6921 f20275;

    /* JADX INFO: renamed from: ޒ, reason: contains not printable characters */
    public final C6926 f20276;

    /* JADX INFO: renamed from: ޓ, reason: contains not printable characters */
    public final boolean f20277;

    /* JADX INFO: renamed from: ސ.ޣ.ބ.ނ$֏, reason: contains not printable characters */
    public final class RunnableC6965 implements Runnable {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public volatile AtomicInteger f20278;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public final InterfaceC6870 f20279;

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public final /* synthetic */ C6964 f20280;

        public RunnableC6965(C6964 c6964, InterfaceC6870 interfaceC6870) {
            if (interfaceC6870 == null) {
                C6635.m9824("responseCallback");
                throw null;
            }
            this.f20280 = c6964;
            this.f20279 = interfaceC6870;
            this.f20278 = new AtomicInteger(0);
        }

        @Override // java.lang.Runnable
        public void run() {
            C6964 c6964;
            StringBuilder sbM4889 = C2803.m4889("OkHttp ");
            sbM4889.append(this.f20280.f20276.f20128.m10087());
            String string = sbM4889.toString();
            Thread threadCurrentThread = Thread.currentThread();
            C6635.m9823((Object) threadCurrentThread, "currentThread");
            String name = threadCurrentThread.getName();
            threadCurrentThread.setName(string);
            try {
                this.f20280.f20263.m10399();
                boolean z = false;
                try {
                    try {
                        try {
                            this.f20279.mo4972(this.f20280, this.f20280.m10222());
                            c6964 = this.f20280;
                        } catch (IOException e) {
                            e = e;
                            z = true;
                            if (!z) {
                                this.f20279.mo4971(this.f20280, e);
                            } else {
                                if (C7069.f20588 == null) {
                                    throw null;
                                }
                                C7069.f20586.m10381("Callback failure for " + C6964.m10214(this.f20280), 4, e);
                            }
                            c6964 = this.f20280;
                        } catch (Throwable th) {
                            th = th;
                            z = true;
                            this.f20280.cancel();
                            if (!z) {
                                IOException iOException = new IOException("canceled due to " + th);
                                iOException.addSuppressed(th);
                                this.f20279.mo4971(this.f20280, iOException);
                            }
                            throw th;
                        }
                    } catch (Throwable th2) {
                        this.f20280.f20275.f20058.m10054(this);
                        throw th2;
                    }
                } catch (IOException e2) {
                    e = e2;
                } catch (Throwable th3) {
                    th = th3;
                }
                c6964.f20275.f20058.m10054(this);
            } finally {
                threadCurrentThread.setName(name);
            }
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final String m10224() {
            return this.f20280.f20276.f20128.f20017;
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.ބ.ނ$ؠ, reason: contains not printable characters */
    public static final class C6966 extends WeakReference<C6964> {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final Object f20281;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C6966(C6964 c6964, Object obj) {
            super(c6964);
            if (c6964 == null) {
                C6635.m9824("referent");
                throw null;
            }
            this.f20281 = obj;
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.ބ.ނ$ހ, reason: contains not printable characters */
    public static final class C6967 extends C7098 {
        public C6967() {
        }

        @Override // p461.C7098
        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public void mo10225() {
            C6964.this.cancel();
        }
    }

    public C6964(C6921 c6921, C6926 c6926, boolean z) {
        if (c6921 == null) {
            C6635.m9824("client");
            throw null;
        }
        if (c6926 == null) {
            C6635.m9824("originalRequest");
            throw null;
        }
        this.f20275 = c6921;
        this.f20276 = c6926;
        this.f20277 = z;
        this.f20261 = c6921.f20059.f19958;
        this.f20262 = c6921.f20062.mo10062(this);
        C6967 c6967 = new C6967();
        c6967.mo10460(this.f20275.f20081, TimeUnit.MILLISECONDS);
        this.f20263 = c6967;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static final /* synthetic */ String m10214(C6964 c6964) {
        StringBuilder sb = new StringBuilder();
        sb.append(c6964.mo10027() ? "canceled " : "");
        sb.append(c6964.f20277 ? "web socket" : "call");
        sb.append(" to ");
        sb.append(c6964.f20276.f20128.m10087());
        return sb.toString();
    }

    @Override // p447.InterfaceC6868
    public void cancel() {
        C6968 c6968M10208;
        Socket socket;
        synchronized (this.f20261) {
            if (this.f20270) {
                return;
            }
            this.f20270 = true;
            C6960 c6960 = this.f20267;
            C6963 c6963 = this.f20265;
            if (c6963 == null || (c6968M10208 = c6963.m10208()) == null) {
                c6968M10208 = this.f20266;
            }
            if (c6960 != null) {
                c6960.f20238.cancel();
            } else if (c6968M10208 != null && (socket = c6968M10208.f20283) != null) {
                C6943.m10165(socket);
            }
            if (this.f20262 == null) {
                throw null;
            }
        }
    }

    public Object clone() {
        return new C6964(this.f20275, this.f20276, this.f20277);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final IOException m10215(IOException iOException) {
        synchronized (this.f20261) {
            this.f20272 = true;
        }
        return m10216(iOException, false);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final <E extends IOException> E m10216(E e, boolean z) {
        boolean z2;
        C6968 c6968;
        Socket socketM10223;
        boolean z3;
        synchronized (this.f20261) {
            if (z) {
                try {
                    z2 = this.f20267 == null;
                } finally {
                }
            }
            if (!z2) {
                throw new IllegalStateException("cannot release connection while it is in use".toString());
            }
            c6968 = this.f20266;
            socketM10223 = (this.f20266 != null && this.f20267 == null && (z || this.f20272)) ? m10223() : null;
            if (this.f20266 != null) {
                c6968 = null;
            }
            z3 = this.f20272 && this.f20267 == null;
        }
        if (socketM10223 != null) {
            C6943.m10165(socketM10223);
        }
        if (c6968 != null) {
            AbstractC6894 abstractC6894 = this.f20262;
            if (c6968 == null) {
                C6635.m9822();
                throw null;
            }
            if (abstractC6894 == null) {
                throw null;
            }
        }
        if (z3) {
            boolean z4 = e != null;
            if (!this.f20271 && this.f20263.m10400()) {
                InterruptedIOException interruptedIOException = new InterruptedIOException("timeout");
                if (e != null) {
                    interruptedIOException.initCause(e);
                }
                e = interruptedIOException;
            }
            if (z4) {
                AbstractC6894 abstractC68942 = this.f20262;
                if (e == null) {
                    C6635.m9822();
                    throw null;
                }
                if (abstractC68942 == null) {
                    throw null;
                }
            } else if (this.f20262 == null) {
                throw null;
            }
        }
        return e;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final <E extends IOException> E m10217(C6960 c6960, boolean z, boolean z2, E e) {
        boolean z3;
        if (c6960 == null) {
            C6635.m9824("exchange");
            throw null;
        }
        synchronized (this.f20261) {
            boolean z4 = true;
            if (!C6635.m9825(c6960, this.f20267)) {
                return e;
            }
            if (z) {
                z3 = !this.f20268;
                this.f20268 = true;
            } else {
                z3 = false;
            }
            if (z2) {
                if (!this.f20269) {
                    z3 = true;
                }
                this.f20269 = true;
            }
            if (this.f20268 && this.f20269 && z3) {
                C6960 c69602 = this.f20267;
                if (c69602 == null) {
                    C6635.m9822();
                    throw null;
                }
                c69602.f20234.f20293++;
                this.f20267 = null;
            } else {
                z4 = false;
            }
            return z4 ? (E) m10216(e, false) : e;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C6960 m10218(C6987 c6987) {
        if (c6987 == null) {
            C6635.m9824("chain");
            throw null;
        }
        synchronized (this.f20261) {
            if (!(!this.f20272)) {
                throw new IllegalStateException("released".toString());
            }
            if (!(this.f20267 == null)) {
                throw new IllegalStateException("Check failed.".toString());
            }
        }
        C6963 c6963 = this.f20265;
        if (c6963 == null) {
            C6635.m9822();
            throw null;
        }
        C6921 c6921 = this.f20275;
        if (c6963 == null) {
            throw null;
        }
        if (c6921 == null) {
            C6635.m9824("client");
            throw null;
        }
        try {
            InterfaceC6984 interfaceC6984M10226 = c6963.m10210(c6987.f20336, c6987.f20337, c6987.f20338, c6921.f20085, c6921.f20063, !C6635.m9825((Object) c6987.f20335.f20129, (Object) "GET")).m10226(c6921, c6987);
            AbstractC6894 abstractC6894 = this.f20262;
            C6963 c69632 = this.f20265;
            if (c69632 == null) {
                C6635.m9822();
                throw null;
            }
            C6960 c6960 = new C6960(this, abstractC6894, c69632, interfaceC6984M10226);
            this.f20274 = c6960;
            synchronized (this.f20261) {
                this.f20267 = c6960;
                this.f20268 = false;
                this.f20269 = false;
            }
            return c6960;
        } catch (IOException e) {
            c6963.m10211(e);
            throw new RouteException(e);
        } catch (RouteException e2) {
            c6963.m10211(e2.f2193);
            throw e2;
        }
    }

    @Override // p447.InterfaceC6868
    /* JADX INFO: renamed from: ֏ */
    public void mo10024(InterfaceC6870 interfaceC6870) {
        if (interfaceC6870 == null) {
            C6635.m9824("responseCallback");
            throw null;
        }
        synchronized (this) {
            if (!(!this.f20273)) {
                throw new IllegalStateException("Already Executed".toString());
            }
            this.f20273 = true;
        }
        m10221();
        this.f20275.f20058.m10052(new RunnableC6965(this, interfaceC6870));
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10219(C6968 c6968) {
        if (c6968 == null) {
            C6635.m9824("connection");
            throw null;
        }
        C6973 c6973 = this.f20261;
        if (!C6943.f20196 || Thread.holdsLock(c6973)) {
            if (!(this.f20266 == null)) {
                throw new IllegalStateException("Check failed.".toString());
            }
            this.f20266 = c6968;
            c6968.f20296.add(new C6966(this, this.f20264));
            return;
        }
        StringBuilder sbM4889 = C2803.m4889("Thread ");
        Thread threadCurrentThread = Thread.currentThread();
        C6635.m9823((Object) threadCurrentThread, "Thread.currentThread()");
        sbM4889.append(threadCurrentThread.getName());
        sbM4889.append(" MUST hold lock on ");
        sbM4889.append(c6973);
        throw new AssertionError(sbM4889.toString());
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10220(boolean z) {
        if (!(!this.f20272)) {
            throw new IllegalStateException("released".toString());
        }
        if (z) {
            C6960 c6960 = this.f20267;
            if (c6960 != null) {
                c6960.f20238.cancel();
                c6960.f20235.m10217(c6960, true, true, null);
            }
            if (!(this.f20267 == null)) {
                throw new IllegalStateException("Check failed.".toString());
            }
        }
        this.f20274 = null;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m10221() {
        if (C7069.f20588 == null) {
            throw null;
        }
        this.f20264 = C7069.f20586.mo10370("response.body().close()");
        if (this.f20262 == null) {
            throw null;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x008f  */
    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C6933 m10222() throws Throwable {
        ArrayList arrayList = new ArrayList();
        C4303.m7131((Collection) arrayList, (Iterable) this.f20275.f20060);
        arrayList.add(new C6989(this.f20275));
        arrayList.add(new C6980(this.f20275.f20067));
        if (this.f20275 == null) {
            throw null;
        }
        arrayList.add(new C6946());
        arrayList.add(C6958.f20228);
        if (!this.f20277) {
            C4303.m7131((Collection) arrayList, (Iterable) this.f20275.f20061);
        }
        arrayList.add(new C6981(this.f20277));
        C6926 c6926 = this.f20276;
        C6921 c6921 = this.f20275;
        C6987 c6987 = new C6987(this, arrayList, 0, null, c6926, c6921.f20082, c6921.f20083, c6921.f20084);
        boolean z = false;
        try {
            C6933 c6933Mo10101 = c6987.mo10101(this.f20276);
            if (mo10027()) {
                C6943.m10164((Closeable) c6933Mo10101);
                throw new IOException("Canceled");
            }
            m10215((IOException) null);
            return c6933Mo10101;
        } catch (IOException e) {
            try {
                IOException iOExceptionM10215 = m10215(e);
                if (iOExceptionM10215 == null) {
                    throw new TypeCastException("null cannot be cast to non-null type kotlin.Throwable");
                }
                throw iOExceptionM10215;
            } catch (Throwable th) {
                th = th;
                z = true;
                if (!z) {
                    m10215((IOException) null);
                }
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
            if (!z) {
            }
            throw th;
        }
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final Socket m10223() {
        C6973 c6973 = this.f20261;
        if (C6943.f20196 && !Thread.holdsLock(c6973)) {
            StringBuilder sbM4889 = C2803.m4889("Thread ");
            Thread threadCurrentThread = Thread.currentThread();
            C6635.m9823((Object) threadCurrentThread, "Thread.currentThread()");
            sbM4889.append(threadCurrentThread.getName());
            sbM4889.append(" MUST hold lock on ");
            sbM4889.append(c6973);
            throw new AssertionError(sbM4889.toString());
        }
        C6968 c6968 = this.f20266;
        if (c6968 == null) {
            C6635.m9822();
            throw null;
        }
        Iterator<Reference<C6964>> it = c6968.f20296.iterator();
        boolean z = false;
        int i = 0;
        while (true) {
            if (!it.hasNext()) {
                i = -1;
                break;
            }
            if (C6635.m9825(it.next().get(), this)) {
                break;
            }
            i++;
        }
        if (!(i != -1)) {
            throw new IllegalStateException("Check failed.".toString());
        }
        C6968 c69682 = this.f20266;
        if (c69682 == null) {
            C6635.m9822();
            throw null;
        }
        c69682.f20296.remove(i);
        this.f20266 = null;
        if (c69682.f20296.isEmpty()) {
            c69682.f20297 = System.nanoTime();
            C6973 c69732 = this.f20261;
            if (c69732 == null) {
                throw null;
            }
            if (C6943.f20196 && !Thread.holdsLock(c69732)) {
                StringBuilder sbM48892 = C2803.m4889("Thread ");
                Thread threadCurrentThread2 = Thread.currentThread();
                C6635.m9823((Object) threadCurrentThread2, "Thread.currentThread()");
                sbM48892.append(threadCurrentThread2.getName());
                sbM48892.append(" MUST hold lock on ");
                sbM48892.append(c69732);
                throw new AssertionError(sbM48892.toString());
            }
            if (c69682.f20290 || c69732.f20309 == 0) {
                c69732.f20308.remove(c69682);
                if (c69732.f20308.isEmpty()) {
                    c69732.f20306.m10184();
                }
                z = true;
            } else {
                c69732.f20306.m10185(c69732.f20307, 0L);
            }
            if (z) {
                return c69682.m10238();
            }
        }
        return null;
    }

    @Override // p447.InterfaceC6868
    /* JADX INFO: renamed from: ރ */
    public C6933 mo10025() {
        synchronized (this) {
            if (!(!this.f20273)) {
                throw new IllegalStateException("Already Executed".toString());
            }
            this.f20273 = true;
        }
        this.f20263.m10399();
        m10221();
        try {
            this.f20275.f20058.m10053(this);
            return m10222();
        } finally {
            C6890 c6890 = this.f20275.f20058;
            c6890.m10051(c6890.f19992, this);
        }
    }

    @Override // p447.InterfaceC6868
    /* JADX INFO: renamed from: ބ */
    public C6926 mo10026() {
        return this.f20276;
    }

    @Override // p447.InterfaceC6868
    /* JADX INFO: renamed from: ޅ */
    public boolean mo10027() {
        boolean z;
        synchronized (this.f20261) {
            z = this.f20270;
        }
        return z;
    }
}
