Skip to main content

Backend

Trait Backend 

Source
pub unsafe trait Backend: Sized + 'static {
    type Wake: Wake;
    type Detached: Send + 'static;

    const FILESYSTEM: Filesystem = _;
Show 36 methods // Required methods fn new(config: &Config, pool: BufferPool) -> Result<Self, Error>; fn now(&self) -> Instant; fn waker(&self) -> Arc<Self::Wake> ⓘ; fn open(&mut self, handle: Handle, spec: Open) -> Result<(), Error>; fn local_addr(&self, handle: Handle) -> Result<SocketAddr, Error>; fn submit(&mut self, request: Request) -> Result<(), Error>; fn cancel(&mut self, op: OpId) -> Result<(), Error>; fn has_work(&self) -> bool; fn poll( &mut self, timeout: Option<Duration>, budget: Budget, events: &mut Vec<Event<Self::Detached>>, ) -> Result<PollInfo, Error>; fn release(&mut self, handle: Handle); fn detach(&mut self, handle: Handle) -> Result<Self::Detached, Error>; fn attach( &mut self, handle: Handle, transport: Self::Detached, ) -> Result<(), Error>; fn integration(&mut self) -> Result<Integration, Error>; // Provided methods fn open_bound_tcp( &mut self, _handle: Handle, _transport: Self::Detached, _peer: SocketAddr, _opts: TcpOpts, ) -> Result<(), Error> { ... } fn fs( &mut self, _op: OpId, _handle: Option<Handle>, _request: FsRequest, ) -> Result<(), Error> { ... } fn fs_watch( &mut self, _handle: Handle, _path: &FsPath, _options: WatchOptions, ) -> Result<(), Error> { ... } fn set_notifier(&mut self, _notifier: Notifier) { ... } fn spawn( &mut self, _handle: Handle, _pipes: [Option<Handle>; 3], _extra: &[Option<Handle>], _spec: &ProcessSpec, ) -> Result<u32, Error> { ... } fn prepare_close(&mut self, _handle: Handle) -> Result<(), Error> { ... } fn kill( &mut self, _handle: Handle, _signal: Signal, _group: bool, ) -> Result<(), Error> { ... } fn signal(&mut self, _handle: Handle, _signal: Signal) -> Result<(), Error> { ... } fn tty_set_mode( &mut self, _handle: Handle, _mode: TtyMode, ) -> Result<(), Error> { ... } fn set_option( &mut self, _handle: Handle, _option: SocketOption, ) -> Result<(), Error> { ... } fn shutdown_receive(&mut self, _handle: Handle) -> Result<(), Error> { ... } fn get_option( &self, _handle: Handle, _kind: SocketOptionKind, ) -> Result<SocketOption, Error> { ... } fn set_keepalive_parameters( &mut self, _handle: Handle, _value: KeepAlive, ) -> Result<(), Error> { ... } fn keepalive_parameters(&self, _handle: Handle) -> Result<KeepAlive, Error> { ... } fn set_listen_backlog( &mut self, _handle: Handle, _backlog: u32, ) -> Result<(), Error> { ... } fn shutdown_read(&mut self, _handle: Handle) -> Result<(), Error> { ... } fn raw_transport(&self, _handle: Handle) -> Result<RawTransport, Error> { ... } fn tty_window_size(&self, _handle: Handle) -> Result<WindowSize, Error> { ... } fn validate_timeout(&self, _timeout: Timeout) -> Result<(), Error> { ... } fn deadline_changed(&mut self, _deadline: Option<Instant>) { ... } fn resolve(&mut self, _op: OpId, _request: &DnsRequest) -> Result<(), Error> { ... } fn attach_tcp_connect( &mut self, _handle: Handle, _transport: Self::Detached, _destination: SocketAddr, ) -> Result<(), Error> { ... } fn attach_tcp_connect_unbound( &mut self, _handle: Handle, _transport: Self::Detached, _destination: SocketAddr, ) -> Result<(), Error> { ... }
}
Expand description

§Safety

Implementers must uphold the buffer-lifetime and native-quiescence guarantees above: no native I/O may access a buffer after its terminal Event or Drop. Core lifetime and handle-release safety relies on those guarantees.

Provided Associated Constants§

Source

const FILESYSTEM: Filesystem = _

