Add atomic close tracking. Closes #370.
This commit is contained in:
parent
9be44d51a6
commit
2c225a05e7
@ -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()
|
||||
|
@ -114,7 +114,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
@Deprecated
|
||||
public boolean isActive()
|
||||
{
|
||||
return ch.getHandle().isActive();
|
||||
return !ch.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user