mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 16:41:35 +01:00
Do not write empty buffer
This commit is contained in:
parent
1b162c1139
commit
1ceffd8540
@ -71,12 +71,15 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
// Flush
|
// Flush
|
||||||
|
final int bufferSize = tickBuffer.writerIndex();
|
||||||
|
if (bufferSize > 0) {
|
||||||
this.channel.eventLoop().submit(() -> {
|
this.channel.eventLoop().submit(() -> {
|
||||||
if (channel.isActive()) {
|
if (channel.isActive()) {
|
||||||
writeWaitingPackets();
|
writeWaitingPackets();
|
||||||
this.channel.flush();
|
channel.flush();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// Network stats
|
// Network stats
|
||||||
super.update();
|
super.update();
|
||||||
}
|
}
|
||||||
@ -208,6 +211,11 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
private void writeWaitingPackets() {
|
private void writeWaitingPackets() {
|
||||||
synchronized (tickBuffer) {
|
synchronized (tickBuffer) {
|
||||||
final ByteBuf copy = tickBuffer.copy();
|
final ByteBuf copy = tickBuffer.copy();
|
||||||
|
if (copy.writerIndex() == 0) {
|
||||||
|
// Nothing to write
|
||||||
|
copy.release();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ChannelFuture channelFuture = channel.write(new FramedPacket(copy));
|
ChannelFuture channelFuture = channel.write(new FramedPacket(copy));
|
||||||
channelFuture.addListener(future -> copy.release());
|
channelFuture.addListener(future -> copy.release());
|
||||||
|
Loading…
Reference in New Issue
Block a user