package io.netty.channel.epoll;

import io.netty.channel.unix.FileDescriptor;
import io.netty.util.internal.PlatformDependent;

/* JADX INFO: loaded from: classes.dex */
public final class Epoll {
    private static final Throwable UNAVAILABILITY_CAUSE;

    static {
        FileDescriptor fileDescriptorNewEpollCreate;
        try {
            fileDescriptorNewEpollCreate = Native.newEpollCreate();
            try {
                FileDescriptor fileDescriptorNewEventFd = Native.newEventFd();
                if (fileDescriptorNewEpollCreate != null) {
                    try {
                        fileDescriptorNewEpollCreate.close();
                    } catch (Exception unused) {
                    }
                }
                if (fileDescriptorNewEventFd != null) {
                    try {
                        fileDescriptorNewEventFd.close();
                    } catch (Exception unused2) {
                    }
                }
                th = null;
            } catch (Throwable th) {
                th = th;
                if (fileDescriptorNewEpollCreate != null) {
                    try {
                        fileDescriptorNewEpollCreate.close();
                    } catch (Exception unused3) {
                    }
                }
            }
        } catch (Throwable th2) {
            th = th2;
            fileDescriptorNewEpollCreate = null;
        }
        if (th != null) {
            UNAVAILABILITY_CAUSE = th;
        } else {
            UNAVAILABILITY_CAUSE = PlatformDependent.hasUnsafe() ? null : new IllegalStateException("sun.misc.Unsafe not available", PlatformDependent.getUnsafeUnavailabilityCause());
        }
    }

    private Epoll() {
    }

    public static void ensureAvailability() {
        Throwable th = UNAVAILABILITY_CAUSE;
        if (th != null) {
            throw ((Error) new UnsatisfiedLinkError("failed to load the required native library").initCause(th));
        }
    }

    public static boolean isAvailable() {
        return UNAVAILABILITY_CAUSE == null;
    }

    public static Throwable unavailabilityCause() {
        return UNAVAILABILITY_CAUSE;
    }
}
