package q9; import java.io.IOException; import java.net.Socket; import java.util.List; import n9.b0; import n9.i0; import n9.v; import n9.z; import q9.j; /* loaded from: classes2.dex */ final class d { /* renamed from: a, reason: collision with root package name */ private final k f13525a; /* renamed from: b, reason: collision with root package name */ private final n9.a f13526b; /* renamed from: c, reason: collision with root package name */ private final g f13527c; /* renamed from: d, reason: collision with root package name */ private final n9.g f13528d; /* renamed from: e, reason: collision with root package name */ private final v f13529e; /* renamed from: f, reason: collision with root package name */ private j.a f13530f; /* renamed from: g, reason: collision with root package name */ private final j f13531g; /* renamed from: h, reason: collision with root package name */ private e f13532h; /* renamed from: i, reason: collision with root package name */ private boolean f13533i; /* renamed from: j, reason: collision with root package name */ private i0 f13534j; d(k kVar, g gVar, n9.a aVar, n9.g gVar2, v vVar) { this.f13525a = kVar; this.f13527c = gVar; this.f13526b = aVar; this.f13528d = gVar2; this.f13529e = vVar; this.f13531g = new j(aVar, gVar.f13557e, gVar2, vVar); } private e c(int i10, int i11, int i12, int i13, boolean z10) { e eVar; Socket socket; Socket n10; e eVar2; i0 i0Var; boolean z11; boolean z12; List list; j.a aVar; synchronized (this.f13527c) { if (this.f13525a.i()) { throw new IOException("Canceled"); } this.f13533i = false; k kVar = this.f13525a; eVar = kVar.f13580i; socket = null; n10 = (eVar == null || !eVar.f13544k) ? null : kVar.n(); k kVar2 = this.f13525a; eVar2 = kVar2.f13580i; if (eVar2 != null) { eVar = null; } else { eVar2 = null; } if (eVar2 == null) { if (this.f13527c.h(this.f13526b, kVar2, null, false)) { eVar2 = this.f13525a.f13580i; i0Var = null; z11 = true; } else { i0Var = this.f13534j; if (i0Var != null) { this.f13534j = null; } else if (g()) { i0Var = this.f13525a.f13580i.q(); } z11 = false; } } i0Var = null; z11 = false; } o9.e.h(n10); if (eVar != null) { this.f13529e.i(this.f13528d, eVar); } if (z11) { this.f13529e.h(this.f13528d, eVar2); } if (eVar2 != null) { return eVar2; } if (i0Var != null || ((aVar = this.f13530f) != null && aVar.b())) { z12 = false; } else { this.f13530f = this.f13531g.d(); z12 = true; } synchronized (this.f13527c) { if (this.f13525a.i()) { throw new IOException("Canceled"); } if (z12) { list = this.f13530f.a(); if (this.f13527c.h(this.f13526b, this.f13525a, list, false)) { eVar2 = this.f13525a.f13580i; z11 = true; } } else { list = null; } if (!z11) { if (i0Var == null) { i0Var = this.f13530f.c(); } eVar2 = new e(this.f13527c, i0Var); this.f13532h = eVar2; } } if (z11) { this.f13529e.h(this.f13528d, eVar2); return eVar2; } eVar2.d(i10, i11, i12, i13, z10, this.f13528d, this.f13529e); this.f13527c.f13557e.a(eVar2.q()); synchronized (this.f13527c) { this.f13532h = null; if (this.f13527c.h(this.f13526b, this.f13525a, list, true)) { eVar2.f13544k = true; socket = eVar2.s(); eVar2 = this.f13525a.f13580i; this.f13534j = i0Var; } else { this.f13527c.g(eVar2); this.f13525a.a(eVar2); } } o9.e.h(socket); this.f13529e.h(this.f13528d, eVar2); return eVar2; } private e d(int i10, int i11, int i12, int i13, boolean z10, boolean z11) { while (true) { e c10 = c(i10, i11, i12, i13, z10); synchronized (this.f13527c) { if (c10.f13546m == 0 && !c10.n()) { return c10; } if (c10.m(z11)) { return c10; } c10.p(); } } } private boolean g() { e eVar = this.f13525a.f13580i; return eVar != null && eVar.f13545l == 0 && o9.e.E(eVar.q().a().l(), this.f13526b.l()); } e a() { return this.f13532h; } public r9.c b(b0 b0Var, z.a aVar, boolean z10) { try { return d(aVar.c(), aVar.a(), aVar.b(), b0Var.u(), b0Var.B(), z10).o(b0Var, aVar); } catch (IOException e10) { h(); throw new i(e10); } catch (i e11) { h(); throw e11; } } boolean e() { synchronized (this.f13527c) { boolean z10 = true; if (this.f13534j != null) { return true; } if (g()) { this.f13534j = this.f13525a.f13580i.q(); return true; } j.a aVar = this.f13530f; if ((aVar == null || !aVar.b()) && !this.f13531g.b()) { z10 = false; } return z10; } } boolean f() { boolean z10; synchronized (this.f13527c) { z10 = this.f13533i; } return z10; } void h() { synchronized (this.f13527c) { this.f13533i = true; } } }