Skip to main content

base_scheduler/
socket_packet_reading.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::{BufferPool, BufferPooling, SocketOperation, SocketPacketReader, SocketRecvMessageMut};
5use std::io;
6
7/// Construct sequential packet input bound to this scheduler. Backends choose the static reader and completed message representation without exposing their receive mechanism.
8pub trait SocketPacketReading: SocketOperation + BufferPooling {
9    /// Retain the socket and reusable backend state without submitting a receive or allocating a payload pool. Owned reads initialize default storage lazily.
10    fn socket_packet_reader<'scheduler>(
11        &'scheduler self,
12        socket: &Self::Socket,
13    ) -> io::Result<
14        impl SocketPacketReader<
15            Message: SocketRecvMessageMut<Payload = <Self::Pool as BufferPool>::Buffer>,
16        > + 'scheduler,
17    >
18    where
19        Self: Sized,
20        Self::Socket: 'static;
21
22    /// Construct a reader using the supplied pool for owned messages. Borrowed reads do not acquire pool storage; completed messages retain their pool independently.
23    fn socket_packet_reader_with_pool<'scheduler>(
24        &'scheduler self,
25        socket: &Self::Socket,
26        pool: Self::Pool,
27    ) -> io::Result<
28        impl SocketPacketReader<
29            Message: SocketRecvMessageMut<Payload = <Self::Pool as BufferPool>::Buffer>,
30        > + 'scheduler,
31    >
32    where
33        Self: Sized,
34        Self::Socket: 'static;
35}