package k5; import h5.d0; import h5.f0; import h5.i; import h5.m0; import h5.n; import h5.t; import java.io.IOException; import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.net.Socket; import java.util.List; import k5.f; /* loaded from: classes2.dex */ public final class g { /* renamed from: o, reason: collision with root package name */ static final /* synthetic */ boolean f11251o = true; /* renamed from: a, reason: collision with root package name */ public final h5.a f11252a; /* renamed from: b, reason: collision with root package name */ private f.a f11253b; /* renamed from: c, reason: collision with root package name */ private m0 f11254c; /* renamed from: d, reason: collision with root package name */ private final n f11255d; /* renamed from: e, reason: collision with root package name */ public final i f11256e; /* renamed from: f, reason: collision with root package name */ public final t f11257f; /* renamed from: g, reason: collision with root package name */ private final Object f11258g; /* renamed from: h, reason: collision with root package name */ private final f f11259h; /* renamed from: i, reason: collision with root package name */ private int f11260i; /* renamed from: j, reason: collision with root package name */ private c f11261j; /* renamed from: k, reason: collision with root package name */ private boolean f11262k; /* renamed from: l, reason: collision with root package name */ private boolean f11263l; /* renamed from: m, reason: collision with root package name */ private boolean f11264m; /* renamed from: n, reason: collision with root package name */ private l5.c f11265n; public static final class a extends WeakReference { /* renamed from: a, reason: collision with root package name */ public final Object f11266a; a(g gVar, Object obj) { super(gVar); this.f11266a = obj; } } public g(n nVar, h5.a aVar, i iVar, t tVar, Object obj) { this.f11255d = nVar; this.f11252a = aVar; this.f11256e = iVar; this.f11257f = tVar; this.f11259h = new f(aVar, g(), iVar, tVar); this.f11258g = obj; } private Socket a() { if (!f11251o && !Thread.holdsLock(this.f11255d)) { throw new AssertionError(); } c cVar = this.f11261j; if (cVar == null || !cVar.f11233k) { return null; } return b(false, false, f11251o); } private Socket b(boolean z10, boolean z11, boolean z12) { Socket socket; if (!f11251o && !Thread.holdsLock(this.f11255d)) { throw new AssertionError(); } if (z12) { this.f11265n = null; } if (z11) { this.f11263l = f11251o; } c cVar = this.f11261j; if (cVar == null) { return null; } if (z10) { cVar.f11233k = f11251o; } if (this.f11265n != null) { return null; } if (!this.f11263l && !cVar.f11233k) { return null; } e(cVar); if (this.f11261j.f11236n.isEmpty()) { this.f11261j.f11237o = System.nanoTime(); if (i5.a.f10869a.e(this.f11255d, this.f11261j)) { socket = this.f11261j.r(); this.f11261j = null; return socket; } } socket = null; this.f11261j = null; return socket; } private c c(int i10, int i11, int i12, int i13, boolean z10) { c cVar; Socket a10; c cVar2; Socket socket; m0 m0Var; boolean z11; boolean z12; f.a aVar; synchronized (this.f11255d) { if (this.f11263l) { throw new IllegalStateException("released"); } if (this.f11265n != null) { throw new IllegalStateException("codec != null"); } if (this.f11264m) { throw new IOException("Canceled"); } cVar = this.f11261j; a10 = a(); cVar2 = this.f11261j; socket = null; if (cVar2 != null) { cVar = null; } else { cVar2 = null; } if (!this.f11262k) { cVar = null; } if (cVar2 == null) { i5.a.f10869a.h(this.f11255d, this.f11252a, this, null); c cVar3 = this.f11261j; if (cVar3 != null) { cVar2 = cVar3; z11 = f11251o; m0Var = null; } else { m0Var = this.f11254c; } } else { m0Var = null; } z11 = false; } i5.c.k(a10); if (cVar != null) { this.f11257f.i(this.f11256e, cVar); } if (z11) { this.f11257f.h(this.f11256e, cVar2); } if (cVar2 != null) { return cVar2; } if (m0Var != null || ((aVar = this.f11253b) != null && aVar.b())) { z12 = false; } else { this.f11253b = this.f11259h.h(); z12 = f11251o; } synchronized (this.f11255d) { if (this.f11264m) { throw new IOException("Canceled"); } if (z12) { List a11 = this.f11253b.a(); int size = a11.size(); int i14 = 0; while (true) { if (i14 >= size) { break; } m0 m0Var2 = (m0) a11.get(i14); i5.a.f10869a.h(this.f11255d, this.f11252a, this, m0Var2); c cVar4 = this.f11261j; if (cVar4 != null) { this.f11254c = m0Var2; cVar2 = cVar4; z11 = f11251o; break; } i14++; } } if (!z11) { if (m0Var == null) { m0Var = this.f11253b.c(); } this.f11254c = m0Var; this.f11260i = 0; cVar2 = new c(this.f11255d, m0Var); f(cVar2, false); } } if (!z11) { cVar2.k(i10, i11, i12, i13, z10, this.f11256e, this.f11257f); g().a(cVar2.q()); synchronized (this.f11255d) { this.f11262k = f11251o; i5.a.f10869a.i(this.f11255d, cVar2); if (cVar2.o()) { socket = i5.a.f10869a.f(this.f11255d, this.f11252a, this); cVar2 = this.f11261j; } } i5.c.k(socket); } this.f11257f.h(this.f11256e, cVar2); return cVar2; } private c d(int i10, int i11, int i12, int i13, boolean z10, boolean z11) { while (true) { c c10 = c(i10, i11, i12, i13, z10); synchronized (this.f11255d) { if (c10.f11234l == 0) { return c10; } if (c10.n(z11)) { return c10; } l(); } } } private void e(c cVar) { int size = cVar.f11236n.size(); for (int i10 = 0; i10 < size; i10++) { if (((Reference) cVar.f11236n.get(i10)).get() == this) { cVar.f11236n.remove(i10); return; } } throw new IllegalStateException(); } private d g() { return i5.a.f10869a.j(this.f11255d); } public void f(c cVar, boolean z10) { if (!f11251o && !Thread.holdsLock(this.f11255d)) { throw new AssertionError(); } if (this.f11261j != null) { throw new IllegalStateException(); } this.f11261j = cVar; this.f11262k = z10; cVar.f11236n.add(new a(this, this.f11258g)); } public l5.c h() { l5.c cVar; synchronized (this.f11255d) { cVar = this.f11265n; } return cVar; } public synchronized c i() { return this.f11261j; } public boolean j() { f.a aVar; if (this.f11254c != null || (((aVar = this.f11253b) != null && aVar.b()) || this.f11259h.g())) { return f11251o; } return false; } public l5.c k(f0 f0Var, d0.a aVar, boolean z10) { try { l5.c p10 = d(aVar.c(), aVar.a(), aVar.b(), f0Var.t(), f0Var.A(), z10).p(f0Var, aVar, this); synchronized (this.f11255d) { this.f11265n = p10; } return p10; } catch (IOException e10) { throw new e(e10); } } public void l() { c cVar; Socket b10; synchronized (this.f11255d) { cVar = this.f11261j; b10 = b(f11251o, false, false); if (this.f11261j != null) { cVar = null; } } i5.c.k(b10); if (cVar != null) { this.f11257f.i(this.f11256e, cVar); } } public void m() { c cVar; Socket b10; synchronized (this.f11255d) { cVar = this.f11261j; b10 = b(false, f11251o, false); if (this.f11261j != null) { cVar = null; } } i5.c.k(b10); if (cVar != null) { this.f11257f.i(this.f11256e, cVar); } } public Socket n(c cVar) { if (!f11251o && !Thread.holdsLock(this.f11255d)) { throw new AssertionError(); } if (this.f11265n != null || this.f11261j.f11236n.size() != 1) { throw new IllegalStateException(); } Reference reference = (Reference) this.f11261j.f11236n.get(0); Socket b10 = b(f11251o, false, false); this.f11261j = cVar; cVar.f11236n.add(reference); return b10; } public m0 o() { return this.f11254c; } /* JADX WARN: Removed duplicated region for block: B:16:0x004c A[Catch: all -> 0x0060, TryCatch #0 {, blocks: (B:4:0x0003, B:6:0x000a, B:8:0x0012, B:10:0x0019, B:14:0x0042, B:16:0x004c, B:20:0x0052, B:28:0x003d, B:30:0x001e, B:32:0x0022, B:34:0x0028, B:36:0x002c, B:38:0x0032, B:41:0x0038), top: B:3:0x0003 }] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public void p(java.io.IOException r7) { /* r6 = this; h5.n r0 = r6.f11255d monitor-enter(r0) boolean r1 = r7 instanceof n5.j // Catch: java.lang.Throwable -> L60 r2 = 0 r3 = 1 r4 = 0 if (r1 == 0) goto L1e n5.j r7 = (n5.j) r7 // Catch: java.lang.Throwable -> L60 n5.b r7 = r7.f12109a // Catch: java.lang.Throwable -> L60 n5.b r1 = n5.b.REFUSED_STREAM // Catch: java.lang.Throwable -> L60 if (r7 != r1) goto L17 int r5 = r6.f11260i // Catch: java.lang.Throwable -> L60 int r5 = r5 + r3 r6.f11260i = r5 // Catch: java.lang.Throwable -> L60 L17: if (r7 != r1) goto L3d int r7 = r6.f11260i // Catch: java.lang.Throwable -> L60 if (r7 <= r3) goto L41 goto L3d L1e: k5.c r1 = r6.f11261j // Catch: java.lang.Throwable -> L60 if (r1 == 0) goto L41 boolean r1 = r1.o() // Catch: java.lang.Throwable -> L60 if (r1 == 0) goto L2c boolean r1 = r7 instanceof n5.a // Catch: java.lang.Throwable -> L60 if (r1 == 0) goto L41 L2c: k5.c r1 = r6.f11261j // Catch: java.lang.Throwable -> L60 int r1 = r1.f11234l // Catch: java.lang.Throwable -> L60 if (r1 != 0) goto L3f h5.m0 r1 = r6.f11254c // Catch: java.lang.Throwable -> L60 if (r1 == 0) goto L3d if (r7 == 0) goto L3d k5.f r5 = r6.f11259h // Catch: java.lang.Throwable -> L60 r5.f(r1, r7) // Catch: java.lang.Throwable -> L60 L3d: r6.f11254c = r2 // Catch: java.lang.Throwable -> L60 L3f: r7 = 1 goto L42 L41: r7 = 0 L42: k5.c r1 = r6.f11261j // Catch: java.lang.Throwable -> L60 java.net.Socket r7 = r6.b(r7, r4, r3) // Catch: java.lang.Throwable -> L60 k5.c r3 = r6.f11261j // Catch: java.lang.Throwable -> L60 if (r3 != 0) goto L52 boolean r3 = r6.f11262k // Catch: java.lang.Throwable -> L60 if (r3 != 0) goto L51 goto L52 L51: r2 = r1 L52: monitor-exit(r0) // Catch: java.lang.Throwable -> L60 i5.c.k(r7) if (r2 == 0) goto L5f h5.t r7 = r6.f11257f h5.i r0 = r6.f11256e r7.i(r0, r2) L5f: return L60: r7 = move-exception monitor-exit(r0) // Catch: java.lang.Throwable -> L60 throw r7 */ throw new UnsupportedOperationException("Method not decompiled: k5.g.p(java.io.IOException):void"); } public void q(boolean z10, l5.c cVar, long j10, IOException iOException) { c cVar2; Socket b10; boolean z11; this.f11257f.p(this.f11256e, j10); synchronized (this.f11255d) { if (cVar != null) { if (cVar == this.f11265n) { if (!z10) { this.f11261j.f11234l++; } cVar2 = this.f11261j; b10 = b(z10, false, f11251o); if (this.f11261j != null) { cVar2 = null; } z11 = this.f11263l; } } throw new IllegalStateException("expected " + this.f11265n + " but was " + cVar); } i5.c.k(b10); if (cVar2 != null) { this.f11257f.i(this.f11256e, cVar2); } if (iOException != null) { this.f11257f.c(this.f11256e, iOException); } else if (z11) { this.f11257f.b(this.f11256e); } } public String toString() { c i10 = i(); return i10 != null ? i10.toString() : this.f11252a.toString(); } }