/*
 * Copyright 2014 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.channel.epoll;

/**
 * Tells if <a href="http://netty.io/wiki/native-transports.html">{@code netty-transport-native-epoll}</a> is supported.
 */
public final class Epoll {

    private static final boolean IS_AVAILABLE;

    static  {
        boolean available;
        int epollFd = -1;
        int eventFd = -1;
        try {
            epollFd = Native.epollCreate();
            eventFd = Native.eventFd();
            available = true;
        } catch (Throwable cause) {
            // ignore
            available = false;
        } finally {
            if (epollFd != -1) {
                try {
                    Native.close(epollFd);
                } catch (Exception ignore) {
                    // ignore
                }
            }
            if (eventFd != -1) {
                try {
                    Native.close(eventFd);
                } catch (Exception ignore) {
                    // ignore
                }
            }
        }
        IS_AVAILABLE = available;
    }

    /**
     * Returns {@code true} if and only if the
     * <a href="http://netty.io/wiki/native-transports.html">{@code netty-transport-native-epoll}</a> can be used.
     */
    public static boolean isAvailable() {
        return IS_AVAILABLE;
    }

    private Epoll() { }
}

@@ -847,27 +847,37 @@
 nal 
-boolean IS_AVAILABL
+Throwable UNAVAILABILITY_CAUS
 E;%0A%0A
@@ -902,25 +902,30 @@
     
-boolean available
+Throwable cause = null
 ;%0A  
@@ -1076,38 +1076,8 @@
 ();%0A
-            available = true;%0A
     
@@ -1099,21 +1099,17 @@
 rowable 
-cause
+t
 ) %7B%0A    
@@ -1120,47 +1120,17 @@
     
-// ignore%0A            available = false
+cause = t
 ;%0A  
@@ -1571,41 +1571,147 @@
   %7D%0A
-        IS_AVAILABLE = available;
+%0A        if (cause != null) %7B%0A            UNAVAILABILITY_CAUSE = cause;%0A        %7D else %7B%0A            UNAVAILABILITY_CAUSE = null;%0A        %7D
 %0A   
@@ -1875,65 +1875,877 @@
 /a%3E 
-can be used.%0A     */%0A    public static boolean isAvailabl
+is available.%0A     */%0A    public static boolean isAvailable() %7B%0A        return UNAVAILABILITY_CAUSE == null;%0A    %7D%0A%0A    /**%0A     * Ensure that %3Ca href=%22http://netty.io/wiki/native-transports.html%22%3E%7B@code netty-transport-native-epoll%7D%3C/a%3E is%0A     * available.%0A     *%0A     * @throws UnsatisfiedLinkError if unavailable%0A     */%0A    public static void ensureAvailability() %7B%0A        if (UNAVAILABILITY_CAUSE != null) %7B%0A            throw (Error) new UnsatisfiedLinkError(%0A                    %22failed to load the required native library%22).initCause(UNAVAILABILITY_CAUSE);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Returns the cause of unavailability of%0A     * %3Ca href=%22http://netty.io/wiki/native-transports.html%22%3E%7B@code netty-transport-native-epoll%7D%3C/a%3E.%0A     *%0A     * @return the cause if unavailable. %7B@code null%7D if available.%0A     */%0A    public static Throwable unavailabilityCaus
 e() 
@@ -2765,19 +2765,27 @@
 urn 
-IS_
+UN
 AVAILAB
-L
+ILITY_CAUS
 E;%0A 

Add more utility methods to check the availability of the epoll transport