Buffer short responses (2) (#531)
* Response: build reader at construction time * Remove unwrapping/rewrapping DeadlineStream * Let into_reader() provide Sync + 'static * Prebuffer Vec use known capacity Co-authored-by: Martin Algesten <martin@algesten.se>
This commit is contained in:
committed by
GitHub
parent
9908c446d6
commit
f14fc45179
@@ -50,7 +50,7 @@ impl<T: ReadWrite + ?Sized> ReadWrite for Box<T> {
|
||||
// after the provided deadline, and sets timeouts on the underlying
|
||||
// TcpStream to ensure read() doesn't block beyond the deadline.
|
||||
// When the From trait is used to turn a DeadlineStream back into a
|
||||
// Stream (by PoolReturningRead), the timeouts are removed.
|
||||
// Stream (by PoolReturnRead), the timeouts are removed.
|
||||
pub(crate) struct DeadlineStream {
|
||||
stream: Stream,
|
||||
deadline: Option<Instant>,
|
||||
@@ -60,6 +60,10 @@ impl DeadlineStream {
|
||||
pub(crate) fn new(stream: Stream, deadline: Option<Instant>) -> Self {
|
||||
DeadlineStream { stream, deadline }
|
||||
}
|
||||
|
||||
pub(crate) fn inner_ref(&self) -> &Stream {
|
||||
&self.stream
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DeadlineStream> for Stream {
|
||||
@@ -184,6 +188,10 @@ impl Stream {
|
||||
stream
|
||||
}
|
||||
|
||||
pub(crate) fn buffer(&self) -> &[u8] {
|
||||
self.inner.buffer()
|
||||
}
|
||||
|
||||
fn from_tcp_stream(t: TcpStream) -> Stream {
|
||||
Stream::logged_create(Stream {
|
||||
inner: BufReader::new(Box::new(t)),
|
||||
|
||||
Reference in New Issue
Block a user