Skip to main content

http_type/stream/
struct.rs

1use super::*;
2
3#[derive(CustomDebug, Data, DisplayDebug, New)]
4pub struct Stream {
5    #[get_mut(pub(super))]
6    #[set(pub(super))]
7    pub(super) stream: TcpStream,
8    #[get_mut(pub(super))]
9    #[set(pub(super))]
10    pub(super) request_config: RequestConfig,
11    #[get(type(copy))]
12    #[get_mut(pub(super))]
13    pub(super) closed: bool,
14}
15
16/// A buffered reader over a `TcpStream` with a reusable read buffer.
17///
18/// This reader batches socket reads into an internal buffer to reduce
19/// syscall count, and returns its buffer to a thread-local pool on drop
20/// so keep-alive requests avoid repeated buffer allocation.
21#[derive(Data, New)]
22pub(crate) struct PooledReader<'a> {
23    /// The underlying TCP stream being read.
24    #[get(pub(crate))]
25    #[get_mut(pub(crate))]
26    #[set(pub(crate))]
27    pub(super) stream: &'a mut TcpStream,
28    /// The reusable read buffer holding unconsumed bytes in `start..end`.
29    #[get(pub(crate))]
30    #[get_mut(pub(crate))]
31    #[set(pub(crate))]
32    pub(super) buffer: Vec<u8>,
33    /// The index of the first unconsumed byte in the buffer.
34    #[get(pub(crate))]
35    #[get_mut(pub(crate))]
36    #[set(pub(crate))]
37    #[new(skip)]
38    pub(super) start: usize,
39    /// The index one past the last valid byte in the buffer.
40    #[get(pub(crate))]
41    #[get_mut(pub(crate))]
42    #[set(pub(crate))]
43    #[new(skip)]
44    pub(super) end: usize,
45}