#9900: cleanup h2c nanotime code

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2023-11-21 15:36:54 +01:00
parent 0ebea03577
commit b270724ff5
2 changed files with 16 additions and 17 deletions

View File

@ -54,8 +54,8 @@ public class Parser
private int maxSettingsKeys = SettingsFrame.DEFAULT_MAX_KEYS;
private boolean continuation;
private State state = State.HEADER;
private long beginNanoTime = Long.MIN_VALUE;
private boolean nanoTimeRead = true;
private long beginNanoTime;
private boolean nanoTimeStored;
public Parser(ByteBufferPool bufferPool, int maxHeaderSize)
{
@ -66,11 +66,7 @@ public class Parser
{
this.bufferPool = bufferPool;
this.headerParser = new HeaderParser(rateControl == null ? RateControl.NO_RATE_CONTROL : rateControl);
this.hpackDecoder = new HpackDecoder(maxHeaderSize, () ->
{
nanoTimeRead = true;
return beginNanoTime;
});
this.hpackDecoder = new HpackDecoder(maxHeaderSize, this::loadAndClearBeginNanoTime);
this.bodyParsers = new BodyParser[FrameType.values().length];
}
@ -108,18 +104,22 @@ public class Parser
{
headerParser.reset();
state = State.HEADER;
beginNanoTime = Long.MIN_VALUE;
nanoTimeRead = true;
nanoTimeStored = false;
}
protected void takeNanoTime()
private long loadAndClearBeginNanoTime()
{
if (nanoTimeRead)
long beginNanoTime = this.beginNanoTime;
nanoTimeStored = false;
return beginNanoTime;
}
private void storeBeginNanoTime()
{
if (!nanoTimeStored)
{
beginNanoTime = NanoTime.now(); // TODO #9900 check beginNanoTime's accuracy
if (beginNanoTime == Long.MIN_VALUE)
beginNanoTime++;
nanoTimeRead = false;
beginNanoTime = NanoTime.now();
nanoTimeStored = true;
}
}
@ -138,9 +138,9 @@ public class Parser
{
try
{
takeNanoTime();
while (true)
{
storeBeginNanoTime();
switch (state)
{
case HEADER:

View File

@ -86,7 +86,6 @@ public class ServerParser extends Parser
{
if (LOG.isDebugEnabled())
LOG.debug("Parsing {}", buffer);
takeNanoTime();
while (true)
{
switch (state)