33
33
import io .netty .channel .socket .SocketChannel ;
34
34
import io .netty .channel .socket .nio .NioServerSocketChannel ;
35
35
import io .netty .channel .socket .nio .NioSocketChannel ;
36
+ import io .netty .incubator .channel .uring .IOUringEventLoopGroup ;
37
+ import io .netty .incubator .channel .uring .IOUringServerSocketChannel ;
38
+ import io .netty .incubator .channel .uring .IOUringSocketChannel ;
36
39
37
40
/**
38
41
* Utils for netty EventLoop
43
46
public class NettyEventLoopUtil {
44
47
45
48
/** check whether epoll enabled, and it would not be changed during runtime. */
46
- private static boolean epollEnabled = ConfigManager .netty_epoll () && Epoll .isAvailable ();
49
+ private static final boolean epollEnabled = ConfigManager .netty_epoll ()
50
+ && Epoll .isAvailable ();
51
+
52
+ private static final boolean ioUringEnabled = ConfigManager .netty_io_uring ();
47
53
48
54
/**
49
55
* Create the right event loop according to current platform and system property, fallback to NIO when epoll not enabled.
@@ -53,22 +59,25 @@ public class NettyEventLoopUtil {
53
59
* @return an EventLoopGroup suitable for the current platform
54
60
*/
55
61
public static EventLoopGroup newEventLoopGroup (int nThreads , ThreadFactory threadFactory ) {
56
- return epollEnabled ? new EpollEventLoopGroup (nThreads , threadFactory )
57
- : new NioEventLoopGroup (nThreads , threadFactory );
62
+ return ioUringEnabled ? new IOUringEventLoopGroup (nThreads , threadFactory )
63
+ : epollEnabled ? new EpollEventLoopGroup (nThreads , threadFactory )
64
+ : new NioEventLoopGroup (nThreads , threadFactory );
58
65
}
59
66
60
67
/**
61
68
* @return a SocketChannel class suitable for the given EventLoopGroup implementation
62
69
*/
63
70
public static Class <? extends SocketChannel > getClientSocketChannelClass () {
64
- return epollEnabled ? EpollSocketChannel .class : NioSocketChannel .class ;
71
+ return ioUringEnabled ? IOUringSocketChannel .class
72
+ : epollEnabled ? EpollSocketChannel .class : NioSocketChannel .class ;
65
73
}
66
74
67
75
/**
68
76
* @return a ServerSocketChannel class suitable for the given EventLoopGroup implementation
69
77
*/
70
78
public static Class <? extends ServerSocketChannel > getServerSocketChannelClass () {
71
- return epollEnabled ? EpollServerSocketChannel .class : NioServerSocketChannel .class ;
79
+ return ioUringEnabled ? IOUringServerSocketChannel .class
80
+ : epollEnabled ? EpollServerSocketChannel .class : NioServerSocketChannel .class ;
72
81
}
73
82
74
83
/**
@@ -77,7 +86,7 @@ public static Class<? extends ServerSocketChannel> getServerSocketChannelClass()
77
86
* @param serverBootstrap server bootstrap
78
87
*/
79
88
public static void enableTriggeredMode (ServerBootstrap serverBootstrap ) {
80
- if (epollEnabled ) {
89
+ if (! ioUringEnabled && epollEnabled ) {
81
90
if (ConfigManager .netty_epoll_lt_enabled ()) {
82
91
serverBootstrap .childOption (EpollChannelOption .EPOLL_MODE ,
83
92
EpollMode .LEVEL_TRIGGERED );
0 commit comments