From de6bbe5f82ea8ff460fc18b902607f0df91c3d92 Mon Sep 17 00:00:00 2001 From: Alex <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Tue, 17 Sep 2024 03:44:28 +0200 Subject: [PATCH] Allow accessing backing class for a channel instead of only its factory (#859) Some netty libraries that are poorly coded only accept classes. Example: https://github.com/CloudburstMC/Network/pull/42 --- .../network/helper/TransportHelper.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/network/helper/TransportHelper.java b/protocol/src/main/java/org/geysermc/mcprotocollib/network/helper/TransportHelper.java index 698110ad6..7e5268373 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/network/helper/TransportHelper.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/network/helper/TransportHelper.java @@ -34,8 +34,11 @@ public enum TransportMethod { } public record TransportType(TransportMethod method, + Class serverSocketChannelClass, ChannelFactory serverSocketChannelFactory, + Class socketChannelClass, ChannelFactory socketChannelFactory, + Class datagramChannelClass, ChannelFactory datagramChannelFactory, Function eventLoopGroupFactory, boolean supportsTcpFastOpenServer, @@ -46,8 +49,11 @@ public static TransportType determineTransportMethod() { if (isClassAvailable("io.netty.incubator.channel.uring.IOUring") && IOUring.isAvailable()) { return new TransportType( TransportMethod.IO_URING, + IOUringServerSocketChannel.class, IOUringServerSocketChannel::new, + IOUringSocketChannel.class, IOUringSocketChannel::new, + IOUringDatagramChannel.class, IOUringDatagramChannel::new, factory -> new IOUringEventLoopGroup(0, factory), IOUring.isTcpFastOpenServerSideAvailable(), @@ -58,8 +64,11 @@ public static TransportType determineTransportMethod() { if (isClassAvailable("io.netty.channel.epoll.Epoll") && Epoll.isAvailable()) { return new TransportType( TransportMethod.EPOLL, + EpollServerSocketChannel.class, EpollServerSocketChannel::new, + EpollSocketChannel.class, EpollSocketChannel::new, + EpollDatagramChannel.class, EpollDatagramChannel::new, factory -> new EpollEventLoopGroup(0, factory), Epoll.isTcpFastOpenServerSideAvailable(), @@ -70,8 +79,11 @@ public static TransportType determineTransportMethod() { if (isClassAvailable("io.netty.channel.kqueue.KQueue") && KQueue.isAvailable()) { return new TransportType( TransportMethod.KQUEUE, + KQueueServerSocketChannel.class, KQueueServerSocketChannel::new, + KQueueSocketChannel.class, KQueueSocketChannel::new, + KQueueDatagramChannel.class, KQueueDatagramChannel::new, factory -> new KQueueEventLoopGroup(0, factory), KQueue.isTcpFastOpenServerSideAvailable(), @@ -81,8 +93,11 @@ public static TransportType determineTransportMethod() { return new TransportType( TransportMethod.NIO, + NioServerSocketChannel.class, NioServerSocketChannel::new, + NioSocketChannel.class, NioSocketChannel::new, + NioDatagramChannel.class, NioDatagramChannel::new, factory -> new NioEventLoopGroup(0, factory), false,