package 㿎;

import java.lang.ref.Reference;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import ඓ.K.K.K.C1293;
import 㿎.ሽ.C2540;
import 㿎.ሽ.ඓ.C2543;
import 㿎.ሽ.ඓ.C2548;
import 㿎.ሽ.ඓ.C2550;
import 㿎.ሽ.ᨨ.C2558;

/* renamed from: 㿎.㳳  reason: contains not printable characters */
/* compiled from: ConnectionPool */
public final class C2655 {

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static final Executor f9021 = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue(), C2540.m6649("OkHttp ConnectionPool", true));

    /* renamed from: ʬ  reason: contains not printable characters */
    public final Runnable f9022 = new RunnableC2656();

    /* renamed from: ඓ  reason: contains not printable characters */
    public final C2550 f9023 = new C2550();

    /* renamed from: ῲ  reason: contains not printable characters */
    public final long f9024;

    /* renamed from: K  reason: contains not printable characters */
    public final int f9025 = 5;

    /* renamed from: 㴹  reason: contains not printable characters */
    public boolean f9026;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final Deque<C2543> f9027 = new ArrayDeque();

    /* renamed from: 㿎.㳳$K  reason: contains not printable characters */
    /* compiled from: ConnectionPool */
    public class RunnableC2656 implements Runnable {
        public RunnableC2656() {
        }

        /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
        /* JADX WARNING: Missing exception handler attribute for start block: B:10:0x002b */
        public void run() {
            while (true) {
                long r0 = C2655.this.m6980(System.nanoTime());
                if (r0 != -1) {
                    if (r0 > 0) {
                        long j = r0 / 1000000;
                        long j2 = r0 - (1000000 * j);
                        synchronized (C2655.this) {
                            C2655.this.wait(j, (int) j2);
                        }
                    }
                } else {
                    return;
                }
            }
        }
    }

    public C2655() {
        TimeUnit timeUnit = TimeUnit.MINUTES;
        this.f9024 = timeUnit.toNanos(5);
    }

    /* renamed from: K  reason: contains not printable characters */
    public boolean m6981(C2543 r2) {
        if (r2.f8582 || this.f9025 == 0) {
            this.f9027.remove(r2);
            return true;
        }
        notifyAll();
        return false;
    }

    /* renamed from: K  reason: contains not printable characters */
    public long m6980(long j) {
        synchronized (this) {
            long j2 = Long.MIN_VALUE;
            C2543 r5 = null;
            int i = 0;
            int i2 = 0;
            for (C2543 r7 : this.f9027) {
                if (m6979(r7, j) > 0) {
                    i2++;
                } else {
                    i++;
                    long j3 = j - r7.f8587;
                    if (j3 > j2) {
                        r5 = r7;
                        j2 = j3;
                    }
                }
            }
            if (j2 < this.f9024) {
                if (i <= this.f9025) {
                    if (i > 0) {
                        return this.f9024 - j2;
                    } else if (i2 > 0) {
                        return this.f9024;
                    } else {
                        this.f9026 = false;
                        return -1;
                    }
                }
            }
            this.f9027.remove(r5);
            C2540.m6652(r5.f8581);
            return 0;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final int m6979(C2543 r7, long j) {
        List<Reference<C2548>> list = r7.f8580;
        int i = 0;
        while (i < list.size()) {
            Reference<C2548> reference = list.get(i);
            if (reference.get() != null) {
                i++;
            } else {
                StringBuilder r4 = C1293.m3416("A connection to ");
                r4.append(r7.f8579.f8559.f8969);
                r4.append(" was leaked. Did you forget to close a response body?");
                C2558.f8643.m6732(r4.toString(), ((C2548.C2549) reference).f8622);
                list.remove(i);
                r7.f8582 = true;
                if (list.isEmpty()) {
                    r7.f8587 = j - this.f9024;
                    return 0;
                }
            }
        }
        return list.size();
    }
}
