mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-30 14:13:47 +01:00
Solve long standing issue of creating too many TCP packets. This fix works very effectively.
This commit is contained in:
parent
632fa8bd94
commit
5c4ea3c7a0
@ -181,7 +181,7 @@ public class BungeeCord extends ProxyServer
|
|||||||
public static void main(String[] args) throws Exception
|
public static void main(String[] args) throws Exception
|
||||||
{
|
{
|
||||||
Calendar deadline = Calendar.getInstance();
|
Calendar deadline = Calendar.getInstance();
|
||||||
deadline.set( 2013, 7, 1 ); // year, month, date
|
deadline.set( 2013, 7, 16 ); // year, month, date
|
||||||
if ( Calendar.getInstance().after( deadline ) )
|
if ( Calendar.getInstance().after( deadline ) )
|
||||||
{
|
{
|
||||||
System.err.println( "*** Warning, this build is outdated ***" );
|
System.err.println( "*** Warning, this build is outdated ***" );
|
||||||
|
@ -2,6 +2,7 @@ package net.md_5.bungee.netty;
|
|||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.MessageList;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
public class ChannelWrapper
|
public class ChannelWrapper
|
||||||
@ -10,17 +11,35 @@ public class ChannelWrapper
|
|||||||
private final Channel ch;
|
private final Channel ch;
|
||||||
@Getter
|
@Getter
|
||||||
private volatile boolean closed;
|
private volatile boolean closed;
|
||||||
|
private final MessageList<Object> queue = MessageList.newInstance();
|
||||||
|
private volatile boolean flushNow = true;
|
||||||
|
|
||||||
public ChannelWrapper(ChannelHandlerContext ctx)
|
public ChannelWrapper(ChannelHandlerContext ctx)
|
||||||
{
|
{
|
||||||
this.ch = ctx.channel();
|
this.ch = ctx.channel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void flushNow(boolean flush)
|
||||||
|
{
|
||||||
|
if ( !flushNow && flush )
|
||||||
|
{
|
||||||
|
ch.write( queue.copy() );
|
||||||
|
queue.clear();
|
||||||
|
}
|
||||||
|
this.flushNow = flush;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void write(Object packet)
|
public synchronized void write(Object packet)
|
||||||
{
|
{
|
||||||
if ( !closed )
|
if ( !closed )
|
||||||
{
|
{
|
||||||
ch.write( packet );
|
if ( flushNow )
|
||||||
|
{
|
||||||
|
ch.write( packet );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
queue.add( packet );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +48,7 @@ public class ChannelWrapper
|
|||||||
if ( !closed )
|
if ( !closed )
|
||||||
{
|
{
|
||||||
closed = true;
|
closed = true;
|
||||||
|
ch.write( queue );
|
||||||
ch.close();
|
ch.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
|||||||
@Override
|
@Override
|
||||||
public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> msgs) throws Exception
|
public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> msgs) throws Exception
|
||||||
{
|
{
|
||||||
|
channel.flushNow( false );
|
||||||
for ( Object msg : msgs )
|
for ( Object msg : msgs )
|
||||||
{
|
{
|
||||||
if ( handler != null && ctx.channel().isActive() )
|
if ( handler != null && ctx.channel().isActive() )
|
||||||
@ -85,6 +86,7 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
channel.flushNow( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user