package P4;

import K4.m;
import K4.p;
import K4.t;
import K4.u;
import K4.w;
import O4.h;
import O4.j;
import R4.C0182a;
import com.google.android.gms.internal.measurement.AbstractC0366e2;
import java.io.IOException;
import java.net.ProtocolException;
import r4.AbstractC0983h;

/* JADX INFO: loaded from: classes.dex */
public final class b implements p {
    @Override // K4.p
    public final u a(f fVar) throws IOException {
        IOException iOException;
        IOException iOException2;
        O4.c cVar = fVar.f2554d;
        AbstractC0983h.b(cVar);
        h hVar = (h) cVar.f2320b;
        d dVar = (d) cVar.f2322d;
        j jVar = (j) cVar.f2323e;
        F3.e eVar = fVar.f2555e;
        long jCurrentTimeMillis = System.currentTimeMillis();
        try {
            try {
                AbstractC0983h.e("call", hVar);
                dVar.e(eVar);
                AbstractC0366e2.q((String) eVar.f715m);
                hVar.h(cVar, true, false, null);
                try {
                    dVar.c();
                    iOException = null;
                } catch (IOException e2) {
                    cVar.f(e2);
                    throw e2;
                }
            } catch (IOException e6) {
                AbstractC0983h.e("call", hVar);
                cVar.f(e6);
                throw e6;
            }
        } catch (IOException e7) {
            if ((e7 instanceof C0182a) || !cVar.f2319a) {
                throw e7;
            }
            iOException = e7;
        }
        try {
            t tVarE = cVar.e(false);
            AbstractC0983h.b(tVarE);
            AbstractC0983h.e("call", hVar);
            tVarE.f1211a = eVar;
            tVarE.f1215e = jVar.f2354e;
            tVarE.f1220k = jCurrentTimeMillis;
            iOException2 = iOException;
            try {
                tVarE.f1221l = System.currentTimeMillis();
                u uVarA = tVarE.a();
                int i = uVarA.f1226n;
                if (i == 100 || (102 <= i && i < 200)) {
                    t tVarE2 = cVar.e(false);
                    AbstractC0983h.b(tVarE2);
                    tVarE2.f1211a = eVar;
                    tVarE2.f1215e = jVar.f2354e;
                    tVarE2.f1220k = jCurrentTimeMillis;
                    tVarE2.f1221l = System.currentTimeMillis();
                    uVarA = tVarE2.a();
                    i = uVarA.f1226n;
                }
                AbstractC0983h.e("call", hVar);
                t tVarE3 = uVarA.e();
                tVarE3.f1217g = cVar.c(uVarA);
                u uVarA2 = tVarE3.a();
                if ("close".equalsIgnoreCase(((m) uVarA2.f1223k.f716n).a("Connection")) || "close".equalsIgnoreCase(u.a(uVarA2, "Connection"))) {
                    dVar.g().k();
                }
                if (i == 204 || i == 205) {
                    w wVar = uVarA2.q;
                    if ((wVar == null ? -1L : wVar.a()) > 0) {
                        StringBuilder sb = new StringBuilder("HTTP ");
                        sb.append(i);
                        sb.append(" had non-zero Content-Length: ");
                        sb.append(wVar == null ? null : Long.valueOf(wVar.a()));
                        throw new ProtocolException(sb.toString());
                    }
                }
                return uVarA2;
            } catch (IOException e8) {
                e = e8;
                if (iOException2 == null) {
                    throw e;
                }
                S4.d.a(iOException2, e);
                throw iOException2;
            }
        } catch (IOException e9) {
            e = e9;
            iOException2 = iOException;
        }
    }
}
