Improve socket shutdown

This commit is contained in:
TheMode 2021-08-04 05:15:40 +02:00
parent 557d34c378
commit 8895e49a52
3 changed files with 3 additions and 3 deletions

View File

@ -65,6 +65,7 @@ public class Server {
public void stop() { public void stop() {
this.stop = true; this.stop = true;
this.workers.forEach(worker -> worker.selector.wakeup());
} }
public String getAddress() { public String getAddress() {

View File

@ -19,7 +19,7 @@ import java.util.zip.Inflater;
public class Worker { public class Worker {
private final Map<SocketChannel, NettyPlayerConnection> connectionMap = new ConcurrentHashMap<>(); private final Map<SocketChannel, NettyPlayerConnection> connectionMap = new ConcurrentHashMap<>();
private final Selector selector = Selector.open(); protected final Selector selector = Selector.open();
private final PacketProcessor packetProcessor; private final PacketProcessor packetProcessor;
public Worker(Server server, PacketProcessor packetProcessor) throws IOException { public Worker(Server server, PacketProcessor packetProcessor) throws IOException {

View File

@ -101,8 +101,7 @@ public final class PacketUtils {
continue; continue;
final PlayerConnection playerConnection = player.getPlayerConnection(); final PlayerConnection playerConnection = player.getPlayerConnection();
if (playerConnection instanceof NettyPlayerConnection) { if (playerConnection instanceof NettyPlayerConnection) {
final NettyPlayerConnection nettyPlayerConnection = (NettyPlayerConnection) playerConnection; ((NettyPlayerConnection) playerConnection).write(framedPacket);
nettyPlayerConnection.write(framedPacket);
} else { } else {
playerConnection.sendPacket(packet); playerConnection.sendPacket(packet);
} }