Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve HttpOutput.print() #12530

Open
wants to merge 2 commits into
base: jetty-12.1.x
Choose a base branch
from

Conversation

lorban
Copy link
Contributor

@lorban lorban commented Nov 13, 2024

Prototype / WIP.

This PR improves HttpOutput.print() by simplifying it, avoiding copies when needed and fixing a too early buffer release.

@lorban lorban self-assigned this Nov 13, 2024
}
finally
{
out.release();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the above write() call is async, out.release() may be called before the write is done.

_encoder.offer(encoder);
}
byte[] bytes = s.getBytes(charset);
IORunnable r = eoln ? () -> write("\r\n".getBytes(StandardCharsets.UTF_8)) : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ASCII for \r\n.

The write of this IORunnable could remain pending, so you cannot notify callback until this write is complete.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better yet, use IO.CRLF_BYTES

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and call the variable onComplete

@@ -799,8 +809,27 @@ public void write(byte[] b, int off, int len) throws IOException

if (async)
{
IORunnable copy = onComplete;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is copy the right name? It confused me. How about just doOnComplete or runOnComplete?

@@ -820,6 +849,10 @@ public void write(byte[] b, int off, int len) throws IOException
if (len > 0 && !last && len <= _commitSize && len <= maximizeAggregateSpace())
{
BufferUtil.append(byteBuffer, b, off, len);
IORunnable copy = onComplete;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

_encoder.offer(encoder);
}
byte[] bytes = s.getBytes(charset);
IORunnable r = eoln ? () -> write("\r\n".getBytes(StandardCharsets.UTF_8)) : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better yet, use IO.CRLF_BYTES

_encoder.offer(encoder);
}
byte[] bytes = s.getBytes(charset);
IORunnable r = eoln ? () -> write("\r\n".getBytes(StandardCharsets.UTF_8)) : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and call the variable onComplete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants