Fix by checking if the connection uses inet socket (#1152)

This commit is contained in:
Noel Németh 2022-06-05 14:53:28 +02:00 committed by GitHub
parent 2289cf32e1
commit b112248ae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -107,6 +107,7 @@ public class Main {
OpenToLAN.open(new OpenToLANConfig().eventCallDelay(Duration.of(1, TimeUnit.DAY)));
minecraftServer.start("0.0.0.0", 25565);
// minecraftServer.start(java.net.UnixDomainSocketAddress.of("minestom-demo.sock"));
//Runtime.getRuntime().addShutdownHook(new Thread(MinecraftServer::stopCleanly));
}
}

View File

@ -10,6 +10,7 @@ import org.jctools.queues.MpscUnboundedXaddArrayQueue;
import org.jetbrains.annotations.ApiStatus;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
@ -109,11 +110,13 @@ public final class Worker extends MinestomThread {
this.connectionMap.put(channel, new PlayerSocketConnection(this, channel, channel.getRemoteAddress()));
channel.configureBlocking(false);
channel.register(selector, SelectionKey.OP_READ);
Socket socket = channel.socket();
socket.setSendBufferSize(Server.SOCKET_SEND_BUFFER_SIZE);
socket.setReceiveBufferSize(Server.SOCKET_RECEIVE_BUFFER_SIZE);
socket.setTcpNoDelay(Server.NO_DELAY);
socket.setSoTimeout(30 * 1000); // 30 seconds
if (channel.getLocalAddress() instanceof InetSocketAddress) {
Socket socket = channel.socket();
socket.setSendBufferSize(Server.SOCKET_SEND_BUFFER_SIZE);
socket.setReceiveBufferSize(Server.SOCKET_RECEIVE_BUFFER_SIZE);
socket.setTcpNoDelay(Server.NO_DELAY);
socket.setSoTimeout(30 * 1000); // 30 seconds
}
this.selector.wakeup();
}