-
Notifications
You must be signed in to change notification settings - Fork 123
Buffer channelRead
s in ResponseStreamState
until the next channelReadComplete
#388
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
case waitingForRead(CircularBuffer<ByteBuffer>) | ||
/// The state machines expects a call to `demandMoreResponseBodyParts`. The buffer is empty. It is | ||
/// preserved for performance reasons. | ||
case waitingForDemand(CircularBuffer<ByteBuffer>) |
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.
By making this a mini-state-machine, I recommend going the whole way: pull this out to a file and give it a bunch of methods that correspond to the events that can occur to it (e.g. func read
). Then, the bigger state machine can just call those.
d76029f
to
96fbbbd
Compare
channelRead
s in the HTTPRequestStateMachine until the next channelReadComplete
channelRead
s in ResponseStreamState
until the next channelReadComplete
private var state: State | ||
|
||
init(expectingBody: Bool) { | ||
self.state = .waitingForBytes(CircularBuffer(initialCapacity: expectingBody ? 16 : 0)) |
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.
Given that there is no such thing as an empty circular buffer (initialCapacity: 0
still allocates) we may as well skip the branch and just always set 16
.
mutating func end() -> CircularBuffer<ByteBuffer> { | ||
switch self.state { | ||
case .waitingForBytes(let buffer): | ||
// This should never happen. But we don't want to precondition this behavior. Let's just |
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.
This comment is wrong.
expectingBody = true | ||
} | ||
} else if head.headers.contains(name: "transfer-encoding") { | ||
expectingBody = true |
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.
We can delete this code per my above comment.
2c49141
to
a4fba69
Compare
Motivation
After a lengthy offline discussion @Lukasa, we concluded that it would be best, if the
HTTPRequestStateMachine
would buffer up all reads until the nextchannelReadComplete
. The main reason is, we minimize potential cross thread communication, by passing collected byteBuffers onward.Modifications
ConsumerControlState
was replaced withResponseStreamState
channelRead
s are buffered up to achannelReadComplete
.channelReadComplete
all buffered body parts are forwarded to the consumer