Where typed filesystem requests run for this backend.

Required Associated Types§

Source

type Wake: Wake

Thread-safe native wake endpoint type.

Source

type Detached: Send + 'static

Owning transferable representation of an unregistered resource.

Required Methods§

Source

fn new(config: &Config, pool: BufferPool) -> Result<Self, Error>

Construct backend storage and native wait resources with the supplied shared read pool.

Source

fn now(&self) -> Instant

Monotonic, nondecreasing time in a consistent domain across calls. Native adapters return std::time::Instant::now(). Web adapters construct crate::Instant::from_duration from their monotonic host clock. This method must not schedule work, block, or invoke a user callback.

Source

fn waker(&self) -> Arc<Self::Wake> ⓘ

Clone the lifetime-safe native wake endpoint for this backend.

Source

fn open(&mut self, handle: Handle, spec: Open) -> Result<(), Error>

Bind a new resource to the supplied handle, retaining nothing on error.

Source

fn local_addr(&self, handle: Handle) -> Result<SocketAddr, Error>

Return the local IP endpoint of a bound socket.

Source

fn submit(&mut self, request: Request) -> Result<(), Error>

Accept one operation or reject it before retaining native buffer access.

Source

fn cancel(&mut self, op: OpId) -> Result<(), Error>

Request cancellation; terminal acknowledgement must precede memory reuse.

Source

fn has_work(&self) -> bool

Whether completions or immediately runnable cached operations are available.

Source

fn poll( &mut self, timeout: Option<Duration>, budget: Budget, events: &mut Vec<Event<Self::Detached>>, ) -> Result<PollInfo, Error>

Append bounded completions, performing at most one OS wait with the supplied exact timeout, and delivering no more multishot connections than budget allows.

Source

fn release(&mut self, handle: Handle)

Release a quiescent resource after Closed was appended to host output.

Source

fn detach(&mut self, handle: Handle) -> Result<Self::Detached, Error>

Unregister a quiescent resource and return its owning transferable representation.

Source

fn attach( &mut self, handle: Handle, transport: Self::Detached, ) -> Result<(), Error>

Register an owning transport on this loop; failure drops the rejected transport.

Source

fn integration(&mut self) -> Result<Integration, Error>

Opt into external host waiting and return the borrowed integration primitive.

Provided Methods§

Source

fn open_bound_tcp( &mut self, _handle: Handle, _transport: Self::Detached, _peer: SocketAddr, _opts: TcpOpts, ) -> Result<(), Error>

Adopt an exclusively owned, bound but unconnected TCP transport and configure its peer before a Connect request. Preserve the local binding and existing socket options; apply nodelay when requested. On error, retain no resource or native registration. Backends without native transport adoption return Unsupported.

Source

fn fs( &mut self, _op: OpId, _handle: Option<Handle>, _request: FsRequest, ) -> Result<(), Error>

Accept a typed filesystem request (only with Filesystem::Backend). handle is the request’s file handle, or the new handle for an open.

Source

fn fs_watch( &mut self, _handle: Handle, _path: &FsPath, _options: WatchOptions, ) -> Result<(), Error>

Bind a native filesystem watch to a new handle, retaining nothing on error.

Source

fn set_notifier(&mut self, _notifier: Notifier)

Give process-wide services this loop’s parking-aware notification endpoint.

Source

fn spawn( &mut self, _handle: Handle, _pipes: [Option<Handle>; 3], _extra: &[Option<Handle>], _spec: &ProcessSpec, ) -> Result<u32, Error>

Spawn and bind the child and requested parent pipe handles atomically. Failure must release all supplied handles and reap any created child.

extra is parallel to spec.extra: a handle is supplied for every entry whose source has a parent end, and None for the rest. The core has already checked descriptor numbers and duplicates.

Source

fn prepare_close(&mut self, _handle: Handle) -> Result<(), Error>

Begin nonblocking resource teardown before the core cancels its operations. Process backends terminate the owned child/tree here and defer its terminal acknowledgement until exit/reaping, so release never blocks a normal turn. Other resources need no action. An error leaves the core handle open.

Source

fn kill( &mut self, _handle: Handle, _signal: Signal, _group: bool, ) -> Result<(), Error>

Signal an owned child, or its explicitly isolated process group.

