slight fill interest cleanup

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2021-03-16 11:49:33 +01:00 committed by Simone Bordet
parent 9d0b7f71ac
commit 03fd0d5fef
2 changed files with 20 additions and 30 deletions

View File

@ -35,12 +35,14 @@ public class QuicStreamEndPoint extends IdleTimeout implements EndPoint
{ {
private static final Logger LOG = LoggerFactory.getLogger(QuicStreamEndPoint.class); private static final Logger LOG = LoggerFactory.getLogger(QuicStreamEndPoint.class);
private final AtomicBoolean fillable = new AtomicBoolean();
private final FillInterest fillInterest = new FillInterest() private final FillInterest fillInterest = new FillInterest()
{ {
@Override @Override
protected void needsFillInterest() throws IOException protected void needsFillInterest() throws IOException
{ {
if (fillable.getAndSet(false))
fillInterest.fillable();
} }
}; };
private final long streamId; private final long streamId;
@ -139,14 +141,12 @@ public class QuicStreamEndPoint extends IdleTimeout implements EndPoint
return quicheConnection; return quicheConnection;
} }
//TODO: this is racy
private final AtomicBoolean fillable = new AtomicBoolean();
public Runnable onSelected(InetSocketAddress remoteAddress, boolean readable, boolean writable) public Runnable onSelected(InetSocketAddress remoteAddress, boolean readable, boolean writable)
{ {
this.remoteAddress = remoteAddress; this.remoteAddress = remoteAddress;
return () -> return () ->
{ {
//TODO: this is racy
if (!fillInterest.fillable()) if (!fillInterest.fillable())
fillable.set(true); fillable.set(true);
}; };
@ -156,17 +156,12 @@ public class QuicStreamEndPoint extends IdleTimeout implements EndPoint
public void fillInterested(Callback callback) throws ReadPendingException public void fillInterested(Callback callback) throws ReadPendingException
{ {
fillInterest.register(callback); fillInterest.register(callback);
if (fillable.getAndSet(false))
fillInterest.fillable();
} }
@Override @Override
public boolean tryFillInterested(Callback callback) public boolean tryFillInterested(Callback callback)
{ {
boolean registered = fillInterest.tryRegister(callback); return fillInterest.tryRegister(callback);
if (registered && fillable.getAndSet(false))
fillInterest.fillable();
return registered;
} }
@Override @Override

View File

@ -40,12 +40,14 @@ public class ServerDatagramEndPoint extends IdleTimeout implements EndPoint, Man
{ {
private static final Logger LOG = LoggerFactory.getLogger(ServerDatagramEndPoint.class); private static final Logger LOG = LoggerFactory.getLogger(ServerDatagramEndPoint.class);
private final AtomicBoolean fillable = new AtomicBoolean();
private final FillInterest fillInterest = new FillInterest() private final FillInterest fillInterest = new FillInterest()
{ {
@Override @Override
protected void needsFillInterest() throws IOException protected void needsFillInterest() throws IOException
{ {
if (fillable.getAndSet(false))
fillInterest.fillable();
} }
}; };
private final DatagramChannel channel; private final DatagramChannel channel;
@ -166,19 +168,6 @@ public class ServerDatagramEndPoint extends IdleTimeout implements EndPoint, Man
LOG.info("idle timeout", timeout); LOG.info("idle timeout", timeout);
} }
//TODO: this is racy
private final AtomicBoolean fillable = new AtomicBoolean();
@Override
public Runnable onSelected()
{
return () ->
{
if (!fillInterest.fillable())
fillable.set(true);
};
}
@Override @Override
public void updateKey() public void updateKey()
{ {
@ -191,21 +180,27 @@ public class ServerDatagramEndPoint extends IdleTimeout implements EndPoint, Man
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public Runnable onSelected()
{
return () ->
{
//TODO: this is racy
if (!fillInterest.fillable())
fillable.set(true);
};
}
@Override @Override
public void fillInterested(Callback callback) throws ReadPendingException public void fillInterested(Callback callback) throws ReadPendingException
{ {
fillInterest.register(callback); fillInterest.register(callback);
if (fillable.getAndSet(false))
fillInterest.fillable();
} }
@Override @Override
public boolean tryFillInterested(Callback callback) public boolean tryFillInterested(Callback callback)
{ {
boolean registered = fillInterest.tryRegister(callback); return fillInterest.tryRegister(callback);
if (registered && fillable.getAndSet(false))
fillInterest.fillable();
return registered;
} }
@Override @Override