Issue #3951 - Consider adding demand API to HTTP/2.

Using MathUtils.cappedAdd().

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2019-09-06 10:15:49 +02:00
parent e24ec133e7
commit c59fc08e5a
1 changed files with 2 additions and 13 deletions

View File

@ -44,6 +44,7 @@ import org.eclipse.jetty.http2.frames.ResetFrame;
import org.eclipse.jetty.http2.frames.WindowUpdateFrame;
import org.eclipse.jetty.io.IdleTimeout;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.MathUtils;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.log.Log;
@ -372,7 +373,7 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback, Dumpa
boolean proceed = false;
synchronized (this)
{
dataDemand = addDemand(dataDemand, n);
dataDemand = MathUtils.cappedAdd(dataDemand, n);
if (!dataProcess)
dataProcess = proceed = !dataQueue.isEmpty();
if (LOG.isDebugEnabled())
@ -414,18 +415,6 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback, Dumpa
}
}
private static long addDemand(long x, long y)
{
try
{
return Math.addExact(x, y);
}
catch (ArithmeticException e)
{
return Long.MAX_VALUE;
}
}
private void onReset(ResetFrame frame, Callback callback)
{
remoteReset = true;