Source

fn signal(&mut self, _handle: Handle, _signal: Signal) -> Result<(), Error>

Bind a process-wide signal subscription to a new core handle.

Source

fn tty_set_mode(&mut self, _handle: Handle, _mode: TtyMode) -> Result<(), Error>

Set a terminal mode, retaining the original settings until release/drop.

Source

fn set_option( &mut self, _handle: Handle, _option: SocketOption, ) -> Result<(), Error>

Apply one socket option to a live resource, synchronously, through the OS. No Request is accepted and no Event is produced. A platform without an equivalent returns Unsupported; silently ignoring an option is forbidden, because a host cannot tell an ignored option from an applied one.

Source

fn shutdown_receive(&mut self, _handle: Handle) -> Result<(), Error>

Synchronously request native receive-side shutdown without closing the send direction. Existing accepted requests retain their normal buffer ownership and terminal acknowledgement requirements. Unsupported transports must fail without changing either direction.

Source

fn get_option( &self, _handle: Handle, _kind: SocketOptionKind, ) -> Result<SocketOption, Error>

Read one socket option from the OS. Backends never answer from a cache of what was set: the kernel may round, clamp or double a request, and the caller is entitled to the value the kernel actually holds.

Source

fn set_keepalive_parameters( &mut self, _handle: Handle, _value: KeepAlive, ) -> Result<(), Error>

Set TCP keep-alive timing without changing SO_KEEPALIVE.

Source

fn keepalive_parameters(&self, _handle: Handle) -> Result<KeepAlive, Error>

Query TCP keep-alive timing even while SO_KEEPALIVE is disabled.

Source

fn set_listen_backlog( &mut self, _handle: Handle, _backlog: u32, ) -> Result<(), Error>

Change an already-listening TCP socket’s backlog.

Source

fn shutdown_read(&mut self, _handle: Handle) -> Result<(), Error>

Shut down receive after read operations have been acknowledged. Pending writes remain valid. A pending receive returns WouldBlock.

Source

fn raw_transport(&self, _handle: Handle) -> Result<RawTransport, Error>

Report the native identity of a live transport, for the host only.

The core never acts on the value and never stores it: it reads it out of the backend’s own table and returns it, so a host can implement Node’s socket._handle.fd. Backends return Unsupported for a resource with no descriptor identity of its own (timers, processes, signals, watches, and every WASI/web resource). See Driver::raw_transport for the host rules.

Source

fn tty_window_size(&self, _handle: Handle) -> Result<WindowSize, Error>

Query current terminal dimensions.

Source

fn validate_timeout(&self, _timeout: Timeout) -> Result<(), Error>

Validate the original request even when queued completions eliminate the effective wait. Browser main-thread adapters reject every timeout but Now; a worker adapter may support blocking. Native adapters use this default.

Source

fn deadline_changed(&mut self, _deadline: Option<Instant>)

The core owns timer semantics. Callback-driven adapters arm one host timer for this earliest deadline, whose callback schedules a turn. None disarms it. Native pollers need no action: poll receives the effective timeout. This is a scheduling import, never a user callback. If host scheduling fails, preserve the failure and return it from poll; never fake expiry.

Source

fn resolve(&mut self, _op: OpId, _request: &DnsRequest) -> Result<(), Error>

Start a handle-free host name lookup. The default uses no resources and lets the core fall back to its native blocking pool. Accepted requests obey the same terminal/cancellation and no-spin rules as socket I/O.

Source

fn attach_tcp_connect( &mut self, _handle: Handle, _transport: Self::Detached, _destination: SocketAddr, ) -> Result<(), Error>

Adopt an explicitly bound TCP socket and install its connection destination. No connection is initiated here; the subsequent Connect request owns it. Reject non-TCP, already connected, unbound, or mismatched-family sockets. On failure retain nothing and drop the rejected transport.

Source

fn attach_tcp_connect_unbound( &mut self, _handle: Handle, _transport: Self::Detached, _destination: SocketAddr, ) -> Result<(), Error>

Adopt an unbound TCP socket and install its connection destination. Unix must not bind before Connect; Windows binds inside adoption for ConnectEx. Reject bound/non-TCP/mismatched-family transports and retain nothing on failure. Subsequent Connect owns completion and cancellation.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§