package p447.p448.p455;

import java.io.EOFException;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketTimeoutException;
import java.util.ArrayDeque;
import kotlin.TypeCastException;
import kotlin.jvm.internal.DefaultConstructorMarker;
import okhttp3.internal.http2.StreamResetException;
import p138.p139.p143.p144.C2803;
import p402.InterfaceC6540;
import p402.p411.p413.C6635;
import p447.C6905;
import p447.p448.C6943;
import p461.C7098;
import p461.C7103;
import p461.C7130;
import p461.InterfaceC7107;
import p461.InterfaceC7127;
import p461.InterfaceC7129;

/* JADX INFO: renamed from: ސ.ޣ.އ.ވ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C7036 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public long f20513;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public long f20514;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public long f20515;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public long f20516;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final ArrayDeque<C6905> f20517;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public boolean f20518;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final C7039 f20519;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final C7038 f20520;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final C7040 f20521;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final C7040 f20522;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public EnumC7003 f20523;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public IOException f20524;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public final int f20525;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public final C7011 f20526;

    /* JADX INFO: renamed from: ސ.ޣ.އ.ވ$֏, reason: contains not printable characters */
    public static final class C7037 {
        public C7037() {
        }

        public /* synthetic */ C7037(DefaultConstructorMarker defaultConstructorMarker) {
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.އ.ވ$ؠ, reason: contains not printable characters */
    public final class C7038 implements InterfaceC7127 {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final C7103 f20527;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public boolean f20528;

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public boolean f20529;

        public C7038(boolean z) {
            this.f20529 = z;
            this.f20527 = new C7103();
        }

        public /* synthetic */ C7038(C7036 c7036, boolean z, int i, DefaultConstructorMarker defaultConstructorMarker) {
            z = (i & 1) != 0 ? false : z;
            C7036.this = c7036;
            this.f20529 = z;
            this.f20527 = new C7103();
        }

        @Override // p461.InterfaceC7127, java.io.Closeable, java.lang.AutoCloseable
        public void close() throws SocketTimeoutException {
            C7036 c7036 = C7036.this;
            if (C6943.f20196 && Thread.holdsLock(c7036)) {
                StringBuilder sbM4889 = C2803.m4889("Thread ");
                Thread threadCurrentThread = Thread.currentThread();
                C6635.m9823((Object) threadCurrentThread, "Thread.currentThread()");
                sbM4889.append(threadCurrentThread.getName());
                sbM4889.append(" MUST NOT hold lock on ");
                sbM4889.append(c7036);
                throw new AssertionError(sbM4889.toString());
            }
            synchronized (C7036.this) {
                if (this.f20528) {
                    return;
                }
                boolean z = C7036.this.m10333() == null;
                if (!C7036.this.f20520.f20529) {
                    if (this.f20527.f20630 > 0) {
                        while (this.f20527.f20630 > 0) {
                            m10339(true);
                        }
                    } else if (z) {
                        C7036 c70362 = C7036.this;
                        c70362.f20526.m10302(c70362.f20525, true, null, 0L);
                    }
                }
                synchronized (C7036.this) {
                    this.f20528 = true;
                }
                C7036.this.f20526.f20443.flush();
                C7036.this.m10326();
            }
        }

        @Override // p461.InterfaceC7127, java.io.Flushable
        public void flush() throws SocketTimeoutException {
            C7036 c7036 = C7036.this;
            if (C6943.f20196 && Thread.holdsLock(c7036)) {
                StringBuilder sbM4889 = C2803.m4889("Thread ");
                Thread threadCurrentThread = Thread.currentThread();
                C6635.m9823((Object) threadCurrentThread, "Thread.currentThread()");
                sbM4889.append(threadCurrentThread.getName());
                sbM4889.append(" MUST NOT hold lock on ");
                sbM4889.append(c7036);
                throw new AssertionError(sbM4889.toString());
            }
            synchronized (C7036.this) {
                C7036.this.m10330();
            }
            while (this.f20527.f20630 > 0) {
                m10339(false);
                C7036.this.f20526.flush();
            }
        }

        @Override // p461.InterfaceC7127
        /* JADX INFO: renamed from: ֏ */
        public void mo10205(C7103 c7103, long j) throws SocketTimeoutException {
            if (c7103 == null) {
                C6635.m9824("source");
                throw null;
            }
            C7036 c7036 = C7036.this;
            if (!C6943.f20196 || !Thread.holdsLock(c7036)) {
                this.f20527.mo10205(c7103, j);
                while (this.f20527.f20630 >= 16384) {
                    m10339(false);
                }
            } else {
                StringBuilder sbM4889 = C2803.m4889("Thread ");
                Thread threadCurrentThread = Thread.currentThread();
                C6635.m9823((Object) threadCurrentThread, "Thread.currentThread()");
                sbM4889.append(threadCurrentThread.getName());
                sbM4889.append(" MUST NOT hold lock on ");
                sbM4889.append(c7036);
                throw new AssertionError(sbM4889.toString());
            }
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final void m10339(boolean z) throws SocketTimeoutException {
            long jMin;
            boolean z2;
            synchronized (C7036.this) {
                C7036.this.f20522.m10399();
                while (C7036.this.f20515 >= C7036.this.f20516 && !this.f20529 && !this.f20528 && C7036.this.m10333() == null) {
                    try {
                        C7036.this.m10338();
                    } finally {
                    }
                }
                C7036.this.f20522.m10343();
                C7036.this.m10330();
                jMin = Math.min(C7036.this.f20516 - C7036.this.f20515, this.f20527.f20630);
                C7036.this.f20515 += jMin;
                z2 = z && jMin == this.f20527.f20630 && C7036.this.m10333() == null;
            }
            C7036.this.f20522.m10399();
            try {
                C7036.this.f20526.m10302(C7036.this.f20525, z2, this.f20527, jMin);
            } finally {
            }
        }

        @Override // p461.InterfaceC7127
        /* JADX INFO: renamed from: ށ */
        public C7130 mo10278() {
            return C7036.this.f20522;
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.އ.ވ$ހ, reason: contains not printable characters */
    public final class C7039 implements InterfaceC7129 {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final C7103 f20531 = new C7103();

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public final C7103 f20532 = new C7103();

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public boolean f20533;

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        public final long f20534;

        /* JADX INFO: renamed from: އ, reason: contains not printable characters */
        public boolean f20535;

        public C7039(long j, boolean z) {
            this.f20534 = j;
            this.f20535 = z;
        }

        @Override // p461.InterfaceC7129, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            long j;
            synchronized (C7036.this) {
                this.f20533 = true;
                j = this.f20532.f20630;
                C7103 c7103 = this.f20532;
                c7103.skip(c7103.f20630);
                C7036 c7036 = C7036.this;
                if (c7036 == null) {
                    throw new TypeCastException("null cannot be cast to non-null type java.lang.Object");
                }
                c7036.notifyAll();
            }
            if (j > 0) {
                m10341(j);
            }
            C7036.this.m10326();
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final void m10340(InterfaceC7107 interfaceC7107, long j) {
            boolean z;
            boolean z2;
            boolean z3;
            long j2;
            if (interfaceC7107 == null) {
                C6635.m9824("source");
                throw null;
            }
            C7036 c7036 = C7036.this;
            if (C6943.f20196 && Thread.holdsLock(c7036)) {
                StringBuilder sbM4889 = C2803.m4889("Thread ");
                Thread threadCurrentThread = Thread.currentThread();
                C6635.m9823((Object) threadCurrentThread, "Thread.currentThread()");
                sbM4889.append(threadCurrentThread.getName());
                sbM4889.append(" MUST NOT hold lock on ");
                sbM4889.append(c7036);
                throw new AssertionError(sbM4889.toString());
            }
            while (j > 0) {
                synchronized (C7036.this) {
                    z = this.f20535;
                    z2 = true;
                    z3 = this.f20532.f20630 + j > this.f20534;
                }
                if (z3) {
                    interfaceC7107.skip(j);
                    C7036.this.m10328(EnumC7003.FLOW_CONTROL_ERROR);
                    return;
                }
                if (z) {
                    interfaceC7107.skip(j);
                    return;
                }
                long jMo10207 = interfaceC7107.mo10207(this.f20531, j);
                if (jMo10207 == -1) {
                    throw new EOFException();
                }
                j -= jMo10207;
                synchronized (C7036.this) {
                    if (this.f20533) {
                        j2 = this.f20531.f20630;
                        C7103 c7103 = this.f20531;
                        c7103.skip(c7103.f20630);
                    } else {
                        if (this.f20532.f20630 != 0) {
                            z2 = false;
                        }
                        this.f20532.mo10410((InterfaceC7129) this.f20531);
                        if (z2) {
                            C7036 c70362 = C7036.this;
                            if (c70362 == null) {
                                throw new TypeCastException("null cannot be cast to non-null type java.lang.Object");
                            }
                            c70362.notifyAll();
                        }
                        j2 = 0;
                    }
                }
                if (j2 > 0) {
                    m10341(j2);
                }
            }
        }

        @Override // p461.InterfaceC7129
        /* JADX INFO: renamed from: ؠ */
        public long mo10207(C7103 c7103, long j) throws Throwable {
            Throwable streamResetException;
            long jMo10207;
            boolean z;
            long j2;
            if (c7103 == null) {
                C6635.m9824("sink");
                throw null;
            }
            long j3 = 0;
            if (!(j >= 0)) {
                throw new IllegalArgumentException(C2803.m4874("byteCount < 0: ", j).toString());
            }
            while (true) {
                synchronized (C7036.this) {
                    C7036.this.f20521.m10399();
                    try {
                        if (C7036.this.m10333() != null) {
                            streamResetException = C7036.this.f20524;
                            if (streamResetException == null) {
                                EnumC7003 enumC7003M10333 = C7036.this.m10333();
                                if (enumC7003M10333 == null) {
                                    C6635.m9822();
                                    throw null;
                                }
                                streamResetException = new StreamResetException(enumC7003M10333);
                            }
                        } else {
                            streamResetException = null;
                        }
                        if (this.f20533) {
                            throw new IOException("stream closed");
                        }
                        if (this.f20532.f20630 > j3) {
                            jMo10207 = this.f20532.mo10207(c7103, Math.min(j, this.f20532.f20630));
                            C7036.this.f20513 += jMo10207;
                            long j4 = C7036.this.f20513 - C7036.this.f20514;
                            if (streamResetException == null && j4 >= C7036.this.f20526.f20436.m10361() / 2) {
                                C7036.this.f20526.m10299(C7036.this.f20525, j4);
                                C7036.this.f20514 = C7036.this.f20513;
                            }
                        } else if (this.f20535 || streamResetException != null) {
                            jMo10207 = -1;
                        } else {
                            C7036.this.m10338();
                            z = true;
                            j2 = -1;
                        }
                        j2 = jMo10207;
                        z = false;
                    } finally {
                        C7036.this.f20521.m10343();
                    }
                }
                if (!z) {
                    if (j2 != -1) {
                        m10341(j2);
                        return j2;
                    }
                    if (streamResetException == null) {
                        return -1L;
                    }
                    throw streamResetException;
                }
                j3 = 0;
            }
        }

        @Override // p461.InterfaceC7129
        /* JADX INFO: renamed from: ށ */
        public C7130 mo10277() {
            return C7036.this.f20521;
        }

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        public final void m10341(long j) {
            C7036 c7036 = C7036.this;
            if (!C6943.f20196 || !Thread.holdsLock(c7036)) {
                C7036.this.f20526.m10309(j);
                return;
            }
            StringBuilder sbM4889 = C2803.m4889("Thread ");
            Thread threadCurrentThread = Thread.currentThread();
            C6635.m9823((Object) threadCurrentThread, "Thread.currentThread()");
            sbM4889.append(threadCurrentThread.getName());
            sbM4889.append(" MUST NOT hold lock on ");
            sbM4889.append(c7036);
            throw new AssertionError(sbM4889.toString());
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.އ.ވ$ށ, reason: contains not printable characters */
    public final class C7040 extends C7098 {
        public C7040() {
        }

        @Override // p461.C7098
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public IOException mo10342(IOException iOException) {
            SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout");
            if (iOException != null) {
                socketTimeoutException.initCause(iOException);
            }
            return socketTimeoutException;
        }

        @Override // p461.C7098
        /* JADX INFO: renamed from: ޅ */
        public void mo10225() {
            C7036.this.m10328(EnumC7003.CANCEL);
            C7036.this.f20526.m10298();
        }

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        public final void m10343() throws SocketTimeoutException {
            if (m10400()) {
                throw new SocketTimeoutException("timeout");
            }
        }
    }

    static {
        new C7037(null);
    }

    public C7036(int i, C7011 c7011, boolean z, boolean z2, C6905 c6905) {
        if (c7011 == null) {
            C6635.m9824("connection");
            throw null;
        }
        this.f20525 = i;
        this.f20526 = c7011;
        this.f20516 = c7011.f20437.m10361();
        this.f20517 = new ArrayDeque<>();
        this.f20519 = new C7039(this.f20526.f20436.m10361(), z2);
        this.f20520 = new C7038(z);
        this.f20521 = new C7040();
        this.f20522 = new C7040();
        if (c6905 == null) {
            if (!m10335()) {
                throw new IllegalStateException("remotely-initiated streams should have headers".toString());
            }
        } else {
            if (!(!m10335())) {
                throw new IllegalStateException("locally-initiated streams shouldn't have headers yet".toString());
            }
            this.f20517.add(c6905);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10326() {
        boolean z;
        boolean zM10336;
        if (C6943.f20196 && Thread.holdsLock(this)) {
            StringBuilder sbM4889 = C2803.m4889("Thread ");
            Thread threadCurrentThread = Thread.currentThread();
            C6635.m9823((Object) threadCurrentThread, "Thread.currentThread()");
            sbM4889.append(threadCurrentThread.getName());
            sbM4889.append(" MUST NOT hold lock on ");
            sbM4889.append(this);
            throw new AssertionError(sbM4889.toString());
        }
        synchronized (this) {
            z = !this.f20519.f20535 && this.f20519.f20533 && (this.f20520.f20529 || this.f20520.f20528);
            zM10336 = m10336();
        }
        if (z) {
            m10329(EnumC7003.CANCEL, (IOException) null);
        } else {
            if (zM10336) {
                return;
            }
            this.f20526.m10307(this.f20525);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10327(C6905 c6905, boolean z) {
        boolean zM10336;
        if (c6905 == null) {
            C6635.m9824("headers");
            throw null;
        }
        if (C6943.f20196 && Thread.holdsLock(this)) {
            StringBuilder sbM4889 = C2803.m4889("Thread ");
            Thread threadCurrentThread = Thread.currentThread();
            C6635.m9823((Object) threadCurrentThread, "Thread.currentThread()");
            sbM4889.append(threadCurrentThread.getName());
            sbM4889.append(" MUST NOT hold lock on ");
            sbM4889.append(this);
            throw new AssertionError(sbM4889.toString());
        }
        synchronized (this) {
            if (!this.f20518 || !z) {
                this.f20518 = true;
                this.f20517.add(c6905);
            } else if (this.f20519 == null) {
                throw null;
            }
            if (z) {
                this.f20519.f20535 = true;
            }
            zM10336 = m10336();
            notifyAll();
        }
        if (zM10336) {
            return;
        }
        this.f20526.m10307(this.f20525);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10328(EnumC7003 enumC7003) {
        if (enumC7003 == null) {
            C6635.m9824("errorCode");
            throw null;
        }
        if (m10332(enumC7003, null)) {
            this.f20526.m10301(this.f20525, enumC7003);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10329(EnumC7003 enumC7003, IOException iOException) {
        if (enumC7003 == null) {
            C6635.m9824("rstStatusCode");
            throw null;
        }
        if (m10332(enumC7003, iOException)) {
            C7011 c7011 = this.f20526;
            c7011.f20443.m10348(this.f20525, enumC7003);
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m10330() throws IOException {
        C7038 c7038 = this.f20520;
        if (c7038.f20528) {
            throw new IOException("stream closed");
        }
        if (c7038.f20529) {
            throw new IOException("stream finished");
        }
        if (this.f20523 != null) {
            IOException iOException = this.f20524;
            if (iOException != null) {
                throw iOException;
            }
            EnumC7003 enumC7003 = this.f20523;
            if (enumC7003 != null) {
                throw new StreamResetException(enumC7003);
            }
            C6635.m9822();
            throw null;
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final synchronized void m10331(EnumC7003 enumC7003) {
        if (enumC7003 == null) {
            C6635.m9824("errorCode");
            throw null;
        }
        if (this.f20523 == null) {
            this.f20523 = enumC7003;
            notifyAll();
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final boolean m10332(EnumC7003 enumC7003, IOException iOException) {
        if (C6943.f20196 && Thread.holdsLock(this)) {
            StringBuilder sbM4889 = C2803.m4889("Thread ");
            Thread threadCurrentThread = Thread.currentThread();
            C6635.m9823((Object) threadCurrentThread, "Thread.currentThread()");
            sbM4889.append(threadCurrentThread.getName());
            sbM4889.append(" MUST NOT hold lock on ");
            sbM4889.append(this);
            throw new AssertionError(sbM4889.toString());
        }
        synchronized (this) {
            if (this.f20523 != null) {
                return false;
            }
            if (this.f20519.f20535 && this.f20520.f20529) {
                return false;
            }
            this.f20523 = enumC7003;
            this.f20524 = iOException;
            notifyAll();
            this.f20526.m10307(this.f20525);
            return true;
        }
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final synchronized EnumC7003 m10333() {
        return this.f20523;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final InterfaceC7127 m10334() {
        synchronized (this) {
            if (!(this.f20518 || m10335())) {
                throw new IllegalStateException("reply before requesting the sink".toString());
            }
        }
        return this.f20520;
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final boolean m10335() {
        return this.f20526.f20418 == ((this.f20525 & 1) == 1);
    }

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final synchronized boolean m10336() {
        if (this.f20523 != null) {
            return false;
        }
        if ((this.f20519.f20535 || this.f20519.f20533) && (this.f20520.f20529 || this.f20520.f20528)) {
            if (this.f20518) {
                return false;
            }
        }
        return true;
    }

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final synchronized C6905 m10337() {
        C6905 c6905RemoveFirst;
        this.f20521.m10399();
        while (this.f20517.isEmpty() && this.f20523 == null) {
            try {
                m10338();
            } catch (Throwable th) {
                this.f20521.m10343();
                throw th;
            }
        }
        this.f20521.m10343();
        if (!(!this.f20517.isEmpty())) {
            IOException iOException = this.f20524;
            if (iOException != null) {
                throw iOException;
            }
            EnumC7003 enumC7003 = this.f20523;
            if (enumC7003 != null) {
                throw new StreamResetException(enumC7003);
            }
            C6635.m9822();
            throw null;
        }
        c6905RemoveFirst = this.f20517.removeFirst();
        C6635.m9823((Object) c6905RemoveFirst, "headersQueue.removeFirst()");
        return c6905RemoveFirst;
    }

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final void m10338() throws InterruptedIOException {
        try {
            wait();
        } catch (InterruptedException unused) {
            Thread.currentThread().interrupt();
            throw new InterruptedIOException();
        }
    }
}
