Ensure that the read buffer can contain a single full packet

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-04 03:40:22 +02:00
parent 4f382c5684
commit 22b0c70500

View File

@ -40,7 +40,7 @@ public final class Worker extends Thread {
final SocketChannel channel = (SocketChannel) key.channel(); final SocketChannel channel = (SocketChannel) key.channel();
if (!channel.isOpen()) return; if (!channel.isOpen()) return;
if (!key.isReadable()) return; if (!key.isReadable()) return;
var connection = connectionMap.get(channel); PlayerSocketConnection connection = connectionMap.get(channel);
try { try {
var readBuffer = context.readBuffer; var readBuffer = context.readBuffer;
// Consume last incomplete packet // Consume last incomplete packet
@ -92,7 +92,7 @@ public final class Worker extends Thread {
* Contains objects that we can be shared across all the connection of a {@link Worker worker}. * Contains objects that we can be shared across all the connection of a {@link Worker worker}.
*/ */
public static final class Context { public static final class Context {
public final BinaryBuffer readBuffer = BinaryBuffer.ofSize(Server.SOCKET_BUFFER_SIZE); public final BinaryBuffer readBuffer = BinaryBuffer.ofSize(Server.MAX_PACKET_SIZE);
public final BinaryBuffer contentBuffer = BinaryBuffer.ofSize(Server.MAX_PACKET_SIZE); public final BinaryBuffer contentBuffer = BinaryBuffer.ofSize(Server.MAX_PACKET_SIZE);
public final Inflater inflater = new Inflater(); public final Inflater inflater = new Inflater();