package N4;

import L1.Y;
import O4.j;
import R4.l;
import R4.q;
import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.ConcurrentLinkedQueue;
import r4.AbstractC0983h;

/* JADX INFO: loaded from: classes.dex */
public final class b extends a {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ int f2236e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ Object f2237f;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ b(String str, Object obj, int i) {
        super(str, true);
        this.f2236e = i;
        this.f2237f = obj;
    }

    @Override // N4.a
    public final long a() {
        switch (this.f2236e) {
            case 0:
                ((l) this.f2237f).invoke();
                return -1L;
            case 1:
                Y y5 = (Y) this.f2237f;
                long jNanoTime = System.nanoTime();
                int i = 0;
                long j5 = Long.MIN_VALUE;
                j jVar = null;
                int i5 = 0;
                for (j jVar2 : (ConcurrentLinkedQueue) y5.f1642e) {
                    AbstractC0983h.d("connection", jVar2);
                    synchronized (jVar2) {
                        if (y5.b(jVar2, jNanoTime) > 0) {
                            i5++;
                        } else {
                            i++;
                            long j6 = jNanoTime - jVar2.q;
                            if (j6 > j5) {
                                jVar = jVar2;
                                j5 = j6;
                            }
                        }
                    }
                }
                long j7 = y5.f1639b;
                if (j5 < j7 && i <= 5) {
                    if (i > 0) {
                        return j7 - j5;
                    }
                    if (i5 > 0) {
                        return j7;
                    }
                    return -1L;
                }
                AbstractC0983h.b(jVar);
                synchronized (jVar) {
                    if (!jVar.p.isEmpty()) {
                        return 0L;
                    }
                    if (jVar.q + j5 != jNanoTime) {
                        return 0L;
                    }
                    jVar.f2358j = true;
                    ((ConcurrentLinkedQueue) y5.f1642e).remove(jVar);
                    Socket socket = jVar.f2353d;
                    AbstractC0983h.b(socket);
                    L4.b.c(socket);
                    if (!((ConcurrentLinkedQueue) y5.f1642e).isEmpty()) {
                        return 0L;
                    }
                    ((c) y5.f1640c).a();
                    return 0L;
                }
            default:
                q qVar = (q) this.f2237f;
                qVar.getClass();
                try {
                    qVar.f2711G.l(2, false, 0);
                    return -1L;
                } catch (IOException e2) {
                    qVar.e(e2);
                    return -1L;
                }
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public b(Y y5, String str) {
        super(str, true);
        this.f2236e = 1;
        this.f2237f = y5;
    }
}
