Does OS X not support epoll function?

2019-04-21 01:37发布

I'm learning to use epoll function. But my OS X, Mountain Lion doesn't have a header file, sys/epoll.h.

I'd like to use epoll function on OS X. How Can I use epoll function?

2条回答
The star\"
2楼-- · 2019-04-21 01:48

on Mac OSX use kqueue instead of epoll. Do something like this in your java code.

 final boolean isMac = 

  System.getProperty("os.name").toLowerCase(Locale.US).contains("mac");

    // Configure the server.
    // See https://netty.io/wiki/native-transports.html
    EventLoopGroup bossGroup;
    EventLoopGroup workerGroup;

    if (isMac) {
        bossGroup = new io.netty.channel.kqueue.KQueueEventLoopGroup();
        workerGroup = new io.netty.channel.kqueue.KQueueEventLoopGroup(5);
    } else {
        bossGroup =  new io.netty.channel.epoll.EpollEventLoopGroup();
        workerGroup = new io.netty.channel.epoll.EpollEventLoopGroup(5);
    }

Ensure that you have added io.netty on pom.xml

查看更多
放荡不羁爱自由
3楼-- · 2019-04-21 01:54

Mac OS X doesn't support epoll, but it does support kqueue which is very similar.

查看更多
登录 后发表回答