Skip to content

Commit

Permalink
#9900 accurate implementation of Request.getBeginNanoTime() for FCGI
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <[email protected]>
  • Loading branch information
lorban committed Aug 29, 2023
1 parent 7b13687 commit 4757333
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.ByteBuffer;

import org.eclipse.jetty.fcgi.FCGI;
import org.eclipse.jetty.util.NanoTime;

/**
* <p>Parser for the BEGIN_REQUEST frame content.</p>
Expand All @@ -34,13 +35,19 @@ public class BeginRequestContentParser extends ContentParser
private int cursor;
private int role;
private int flags;
private long beginNanoTime;

public BeginRequestContentParser(HeaderParser headerParser, ServerParser.Listener listener)
{
super(headerParser);
this.listener = listener;
}

public long getBeginNanoTime()
{
return beginNanoTime;
}

@Override
public Result parse(ByteBuffer buffer)
{
Expand All @@ -50,6 +57,7 @@ public Result parse(ByteBuffer buffer)
{
case ROLE:
{
beginNanoTime = NanoTime.now();
if (buffer.remaining() >= 2)
{
role = buffer.getShort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public ServerParser(Listener listener)
contentParsers.put(FCGI.FrameType.STDIN, new StreamContentParser(headerParser, FCGI.StreamType.STD_IN, listener));
}

public long getBeginNanoTime()
{
BeginRequestContentParser contentParser = (BeginRequestContentParser)contentParsers.get(FCGI.FrameType.BEGIN_REQUEST);
return contentParser.getBeginNanoTime();
}

@Override
protected ContentParser findContentParser(FCGI.FrameType frameType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.jetty.server.HttpStream;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.NanoTime;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.thread.Invocable;
Expand Down Expand Up @@ -106,7 +105,8 @@ public void onHeaders()
{
String pathQuery = URIUtil.addPathQuery(_path, _query);
HttpScheme scheme = StringUtil.isEmpty(_secure) ? HttpScheme.HTTP : HttpScheme.HTTPS;
MetaData.Request request = new MetaData.Request(NanoTime.now(), _method, scheme.asString(), hostPort, pathQuery, HttpVersion.fromString(_version), _headers, -1); // TODO #9900 make beginNanoTime accurate
ServerFCGIConnection serverFCGIConnection = (ServerFCGIConnection)getHttpChannel().getConnectionMetaData().getConnection();
MetaData.Request request = new MetaData.Request(serverFCGIConnection.getBeginNanoTime(), _method, scheme.asString(), hostPort, pathQuery, HttpVersion.fromString(_version), _headers, -1); // TODO #9900 make beginNanoTime accurate
Runnable task = _httpChannel.onRequest(request);
_allHeaders.forEach(field -> _httpChannel.getRequest().setAttribute(field.getName(), field.getValue()));
// TODO: here we just execute the task.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public ServerFCGIConnection(Connector connector, EndPoint endPoint, HttpConfigur
this.id = StringUtil.randomAlphaNumeric(16);
}

public long getBeginNanoTime()
{
return parser.getBeginNanoTime();
}

Flusher getFlusher()
{
return flusher;
Expand Down

0 comments on commit 4757333

Please sign in to comment.