Make sure packets are written before closing

This commit is contained in:
md_5 2013-07-07 13:08:25 +10:00
parent 55c2bcd634
commit 475571986c
2 changed files with 11 additions and 2 deletions

View File

@ -42,6 +42,7 @@ public class ServerConnection implements Server
{
if ( !ch.isClosed() )
{
// TODO: Can we just use a future here?
unsafe().sendPacket( new PacketFFKick( reason ) );
ch.getHandle().eventLoop().schedule( new Runnable()
{

View File

@ -2,6 +2,8 @@ package net.md_5.bungee.netty;
import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.MessageList;
@ -50,9 +52,15 @@ public class ChannelWrapper
if ( !closed )
{
closed = true;
ch.write( queue );
ch.write( queue, ch.newPromise() ).addListener( new ChannelFutureListener()
{
@Override
public void operationComplete(ChannelFuture future) throws Exception
{
ch.close();
}
} );
}
}
public void addBefore(String baseName, String name, ChannelHandler handler)