-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
base: jetty-12.1.x
Are you sure you want to change the base?
Improve HttpOutput.print()
#12530
Conversation
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
} | ||
finally | ||
{ | ||
out.release(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
…tty-12.1.x/faster-HttpOutput-print
Prototype / WIP.
This PR improves
HttpOutput.print()
by simplifying it, avoiding copies when needed and fixing a too early buffer release.