Skip to content
This repository was archived by the owner on Jun 7, 2022. It is now read-only.

Commit 20c00be

Browse files
author
Dytanic
committed
added netty transport native kqueue support
1 parent 9db3e89 commit 20c00be

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

cloudnet-lib/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
<classifier>linux-x86_64</classifier>
2323
<scope>compile</scope>
2424
</dependency>
25+
<dependency>
26+
<groupId>io.netty</groupId>
27+
<artifactId>netty-transport-native-kqueue</artifactId>
28+
<version>${dependency.netty.version}</version>
29+
<classifier>osx-x86_64</classifier>
30+
<scope>compile</scope>
31+
</dependency>
2532
<dependency>
2633
<groupId>io.netty</groupId>
2734
<artifactId>netty-codec</artifactId>

cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/NetworkUtils.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
import io.netty.channel.epoll.EpollEventLoopGroup;
1717
import io.netty.channel.epoll.EpollServerSocketChannel;
1818
import io.netty.channel.epoll.EpollSocketChannel;
19+
import io.netty.channel.kqueue.KQueue;
20+
import io.netty.channel.kqueue.KQueueEventLoopGroup;
21+
import io.netty.channel.kqueue.KQueueServerSocketChannel;
22+
import io.netty.channel.kqueue.KQueueSocketChannel;
1923
import io.netty.channel.nio.NioEventLoopGroup;
2024
import io.netty.channel.socket.ServerSocketChannel;
2125
import io.netty.channel.socket.SocketChannel;
@@ -62,11 +66,6 @@ private NetworkUtils()
6266
SPACE_STRING = " ",
6367
SLASH_STRING = "/";
6468

65-
public static Class<? extends SocketChannel> socketChannel()
66-
{
67-
return EPOLL ? EpollSocketChannel.class : NioSocketChannel.class;
68-
}
69-
7069
private static final char[] VALUES = new char[]{
7170
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'
7271
, 'J', '1', '2', '3', '4', '5', '6',
@@ -106,35 +105,41 @@ public static TypeToken<CloudNetwork> cloudnet()
106105
};
107106
}
108107

108+
public static Class<? extends SocketChannel> socketChannel()
109+
{
110+
return EPOLL ? EpollSocketChannel.class : KQueue.isAvailable() ? KQueueSocketChannel.class : NioSocketChannel.class;
111+
}
112+
109113
public static Class<? extends ServerSocketChannel> serverSocketChannel()
110114
{
111-
return EPOLL ? EpollServerSocketChannel.class : NioServerSocketChannel.class;
115+
return EPOLL ? EpollServerSocketChannel.class : KQueue.isAvailable() ? KQueueServerSocketChannel.class : NioServerSocketChannel.class;
112116
}
113117

114118
public static EventLoopGroup eventLoopGroup()
115119
{
116-
return EPOLL ? new EpollEventLoopGroup() : new NioEventLoopGroup();
120+
return eventLoopGroup(Runtime.getRuntime().availableProcessors());
117121
}
118122

119123
public static EventLoopGroup eventLoopGroup(int threads)
120124
{
121-
return EPOLL ? new EpollEventLoopGroup(threads) : new NioEventLoopGroup(threads);
125+
return EPOLL ? new EpollEventLoopGroup(threads) : KQueue.isAvailable() ? new KQueueEventLoopGroup(threads) : new NioEventLoopGroup(threads);
122126
}
123127

124128
public static EventLoopGroup eventLoopGroup(ThreadFactory threadFactory)
125129
{
126-
return EPOLL ? new EpollEventLoopGroup(0, threadFactory) : new NioEventLoopGroup(0, threadFactory);
130+
return eventLoopGroup(0, threadFactory);
127131
}
128132

129133
public static EventLoopGroup eventLoopGroup(int threads, ThreadFactory threadFactory)
130134
{
131-
return EPOLL ? new EpollEventLoopGroup(threads, threadFactory) : new NioEventLoopGroup(threads, threadFactory);
135+
return EPOLL ? new EpollEventLoopGroup(threads, threadFactory) : KQueue.isAvailable() ? new KQueueEventLoopGroup(threads, threadFactory) : new NioEventLoopGroup(threads, threadFactory);
132136
}
133137

134138
public static <T> void addAll(Collection<T> key, Collection<T> value)
135139
{
136-
for (T k : value)
137-
key.add(k);
140+
if (key == null || value == null) return;
141+
142+
key.addAll(value);
138143
}
139144

140145
public static <T, V> void addAll(java.util.Map<T, V> key, java.util.Map<T, V> value)

cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/network/NetworkConnection.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ public boolean tryConnect(boolean ssl, SimpleChannelInboundHandler<Packet> defau
7070
if (ssl) sslContext = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
7171

7272
Bootstrap bootstrap = new Bootstrap()
73-
//.option(ChannelOption.SO_KEEPALIVE, true)
74-
//.option(ChannelOption.TCP_NODELAY, true)
75-
//.option(ChannelOption.IP_TOS, 24)
7673
.option(ChannelOption.AUTO_READ, true)
7774
.group(eventLoopGroup)
7875
.handler(new ChannelInitializer<Channel>() {

0 commit comments

Comments
 (0)