-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Rework FeedableBodyGerator #949
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
Conversation
I think there's a bug in int capacity = buffer.remaining() - 10; // be safe (we'll have to add size, ending, etc.)
int size = Math.min(nextPart.buffer.remaining(), capacity); WDYT? |
At the moment the whole thing relies on the outgoing buffer being big enough to hold the boundaries and at least one byte. The "closing" part has the same problem. |
e2bae09
to
4bf4fb5
Compare
I rewrote parts of it. What do you think? |
queue.remove(); | ||
} else { | ||
readBodyPart(buffer, nextPart); | ||
reads++; |
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.
Looks wrong to me: read
must return the number of bytes read, while this seems to be returning the number of parts read (and still assuming buffer is large enough).
I've added some comments. |
private final static class BodyPart { | ||
|
||
private void move(ByteBuffer destination, ByteBuffer source) { | ||
while(destination.hasRemaining() && source.hasRemaining()) { |
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.
Why not put a whole slice?
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.
Done in af0df14
It doesn't have to return the exact amount of bytes. A positive number is enough. The amount is represented in the ByteBuffer. |
The code also does not assume the outgoing buffer is large enough. It stops writing as soon as it is full and continues with the next buffer at the exact same position. That's why i initialize the buffers in the BodyPart. Also the loop is fine. The copy method from one buffer to another does exactly the same except it checks the destination buffer is large enough (not what i want). |
- don't depend on outgoing buffer size - fill the outgoing buffer with all available data the read method became really big.
Oh, right. Then, as AHC2 is still in alpha, I think we should change |
Ultimately, yes (ping @jroper). |
Sounds good to me. |
Merging, I'll take care of some clean up. Thanks! |
the read method became really big.