Skip to main content

Module singleton_bind

Module singleton_bind 

Source
Expand description

Reusable per-user-session singleton bind for a v2 local-socket listener.

Extracted from running-process-broker-v2’s main() (soldr#2361 Phase 2 prep) so any consumer that wants to run v2 broker-server logic — the scaffold binary in this crate, or soldr’s own embedded broker role — shares one tested implementation of “bind a name exactly once per user session, refuse a second bind instead of racing it” rather than each reimplementing the bind/singleton/stale-socket-cleanup dance.

The stale-socket-cleanup subtlety here is load-bearing: see bind_singleton’s docs and running-process#899 for the concurrency bug this module’s shape specifically avoids.

Enums§

BindSingletonError
Why bind_singleton refused to bind.

Functions§

bind_singleton
Bind socket_path as a v2 local-socket listener, enforcing exactly-one-bind-per-name (the per-user-session singleton property).
bind_singleton_with
Bind a caller-owned listener with the same singleton and serialized stale recovery contract as bind_singleton.
is_already_bound_error
Classify a Listener::bind error as “another process is already bound at this name” vs any other bind failure.
resolve_path_scoped_socket_path
Resolve an install-path-scoped broker name without adding user identity.
resolve_socket_path
Resolve the bare pipe/socket name into a full, platform-specific bind path: \\.\pipe\<bare_name> on Windows, or a file under a per-user runtime directory on Unix (macOS additionally hashes the leaf to fit sun_path’s 104-byte limit).
unix_socket_path_is_stale
Source-compatible stale-endpoint helper for filesystem-backed transports. Tells a genuinely orphaned socket path (left behind by a process that exited without cleaning up) apart from a path where a live peer is listening right now — the two look identical to bind (AddrInUse either way). A connect probe distinguishes them: nothing is listening if the connect itself fails to even reach a peer (ConnectionRefused — the classic “orphaned socket file, no listener” signal — or NotFound); any other outcome, including a successful connect, means treat the path as live and leave it alone. Non-filesystem transports return false because they leave no endpoint file to retire.
wrap_socket_name
Build an interprocess Name from a resolved socket path (see resolve_socket_path).