package o;

import java.io.Closeable;
import java.io.IOException;
import java.net.Socket;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class KF implements Closeable {
    public static final C2880x70 K;
    public final C2880x70 A;
    public C2880x70 B;
    public long C;
    public long D;
    public long E;
    public long F;
    public final Socket G;
    public final SF H;
    public final FF I;
    public final LinkedHashSet J;
    public final CF l;
    public final LinkedHashMap m = new LinkedHashMap();
    public final String n;

    /* renamed from: o, reason: collision with root package name */
    public int f190o;
    public int p;
    public boolean q;
    public final Uc0 r;
    public final Tc0 s;
    public final Tc0 t;
    public final Tc0 u;
    public final ME v;
    public long w;
    public long x;
    public long y;
    public long z;

    static {
        C2880x70 c2880x70 = new C2880x70();
        c2880x70.b(7, 65535);
        c2880x70.b(5, 16384);
        K = c2880x70;
    }

    public KF(U7 u7) {
        this.l = (CF) u7.r;
        String str = (String) u7.f352o;
        this.n = str == null ? null : str;
        this.p = 3;
        Uc0 uc0 = (Uc0) u7.m;
        this.r = uc0;
        this.s = uc0.e();
        this.t = uc0.e();
        this.u = uc0.e();
        this.v = ME.B;
        C2880x70 c2880x70 = new C2880x70();
        c2880x70.b(7, 16777216);
        this.A = c2880x70;
        this.B = K;
        this.F = r0.a();
        Socket socket = (Socket) u7.n;
        this.G = socket == null ? null : socket;
        C1632k00 c1632k00 = (C1632k00) u7.q;
        this.H = new SF(c1632k00 == null ? null : c1632k00);
        C1822m00 c1822m00 = (C1822m00) u7.p;
        this.I = new FF(this, new NF(c1822m00 != null ? c1822m00 : null));
        this.J = new LinkedHashSet();
    }

    public final void b(int i, int i2, IOException iOException) throws IOException {
        int i3;
        Object[] array;
        byte[] bArr = AbstractC2264qi0.a;
        try {
            f(i);
        } catch (IOException unused) {
        }
        synchronized (this) {
            if (this.m.isEmpty()) {
                array = null;
            } else {
                array = this.m.values().toArray(new RF[0]);
                this.m.clear();
            }
        }
        RF[] rfArr = (RF[]) array;
        if (rfArr != null) {
            for (RF rf : rfArr) {
                try {
                    rf.c(i2, iOException);
                } catch (IOException unused2) {
                }
            }
        }
        try {
            this.H.close();
        } catch (IOException unused3) {
        }
        try {
            this.G.close();
        } catch (IOException unused4) {
        }
        this.s.e();
        this.t.e();
        this.u.e();
    }

    public final synchronized RF c(int i) {
        return (RF) this.m.get(Integer.valueOf(i));
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        b(1, 9, null);
    }

    public final synchronized RF d(int i) {
        RF rf;
        rf = (RF) this.m.remove(Integer.valueOf(i));
        notifyAll();
        return rf;
    }

    public final void f(int i) {
        synchronized (this.H) {
            synchronized (this) {
                if (this.q) {
                    return;
                }
                this.q = true;
                this.H.f(AbstractC2264qi0.a, this.f190o, i);
            }
        }
    }

    public final void flush() {
        this.H.flush();
    }

    public final synchronized void g(long j) {
        long j2 = this.C + j;
        this.C = j2;
        long j3 = j2 - this.D;
        if (j3 >= this.A.a() / 2) {
            m(0, j3);
            this.D += j3;
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:19:0x0035, code lost:
    
        r2 = java.lang.Math.min((int) java.lang.Math.min(r12, r6 - r4), r8.H.n);
        r6 = r2;
        r8.E += r6;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void j(int r9, boolean r10, o.C0732af r11, long r12) {
        /*
            r8 = this;
            r0 = 0
            int r2 = (r12 > r0 ? 1 : (r12 == r0 ? 0 : -1))
            r3 = 0
            if (r2 != 0) goto Ld
            o.SF r12 = r8.H
            r12.c(r10, r9, r11, r3)
            return
        Ld:
            int r2 = (r12 > r0 ? 1 : (r12 == r0 ? 0 : -1))
            if (r2 <= 0) goto L68
            monitor-enter(r8)
        L12:
            long r4 = r8.E     // Catch: java.lang.Throwable -> L2a java.lang.InterruptedException -> L59
            long r6 = r8.F     // Catch: java.lang.Throwable -> L2a java.lang.InterruptedException -> L59
            int r2 = (r4 > r6 ? 1 : (r4 == r6 ? 0 : -1))
            if (r2 < 0) goto L34
            java.util.LinkedHashMap r2 = r8.m     // Catch: java.lang.Throwable -> L2a java.lang.InterruptedException -> L59
            java.lang.Integer r4 = java.lang.Integer.valueOf(r9)     // Catch: java.lang.Throwable -> L2a java.lang.InterruptedException -> L59
            boolean r2 = r2.containsKey(r4)     // Catch: java.lang.Throwable -> L2a java.lang.InterruptedException -> L59
            if (r2 == 0) goto L2c
            r8.wait()     // Catch: java.lang.Throwable -> L2a java.lang.InterruptedException -> L59
            goto L12
        L2a:
            r9 = move-exception
            goto L66
        L2c:
            java.io.IOException r9 = new java.io.IOException     // Catch: java.lang.Throwable -> L2a java.lang.InterruptedException -> L59
            java.lang.String r10 = "stream closed"
            r9.<init>(r10)     // Catch: java.lang.Throwable -> L2a java.lang.InterruptedException -> L59
            throw r9     // Catch: java.lang.Throwable -> L2a java.lang.InterruptedException -> L59
        L34:
            long r6 = r6 - r4
            long r4 = java.lang.Math.min(r12, r6)     // Catch: java.lang.Throwable -> L2a
            int r2 = (int) r4     // Catch: java.lang.Throwable -> L2a
            o.SF r4 = r8.H     // Catch: java.lang.Throwable -> L2a
            int r4 = r4.n     // Catch: java.lang.Throwable -> L2a
            int r2 = java.lang.Math.min(r2, r4)     // Catch: java.lang.Throwable -> L2a
            long r4 = r8.E     // Catch: java.lang.Throwable -> L2a
            long r6 = (long) r2     // Catch: java.lang.Throwable -> L2a
            long r4 = r4 + r6
            r8.E = r4     // Catch: java.lang.Throwable -> L2a
            monitor-exit(r8)
            long r12 = r12 - r6
            o.SF r4 = r8.H
            if (r10 == 0) goto L54
            int r5 = (r12 > r0 ? 1 : (r12 == r0 ? 0 : -1))
            if (r5 != 0) goto L54
            r5 = 1
            goto L55
        L54:
            r5 = r3
        L55:
            r4.c(r5, r9, r11, r2)
            goto Ld
        L59:
            java.lang.Thread r9 = java.lang.Thread.currentThread()     // Catch: java.lang.Throwable -> L2a
            r9.interrupt()     // Catch: java.lang.Throwable -> L2a
            java.io.InterruptedIOException r9 = new java.io.InterruptedIOException     // Catch: java.lang.Throwable -> L2a
            r9.<init>()     // Catch: java.lang.Throwable -> L2a
            throw r9     // Catch: java.lang.Throwable -> L2a
        L66:
            monitor-exit(r8)
            throw r9
        L68:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: o.KF.j(int, boolean, o.af, long):void");
    }

    public final void l(int i, int i2) {
        this.s.c(new EF(this.n + '[' + i + "] writeSynReset", this, i, i2, 1), 0L);
    }

    public final void m(int i, long j) {
        this.s.c(new JF(this.n + '[' + i + "] windowUpdate", this, i, j), 0L);
    }
}
