package n4;

import I2.K;
import java.io.IOException;
import java.net.Socket;
import m4.Z1;
import p5.C2734d;
import p5.C2740j;
import p5.N;
import p5.S;

/* JADX INFO: renamed from: n4.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C2625c implements N {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Z1 f21629c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final n f21630d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final int f21631e;
    public C2734d l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public Socket f21635m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public boolean f21636n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f21637o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public int f21638p;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Object f21627a = new Object();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final C2740j f21628b = new C2740j();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f21632f = false;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f21633j = false;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public boolean f21634k = false;

    public C2625c(Z1 z12, n nVar) {
        A4.g.o(z12, "executor");
        this.f21629c = z12;
        this.f21630d = nVar;
        this.f21631e = 10000;
    }

    public final void a(C2734d c2734d, Socket socket) {
        A4.g.t(this.l == null, "AsyncSink's becomeConnected should only be called once.");
        this.l = c2734d;
        this.f21635m = socket;
    }

    @Override // p5.N, java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        if (this.f21634k) {
            return;
        }
        this.f21634k = true;
        this.f21629c.execute(new K(this, 16));
    }

    @Override // p5.N, java.io.Flushable
    public final void flush() throws IOException {
        if (this.f21634k) {
            throw new IOException("closed");
        }
        u4.b.c();
        try {
            synchronized (this.f21627a) {
                if (!this.f21633j) {
                    this.f21633j = true;
                    this.f21629c.execute(new C2623a(this, 1));
                }
            }
            u4.b.f24588a.getClass();
        } catch (Throwable th) {
            try {
                u4.b.f24588a.getClass();
            } catch (Throwable th2) {
                th.addSuppressed(th2);
            }
            throw th;
        }
    }

    @Override // p5.N
    public final S timeout() {
        return S.f23074d;
    }

    @Override // p5.N
    public final void write(C2740j c2740j, long j4) throws IOException {
        A4.g.o(c2740j, "source");
        if (this.f21634k) {
            throw new IOException("closed");
        }
        u4.b.c();
        try {
            synchronized (this.f21627a) {
                try {
                    this.f21628b.write(c2740j, j4);
                    int i6 = this.f21638p + this.f21637o;
                    this.f21638p = i6;
                    boolean z6 = false;
                    this.f21637o = 0;
                    if (!this.f21636n && i6 > this.f21631e) {
                        this.f21636n = true;
                        z6 = true;
                    } else if (!this.f21632f && !this.f21633j && this.f21628b.b() > 0) {
                        this.f21632f = true;
                    }
                    if (z6) {
                        try {
                            this.f21635m.close();
                        } catch (IOException e6) {
                            this.f21630d.p(e6);
                        }
                        u4.b.f24588a.getClass();
                        return;
                    }
                    this.f21629c.execute(new C2623a(this, 0));
                } finally {
                }
            }
            u4.b.f24588a.getClass();
        } catch (Throwable th) {
            try {
                u4.b.f24588a.getClass();
            } catch (Throwable th2) {
                th.addSuppressed(th2);
            }
            throw th;
        }
    }
}
