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
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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.ChannelHandlerContext;
|
||||
import io.netty.channel.MessageList;
|
||||
import lombok.Getter;
|
||||
|
||||
public class ChannelWrapper
|
||||
@ -10,17 +11,35 @@ public class ChannelWrapper
|
||||
private final Channel ch;
|
||||
@Getter
|
||||
private volatile boolean closed;
|
||||
private final MessageList<Object> queue = MessageList.newInstance();
|
||||
private volatile boolean flushNow = true;
|
||||
|
||||
public ChannelWrapper(ChannelHandlerContext ctx)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if ( !closed )
|
||||
{
|
||||
ch.write( packet );
|
||||
if ( flushNow )
|
||||
{
|
||||
ch.write( packet );
|
||||
} else
|
||||
{
|
||||
queue.add( packet );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +48,7 @@ public class ChannelWrapper
|
||||
if ( !closed )
|
||||
{
|
||||
closed = true;
|
||||
ch.write( queue );
|
||||
ch.close();
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> msgs) throws Exception
|
||||
{
|
||||
channel.flushNow( false );
|
||||
for ( Object msg : msgs )
|
||||
{
|
||||
if ( handler != null && ctx.channel().isActive() )
|
||||
@ -85,6 +86,7 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
||||
}
|
||||
}
|
||||
}
|
||||
channel.flushNow( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user