From 8895e49a527804f007dffdf331d36dce2481ab60 Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 4 Aug 2021 05:15:40 +0200 Subject: [PATCH] Improve socket shutdown --- src/main/java/net/minestom/server/network/socket/Server.java | 1 + src/main/java/net/minestom/server/network/socket/Worker.java | 2 +- src/main/java/net/minestom/server/utils/PacketUtils.java | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/network/socket/Server.java b/src/main/java/net/minestom/server/network/socket/Server.java index 434141a42..ac349040c 100644 --- a/src/main/java/net/minestom/server/network/socket/Server.java +++ b/src/main/java/net/minestom/server/network/socket/Server.java @@ -65,6 +65,7 @@ public class Server { public void stop() { this.stop = true; + this.workers.forEach(worker -> worker.selector.wakeup()); } public String getAddress() { diff --git a/src/main/java/net/minestom/server/network/socket/Worker.java b/src/main/java/net/minestom/server/network/socket/Worker.java index 0846bb96a..b12e51232 100644 --- a/src/main/java/net/minestom/server/network/socket/Worker.java +++ b/src/main/java/net/minestom/server/network/socket/Worker.java @@ -19,7 +19,7 @@ import java.util.zip.Inflater; public class Worker { private final Map connectionMap = new ConcurrentHashMap<>(); - private final Selector selector = Selector.open(); + protected final Selector selector = Selector.open(); private final PacketProcessor packetProcessor; public Worker(Server server, PacketProcessor packetProcessor) throws IOException { diff --git a/src/main/java/net/minestom/server/utils/PacketUtils.java b/src/main/java/net/minestom/server/utils/PacketUtils.java index 339512500..4c0bf3f48 100644 --- a/src/main/java/net/minestom/server/utils/PacketUtils.java +++ b/src/main/java/net/minestom/server/utils/PacketUtils.java @@ -101,8 +101,7 @@ public final class PacketUtils { continue; final PlayerConnection playerConnection = player.getPlayerConnection(); if (playerConnection instanceof NettyPlayerConnection) { - final NettyPlayerConnection nettyPlayerConnection = (NettyPlayerConnection) playerConnection; - nettyPlayerConnection.write(framedPacket); + ((NettyPlayerConnection) playerConnection).write(framedPacket); } else { playerConnection.sendPacket(packet); }