diff options
Diffstat (limited to 'gnu/java/nio/SelectorProviderImpl.java')
-rw-r--r-- | gnu/java/nio/SelectorProviderImpl.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/gnu/java/nio/SelectorProviderImpl.java b/gnu/java/nio/SelectorProviderImpl.java index 47521107e..56167b69e 100644 --- a/gnu/java/nio/SelectorProviderImpl.java +++ b/gnu/java/nio/SelectorProviderImpl.java @@ -37,6 +37,9 @@ exception statement from your version. */ package gnu.java.nio; + +import gnu.classpath.SystemProperties; + import java.io.IOException; import java.nio.channels.DatagramChannel; import java.nio.channels.Pipe; @@ -47,6 +50,11 @@ import java.nio.channels.spi.SelectorProvider; public class SelectorProviderImpl extends SelectorProvider { + private static final String SELECTOR_IMPL_KQUEUE = "kqueue"; + private static final String SELECTOR_IMPL_EPOLL = "epoll"; + private static final String SELECTOR_IMPL = "gnu.java.nio.selectorImpl"; + private static boolean epoll_failed = false; + public SelectorProviderImpl () { } @@ -66,6 +74,35 @@ public class SelectorProviderImpl extends SelectorProvider public AbstractSelector openSelector () throws IOException { + String selectorImpl = "default"; + if (KqueueSelectorImpl.kqueue_supported()) + selectorImpl = SELECTOR_IMPL_KQUEUE; + if (EpollSelectorImpl.epoll_supported() && !epoll_failed) + selectorImpl = SELECTOR_IMPL_EPOLL; + selectorImpl = SystemProperties.getProperty(SELECTOR_IMPL, selectorImpl); + + if (selectorImpl.equals(SELECTOR_IMPL_KQUEUE)) + return new KqueueSelectorImpl(this); + + if (selectorImpl.equals(SELECTOR_IMPL_EPOLL)) + { + // We jump through these hoops because even though epoll may look + // like it's available (sys/epoll.h exists, and you can link against + // all the epoll functions) it may not be available in the kernel + // (especially 2.4 kernels), meaning you will get ENOSYS at run time. + // + // Madness! + try + { + return new EpollSelectorImpl(this); + } + catch (InternalError e) + { + // epoll_create throws this on ENOSYS. + epoll_failed = true; + } + } + return new SelectorImpl (this); } |