Skip to main content

base_scheduler/
socket_registration.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use super::SocketOperation;
5use std::{
6    io,
7    net::{TcpListener, TcpStream},
8};
9
10/// Optional interoperability with existing standard-library TCP resources. Streams and listeners become the same backend socket descriptor. Register once; the backend sets the nonblocking mode it needs. Do not change that mode through another handle. Simulated schedulers need not implement it.
11pub trait SocketRegistration: SocketOperation {
12    /// Take ownership of a connected standard-library TCP stream and return it as this scheduler's socket.
13    fn register_socket(&self, socket: TcpStream) -> io::Result<Self::Socket>;
14    /// Take ownership of a standard-library TCP listener and return it as this scheduler's socket.
15    fn register_listener(&self, listener: TcpListener) -> io::Result<Self::Socket>;
16}