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.
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 SocketPacketReading: 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_packet_reader<'scheduler>(
15 &'scheduler self,
16 socket: &Self::Socket,
17 ) -> io::Result<
18 impl SocketPacketReader<
19 Message: SocketRecvMessageMut<Payload = <Self::Pool as BufferPool>::Buffer>,
20 >
21 + 'scheduler
22 + use<'scheduler, Self>,
23 >
24 where
25 Self: Sized,
26 Self::Socket: 'static;
27
28 /// Construct a reader using the supplied pool for owned messages. Borrowed reads do not acquire pool storage; completed messages retain their pool independently.
29 fn socket_packet_reader_with_pool<'scheduler>(
30 &'scheduler self,
31 socket: &Self::Socket,
32 pool: Self::Pool,
33 ) -> io::Result<
34 impl SocketPacketReader<
35 Message: SocketRecvMessageMut<Payload = <Self::Pool as BufferPool>::Buffer>,
36 >
37 + 'scheduler
38 + use<'scheduler, Self>,
39 >
40 where
41 Self: Sized,
42 Self::Socket: 'static;
43}