#9900: cleanup h2c nanotime code
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
parent
0ebea03577
commit
b270724ff5
|
@ -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:
|
||||
|
|
|
@ -86,7 +86,6 @@ public class ServerParser extends Parser
|
|||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Parsing {}", buffer);
|
||||
takeNanoTime();
|
||||
while (true)
|
||||
{
|
||||
switch (state)
|
||||
|
|
Loading…
Reference in New Issue