base_scheduler/socket_stream_reading.rs
1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::{BufferPool, BufferPooling, SocketOperation, SocketStreamReader};
5use std::io;
6
7/// Construct sequential stream input bound to this scheduler. Backends can substitute their own static reader while keeping protocol code independent of registration and receive mechanisms.
8///
9/// The returned handle may borrow the scheduler, but never the temporary socket
10/// reference. It retains backend access independently, so the socket and handle
11/// can move together. Retire and drop handles before exclusively closing the socket.
12pub trait SocketStreamReading: SocketOperation + BufferPooling {
13 /// Retain the socket and reusable backend state without submitting a receive or allocating a payload pool. Owned reads initialize default storage lazily.
14 fn socket_stream_reader<'scheduler>(
15 &'scheduler self,
16 socket: &Self::Socket,
17 ) -> io::Result<
18 impl SocketStreamReader<Buffer = <Self::Pool as BufferPool>::Buffer>
19 + 'scheduler
20 + use<'scheduler, Self>,
21 >
22 where
23 Self::Socket: 'static;
24
25 /// Construct a reader using the supplied pool for owned chunks. Borrowed reads do not acquire pool storage. Returned chunks retain their pool independently of the reader.
26 fn socket_stream_reader_with_pool<'scheduler>(
27 &'scheduler self,
28 socket: &Self::Socket,
29 pool: Self::Pool,
30 ) -> io::Result<
31 impl SocketStreamReader<Buffer = <Self::Pool as BufferPool>::Buffer>
32 + 'scheduler
33 + use<'scheduler, Self>,
34 >
35 where
36 Self::Socket: 'static;
37}