Add atomic close tracking. Closes #370.

This commit is contained in:
md_5 2013-05-22 09:23:35 +10:00
parent 9be44d51a6
commit 2c225a05e7
4 changed files with 20 additions and 5 deletions

View File

@ -31,7 +31,7 @@ public class ServerConnection implements Server
@Override
public synchronized void disconnect(String reason)
{
if ( ch.getHandle().isActive() )
if ( !ch.isClosed() )
{
ch.write( new PacketFFKick( reason ) );
ch.getHandle().eventLoop().schedule( new Runnable()

View File

@ -114,7 +114,7 @@ public final class UserConnection implements ProxiedPlayer
@Deprecated
public boolean isActive()
{
return ch.getHandle().isActive();
return !ch.isClosed();
}
@Override

View File

@ -262,10 +262,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override
public synchronized void disconnect(String reason)
{
if ( ch.getHandle().isActive() )
if ( !ch.isClosed() )
{
ch.write( new PacketFFKick( reason ) );
ch.getHandle().close();
ch.close();
disconnected = true;
}
}

View File

@ -1,11 +1,14 @@
package net.md_5.bungee.netty;
import io.netty.channel.Channel;
import lombok.Getter;
public class ChannelWrapper
{
private final Channel ch;
@Getter
private volatile boolean closed;
public ChannelWrapper(Channel ch)
{
@ -13,9 +16,21 @@ public class ChannelWrapper
}
public void write(Object packet)
{
if ( !closed )
{
ch.write( packet, ch.voidPromise() );
}
}
public void close()
{
if ( !closed )
{
closed = true;
ch.close();
}
}
public Channel getHandle()
{