package t9; import java.io.EOFException; import java.io.IOException; import java.io.InterruptedIOException; import java.net.SocketTimeoutException; import java.util.ArrayDeque; import java.util.Deque; import n9.x; import x9.u; import x9.v; import x9.w; /* loaded from: classes2.dex */ public final class i { /* renamed from: a, reason: collision with root package name */ long f14593a = 0; /* renamed from: b, reason: collision with root package name */ long f14594b; /* renamed from: c, reason: collision with root package name */ final int f14595c; /* renamed from: d, reason: collision with root package name */ final f f14596d; /* renamed from: e, reason: collision with root package name */ private final Deque f14597e; /* renamed from: f, reason: collision with root package name */ private boolean f14598f; /* renamed from: g, reason: collision with root package name */ private final b f14599g; /* renamed from: h, reason: collision with root package name */ final a f14600h; /* renamed from: i, reason: collision with root package name */ final c f14601i; /* renamed from: j, reason: collision with root package name */ final c f14602j; /* renamed from: k, reason: collision with root package name */ t9.b f14603k; /* renamed from: l, reason: collision with root package name */ IOException f14604l; final class a implements u { /* renamed from: a, reason: collision with root package name */ private final x9.c f14605a = new x9.c(); /* renamed from: b, reason: collision with root package name */ private x f14606b; /* renamed from: c, reason: collision with root package name */ boolean f14607c; /* renamed from: d, reason: collision with root package name */ boolean f14608d; a() { } private void c(boolean z10) { i iVar; long min; i iVar2; boolean z11; synchronized (i.this) { i.this.f14602j.k(); while (true) { try { iVar = i.this; if (iVar.f14594b > 0 || this.f14608d || this.f14607c || iVar.f14603k != null) { break; } else { iVar.q(); } } finally { i.this.f14602j.u(); } } iVar.f14602j.u(); i.this.c(); min = Math.min(i.this.f14594b, this.f14605a.u0()); iVar2 = i.this; iVar2.f14594b -= min; } iVar2.f14602j.k(); if (z10) { try { if (min == this.f14605a.u0()) { z11 = true; i iVar3 = i.this; iVar3.f14596d.N0(iVar3.f14595c, z11, this.f14605a, min); } } catch (Throwable th) { throw th; } } z11 = false; i iVar32 = i.this; iVar32.f14596d.N0(iVar32.f14595c, z11, this.f14605a, min); } @Override // x9.u public w b() { return i.this.f14602j; } @Override // x9.u, java.io.Closeable, java.lang.AutoCloseable public void close() { synchronized (i.this) { if (this.f14607c) { return; } if (!i.this.f14600h.f14608d) { boolean z10 = this.f14605a.u0() > 0; if (this.f14606b != null) { while (this.f14605a.u0() > 0) { c(false); } i iVar = i.this; iVar.f14596d.O0(iVar.f14595c, true, o9.e.J(this.f14606b)); } else if (z10) { while (this.f14605a.u0() > 0) { c(true); } } else { i iVar2 = i.this; iVar2.f14596d.N0(iVar2.f14595c, true, null, 0L); } } synchronized (i.this) { this.f14607c = true; } i.this.f14596d.flush(); i.this.b(); } } @Override // x9.u, java.io.Flushable public void flush() { synchronized (i.this) { i.this.c(); } while (this.f14605a.u0() > 0) { c(false); i.this.f14596d.flush(); } } @Override // x9.u public void t0(x9.c cVar, long j10) { this.f14605a.t0(cVar, j10); while (this.f14605a.u0() >= 16384) { c(false); } } } private final class b implements v { /* renamed from: a, reason: collision with root package name */ private final x9.c f14610a = new x9.c(); /* renamed from: b, reason: collision with root package name */ private final x9.c f14611b = new x9.c(); /* renamed from: c, reason: collision with root package name */ private final long f14612c; /* renamed from: d, reason: collision with root package name */ private x f14613d; /* renamed from: e, reason: collision with root package name */ boolean f14614e; /* renamed from: f, reason: collision with root package name */ boolean f14615f; b(long j10) { this.f14612c = j10; } private void G(long j10) { i.this.f14596d.M0(j10); } @Override // x9.v public w b() { return i.this.f14601i; } @Override // x9.v, java.io.Closeable, java.lang.AutoCloseable public void close() { long u02; synchronized (i.this) { this.f14614e = true; u02 = this.f14611b.u0(); this.f14611b.I(); i.this.notifyAll(); } if (u02 > 0) { G(u02); } i.this.b(); } /* JADX WARN: Code restructure failed: missing block: B:25:0x0080, code lost: r11 = -1; */ /* JADX WARN: Removed duplicated region for block: B:30:0x008d */ /* JADX WARN: Removed duplicated region for block: B:33:0x0091 */ @Override // x9.v /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public long s0(x9.c r11, long r12) { /* r10 = this; r0 = 0 int r2 = (r12 > r0 ? 1 : (r12 == r0 ? 0 : -1)) if (r2 < 0) goto La9 L6: t9.i r2 = t9.i.this monitor-enter(r2) t9.i r3 = t9.i.this // Catch: java.lang.Throwable -> La6 t9.i$c r3 = r3.f14601i // Catch: java.lang.Throwable -> La6 r3.k() // Catch: java.lang.Throwable -> La6 t9.i r3 = t9.i.this // Catch: java.lang.Throwable -> L9d t9.b r4 = r3.f14603k // Catch: java.lang.Throwable -> L9d if (r4 == 0) goto L25 java.io.IOException r3 = r3.f14604l // Catch: java.lang.Throwable -> L9d if (r3 == 0) goto L1b goto L26 L1b: t9.n r3 = new t9.n // Catch: java.lang.Throwable -> L9d t9.i r4 = t9.i.this // Catch: java.lang.Throwable -> L9d t9.b r4 = r4.f14603k // Catch: java.lang.Throwable -> L9d r3.(r4) // Catch: java.lang.Throwable -> L9d goto L26 L25: r3 = 0 L26: boolean r4 = r10.f14614e // Catch: java.lang.Throwable -> L9d if (r4 != 0) goto L95 x9.c r4 = r10.f14611b // Catch: java.lang.Throwable -> L9d long r4 = r4.u0() // Catch: java.lang.Throwable -> L9d r6 = -1 int r8 = (r4 > r0 ? 1 : (r4 == r0 ? 0 : -1)) if (r8 <= 0) goto L6c x9.c r4 = r10.f14611b // Catch: java.lang.Throwable -> L9d long r8 = r4.u0() // Catch: java.lang.Throwable -> L9d long r12 = java.lang.Math.min(r12, r8) // Catch: java.lang.Throwable -> L9d long r11 = r4.s0(r11, r12) // Catch: java.lang.Throwable -> L9d t9.i r13 = t9.i.this // Catch: java.lang.Throwable -> L9d long r4 = r13.f14593a // Catch: java.lang.Throwable -> L9d long r4 = r4 + r11 r13.f14593a = r4 // Catch: java.lang.Throwable -> L9d if (r3 != 0) goto L81 t9.f r13 = r13.f14596d // Catch: java.lang.Throwable -> L9d t9.m r13 = r13.f14524t // Catch: java.lang.Throwable -> L9d int r13 = r13.d() // Catch: java.lang.Throwable -> L9d int r13 = r13 / 2 long r8 = (long) r13 // Catch: java.lang.Throwable -> L9d int r13 = (r4 > r8 ? 1 : (r4 == r8 ? 0 : -1)) if (r13 < 0) goto L81 t9.i r13 = t9.i.this // Catch: java.lang.Throwable -> L9d t9.f r4 = r13.f14596d // Catch: java.lang.Throwable -> L9d int r5 = r13.f14595c // Catch: java.lang.Throwable -> L9d long r8 = r13.f14593a // Catch: java.lang.Throwable -> L9d r4.S0(r5, r8) // Catch: java.lang.Throwable -> L9d t9.i r13 = t9.i.this // Catch: java.lang.Throwable -> L9d r13.f14593a = r0 // Catch: java.lang.Throwable -> L9d goto L81 L6c: boolean r4 = r10.f14615f // Catch: java.lang.Throwable -> L9d if (r4 != 0) goto L80 if (r3 != 0) goto L80 t9.i r3 = t9.i.this // Catch: java.lang.Throwable -> L9d r3.q() // Catch: java.lang.Throwable -> L9d t9.i r3 = t9.i.this // Catch: java.lang.Throwable -> La6 t9.i$c r3 = r3.f14601i // Catch: java.lang.Throwable -> La6 r3.u() // Catch: java.lang.Throwable -> La6 monitor-exit(r2) // Catch: java.lang.Throwable -> La6 goto L6 L80: r11 = r6 L81: t9.i r13 = t9.i.this // Catch: java.lang.Throwable -> La6 t9.i$c r13 = r13.f14601i // Catch: java.lang.Throwable -> La6 r13.u() // Catch: java.lang.Throwable -> La6 monitor-exit(r2) // Catch: java.lang.Throwable -> La6 int r13 = (r11 > r6 ? 1 : (r11 == r6 ? 0 : -1)) if (r13 == 0) goto L91 r10.G(r11) return r11 L91: if (r3 != 0) goto L94 return r6 L94: throw r3 L95: java.io.IOException r11 = new java.io.IOException // Catch: java.lang.Throwable -> L9d java.lang.String r12 = "stream closed" r11.(r12) // Catch: java.lang.Throwable -> L9d throw r11 // Catch: java.lang.Throwable -> L9d L9d: r11 = move-exception t9.i r12 = t9.i.this // Catch: java.lang.Throwable -> La6 t9.i$c r12 = r12.f14601i // Catch: java.lang.Throwable -> La6 r12.u() // Catch: java.lang.Throwable -> La6 throw r11 // Catch: java.lang.Throwable -> La6 La6: r11 = move-exception monitor-exit(r2) // Catch: java.lang.Throwable -> La6 throw r11 La9: java.lang.IllegalArgumentException r11 = new java.lang.IllegalArgumentException java.lang.StringBuilder r0 = new java.lang.StringBuilder r0.() java.lang.String r1 = "byteCount < 0: " r0.append(r1) r0.append(r12) java.lang.String r12 = r0.toString() r11.(r12) throw r11 */ throw new UnsupportedOperationException("Method not decompiled: t9.i.b.s0(x9.c, long):long"); } void z(x9.e eVar, long j10) { boolean z10; boolean z11; boolean z12; long j11; while (j10 > 0) { synchronized (i.this) { z10 = this.f14615f; z11 = true; z12 = this.f14611b.u0() + j10 > this.f14612c; } if (z12) { eVar.skip(j10); i.this.f(t9.b.FLOW_CONTROL_ERROR); return; } if (z10) { eVar.skip(j10); return; } long s02 = eVar.s0(this.f14610a, j10); if (s02 == -1) { throw new EOFException(); } j10 -= s02; synchronized (i.this) { if (this.f14614e) { j11 = this.f14610a.u0(); this.f14610a.I(); } else { if (this.f14611b.u0() != 0) { z11 = false; } this.f14611b.H0(this.f14610a); if (z11) { i.this.notifyAll(); } j11 = 0; } } if (j11 > 0) { G(j11); } } } } class c extends x9.a { c() { } @Override // x9.a protected IOException o(IOException iOException) { SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout"); if (iOException != null) { socketTimeoutException.initCause(iOException); } return socketTimeoutException; } @Override // x9.a protected void t() { i.this.f(t9.b.CANCEL); i.this.f14596d.I0(); } public void u() { if (n()) { throw o(null); } } } i(int i10, f fVar, boolean z10, boolean z11, x xVar) { ArrayDeque arrayDeque = new ArrayDeque(); this.f14597e = arrayDeque; this.f14601i = new c(); this.f14602j = new c(); if (fVar == null) { throw new NullPointerException("connection == null"); } this.f14595c = i10; this.f14596d = fVar; this.f14594b = fVar.f14525u.d(); b bVar = new b(fVar.f14524t.d()); this.f14599g = bVar; a aVar = new a(); this.f14600h = aVar; bVar.f14615f = z11; aVar.f14608d = z10; if (xVar != null) { arrayDeque.add(xVar); } if (j() && xVar != null) { throw new IllegalStateException("locally-initiated streams shouldn't have headers yet"); } if (!j() && xVar == null) { throw new IllegalStateException("remotely-initiated streams should have headers"); } } private boolean e(t9.b bVar, IOException iOException) { synchronized (this) { if (this.f14603k != null) { return false; } if (this.f14599g.f14615f && this.f14600h.f14608d) { return false; } this.f14603k = bVar; this.f14604l = iOException; notifyAll(); this.f14596d.H0(this.f14595c); return true; } } void a(long j10) { this.f14594b += j10; if (j10 > 0) { notifyAll(); } } void b() { boolean z10; boolean k10; synchronized (this) { b bVar = this.f14599g; if (!bVar.f14615f && bVar.f14614e) { a aVar = this.f14600h; if (aVar.f14608d || aVar.f14607c) { z10 = true; k10 = k(); } } z10 = false; k10 = k(); } if (z10) { d(t9.b.CANCEL, null); } else { if (k10) { return; } this.f14596d.H0(this.f14595c); } } void c() { a aVar = this.f14600h; if (aVar.f14607c) { throw new IOException("stream closed"); } if (aVar.f14608d) { throw new IOException("stream finished"); } if (this.f14603k != null) { IOException iOException = this.f14604l; if (iOException == null) { throw new n(this.f14603k); } } } public void d(t9.b bVar, IOException iOException) { if (e(bVar, iOException)) { this.f14596d.Q0(this.f14595c, bVar); } } public void f(t9.b bVar) { if (e(bVar, null)) { this.f14596d.R0(this.f14595c, bVar); } } public int g() { return this.f14595c; } public u h() { synchronized (this) { if (!this.f14598f && !j()) { throw new IllegalStateException("reply before requesting the sink"); } } return this.f14600h; } public v i() { return this.f14599g; } public boolean j() { return this.f14596d.f14505a == ((this.f14595c & 1) == 1); } public synchronized boolean k() { if (this.f14603k != null) { return false; } b bVar = this.f14599g; if (bVar.f14615f || bVar.f14614e) { a aVar = this.f14600h; if (aVar.f14608d || aVar.f14607c) { if (this.f14598f) { return false; } } } return true; } public w l() { return this.f14601i; } void m(x9.e eVar, int i10) { this.f14599g.z(eVar, i10); } /* JADX WARN: Removed duplicated region for block: B:9:0x0018 A[Catch: all -> 0x002e, TryCatch #0 {, blocks: (B:3:0x0001, B:7:0x0009, B:9:0x0018, B:10:0x001c, B:11:0x0023, B:18:0x000f), top: B:2:0x0001 }] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ void n(n9.x r3, boolean r4) { /* r2 = this; monitor-enter(r2) boolean r0 = r2.f14598f // Catch: java.lang.Throwable -> L2e r1 = 1 if (r0 == 0) goto Lf if (r4 != 0) goto L9 goto Lf L9: t9.i$b r0 = r2.f14599g // Catch: java.lang.Throwable -> L2e t9.i.b.c(r0, r3) // Catch: java.lang.Throwable -> L2e goto L16 Lf: r2.f14598f = r1 // Catch: java.lang.Throwable -> L2e java.util.Deque r0 = r2.f14597e // Catch: java.lang.Throwable -> L2e r0.add(r3) // Catch: java.lang.Throwable -> L2e L16: if (r4 == 0) goto L1c t9.i$b r3 = r2.f14599g // Catch: java.lang.Throwable -> L2e r3.f14615f = r1 // Catch: java.lang.Throwable -> L2e L1c: boolean r3 = r2.k() // Catch: java.lang.Throwable -> L2e r2.notifyAll() // Catch: java.lang.Throwable -> L2e monitor-exit(r2) // Catch: java.lang.Throwable -> L2e if (r3 != 0) goto L2d t9.f r3 = r2.f14596d int r4 = r2.f14595c r3.H0(r4) L2d: return L2e: r3 = move-exception monitor-exit(r2) // Catch: java.lang.Throwable -> L2e throw r3 */ throw new UnsupportedOperationException("Method not decompiled: t9.i.n(n9.x, boolean):void"); } synchronized void o(t9.b bVar) { if (this.f14603k == null) { this.f14603k = bVar; notifyAll(); } } public synchronized x p() { this.f14601i.k(); while (this.f14597e.isEmpty() && this.f14603k == null) { try { q(); } catch (Throwable th) { this.f14601i.u(); throw th; } } this.f14601i.u(); if (this.f14597e.isEmpty()) { IOException iOException = this.f14604l; if (iOException != null) { throw iOException; } throw new n(this.f14603k); } return (x) this.f14597e.removeFirst(); } void q() { try { wait(); } catch (InterruptedException unused) { Thread.currentThread().interrupt(); throw new InterruptedIOException(); } } public w r() { return this.f14602j; } }