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 @Override
public synchronized void disconnect(String reason) public synchronized void disconnect(String reason)
{ {
if ( ch.getHandle().isActive() ) if ( !ch.isClosed() )
{ {
ch.write( new PacketFFKick( reason ) ); ch.write( new PacketFFKick( reason ) );
ch.getHandle().eventLoop().schedule( new Runnable() ch.getHandle().eventLoop().schedule( new Runnable()

View File

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

View File

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

View File

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