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() ) if ( !ch.isClosed() )
{ {
// TODO: Can we just use a future here?
unsafe().sendPacket( new PacketFFKick( reason ) ); unsafe().sendPacket( new PacketFFKick( reason ) );
ch.getHandle().eventLoop().schedule( new Runnable() 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 com.google.common.base.Preconditions;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.MessageList; import io.netty.channel.MessageList;
@ -50,8 +52,14 @@ public class ChannelWrapper
if ( !closed ) if ( !closed )
{ {
closed = true; closed = true;
ch.write( queue ); ch.write( queue, ch.newPromise() ).addListener( new ChannelFutureListener()
ch.close(); {
@Override
public void operationComplete(ChannelFuture future) throws Exception
{
ch.close();
}
} );
} }
} }