package o7;

import java.io.IOException;
import k7.B;
import k7.C;
import k7.D;
import r7.C1511a;

/* JADX INFO: loaded from: classes.dex */
public final class d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final i f15947a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final p7.b f15949c;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final l f15951e;

    public d(i iVar, e eVar, p7.b bVar) {
        P6.g.e(iVar, "call");
        P6.g.e(eVar, "finder");
        this.f15947a = iVar;
        this.f15948b = eVar;
        this.f15949c = bVar;
        this.f15951e = bVar.h();
    }

    public final IOException a(boolean z8, boolean z9, IOException iOException) {
        if (iOException != null) {
            d(iOException);
        }
        i iVar = this.f15947a;
        if (z9) {
            if (iOException != null) {
                P6.g.e(iVar, "call");
            } else {
                P6.g.e(iVar, "call");
            }
        }
        if (z8) {
            if (iOException != null) {
                P6.g.e(iVar, "call");
            } else {
                P6.g.e(iVar, "call");
            }
        }
        return iVar.k(this, z9, z8, iOException);
    }

    public final D b(C c3) throws IOException {
        p7.b bVar = this.f15949c;
        try {
            String strA = C.a("Content-Type", c3);
            long jD = bVar.d(c3);
            return new D(strA, jD, s7.l.c(new c(this, bVar.a(c3), jD)), 1);
        } catch (IOException e8) {
            P6.g.e(this.f15947a, "call");
            d(e8);
            throw e8;
        }
    }

    public final B c(boolean z8) throws IOException {
        try {
            B bG = this.f15949c.g(z8);
            if (bG != null) {
                bG.f14006m = this;
            }
            return bG;
        } catch (IOException e8) {
            P6.g.e(this.f15947a, "call");
            d(e8);
            throw e8;
        }
    }

    public final void d(IOException iOException) {
        this.f15950d = true;
        this.f15948b.c(iOException);
        l lVarH = this.f15949c.h();
        i iVar = this.f15947a;
        synchronized (lVarH) {
            try {
                P6.g.e(iVar, "call");
                if (!(iOException instanceof r7.B)) {
                    if (!(lVarH.f15988g != null) || (iOException instanceof C1511a)) {
                        lVarH.f15990j = true;
                        if (lVarH.f15993m == 0) {
                            l.d(iVar.f15969q, lVarH.f15983b, iOException);
                            lVarH.f15992l++;
                        }
                    }
                } else if (((r7.B) iOException).f16582q == 8) {
                    int i = lVarH.f15994n + 1;
                    lVarH.f15994n = i;
                    if (i > 1) {
                        lVarH.f15990j = true;
                        lVarH.f15992l++;
                    }
                } else if (((r7.B) iOException).f16582q != 9 || !iVar.f15967C) {
                    lVarH.f15990j = true;
                    lVarH.f15992l++;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
