Redesign pooling mechanic (#565)
Introduce PoolReturner, a handle on an agent and a PoolKey that is capable of returning a Stream to a Pool. Make Streams keep track of their own PoolReturner, instead of having PoolReturnRead keep track of that information. For the LimitedRead code path, get rid of PoolReturnRead. Instead, LimitedRead is responsible for returning its Stream to the Pool after its second-to-last read. In other words, LimitedRead will return the stream if the next read is guaranteed to return Ok(0). Constructing a LimitedRead of size 0 is always wrong, because we could always just return the stream immediately. Change the size argument to NonZeroUsize to enforce that. Remove the Done trait, which was only used for LimitedRead. It was used to try and make sure we returned the stream to the pool on exact reads, but was not reliable. This does not yet move the ChunkDecoder code path away from PoolReturnRead. That requires a little more work. Part 1 of #559. Fixes #555.
This commit is contained in:
committed by
GitHub
parent
d8225b22ed
commit
9083d692f8
@@ -1,4 +1,5 @@
|
||||
use crate::error::Error;
|
||||
use crate::pool::PoolReturner;
|
||||
use crate::stream::{remote_addr_for_test, ReadOnlyStream, Stream};
|
||||
use crate::unit::Unit;
|
||||
use crate::ReadWrite;
|
||||
@@ -55,6 +56,7 @@ pub(crate) fn make_response(
|
||||
Ok(Stream::new(
|
||||
ReadOnlyStream::new(buf),
|
||||
remote_addr_for_test(),
|
||||
PoolReturner::none(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -103,6 +105,7 @@ impl Recorder {
|
||||
Stream::new(
|
||||
TestStream::new(cursor, self.clone()),
|
||||
remote_addr_for_test(),
|
||||
PoolReturner::none(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user