3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Add support for server-side backpressure

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-12-27 18:05:27 -05:00
Ursprung 7329d165f6
Commit 2a1e83902d
3 geänderte Dateien mit 13 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -195,6 +195,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
public void write(Object msg) { public void write(Object msg) {
if (channel.isActive()) { if (channel.isActive()) {
channel.writeAndFlush(msg, channel.voidPromise()); channel.writeAndFlush(msg, channel.voidPromise());
} else {
ReferenceCountUtil.release(msg);
} }
} }
@ -205,6 +207,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
public void delayedWrite(Object msg) { public void delayedWrite(Object msg) {
if (channel.isActive()) { if (channel.isActive()) {
channel.write(msg, channel.voidPromise()); channel.write(msg, channel.voidPromise());
} else {
ReferenceCountUtil.release(msg);
} }
} }

Datei anzeigen

@ -28,6 +28,7 @@ import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil; import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.handler.timeout.ReadTimeoutException; import io.netty.handler.timeout.ReadTimeoutException;
import java.util.Collection; import java.util.Collection;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -284,4 +285,11 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
} }
} }
} }
@Override
public void writabilityChanged() {
Channel serverChan = serverConn.ensureConnected().getChannel();
boolean writable = serverChan.isWritable();
playerConnection.setAutoReading(writable);
}
} }

Datei anzeigen

@ -300,7 +300,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
boolean writable = player.getConnection().getChannel().isWritable(); boolean writable = player.getConnection().getChannel().isWritable();
if (!writable) { if (!writable) {
// We might have packets queued for the server, so flush them now to free up memory. // We might have packets queued from the server, so flush them now to free up memory.
player.getConnection().flush(); player.getConnection().flush();
} }