Skip to content

Commit

Permalink
#9900: cleanup h2c nanotime code
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <[email protected]>
  • Loading branch information
lorban committed Nov 21, 2023
1 parent b419fa3 commit 1ab1120
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -66,11 +66,7 @@ public Parser(ByteBufferPool bufferPool, int maxHeaderSize, RateControl rateCont
{
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];
}

Expand Down Expand Up @@ -108,18 +104,22 @@ private void reset()
{
headerParser.reset();
state = State.HEADER;
beginNanoTime = Long.MIN_VALUE;
nanoTimeRead = true;
nanoTimeStored = false;
}

private long loadAndClearBeginNanoTime()
{
long beginNanoTime = this.beginNanoTime;
nanoTimeStored = false;
return beginNanoTime;
}

protected void takeNanoTime()
private void storeBeginNanoTime()
{
if (nanoTimeRead)
if (!nanoTimeStored)
{
beginNanoTime = NanoTime.now(); // TODO #9900 check beginNanoTime's accuracy
if (beginNanoTime == Long.MIN_VALUE)
beginNanoTime++;
nanoTimeRead = false;
beginNanoTime = NanoTime.now();
nanoTimeStored = true;
}
}

Expand All @@ -138,9 +138,9 @@ public void parse(ByteBuffer buffer)
{
try
{
takeNanoTime();
while (true)
{
storeBeginNanoTime();
switch (state)
{
case HEADER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public void parse(ByteBuffer buffer)
{
if (LOG.isDebugEnabled())
LOG.debug("Parsing {}", buffer);
takeNanoTime();
while (true)
{
switch (state)
Expand Down

0 comments on commit 1ab1120

Please sign in to comment.