Skip to main content

Server

Struct Server 

Source
pub struct Server { /* private fields */ }
Expand description

The listening server.

bind spawns a background thread that owns the control TcpListener and accepts connections for the life of the process; dropping Server does not stop that thread or close the control port — there is currently no shutdown handshake for the control listener itself. Only per-session data listeners are torn down early, and only through Server::reap. This is a deliberate, narrower scope than “dropping it stops accepting” would suggest; widening it is future work, not a claim this code already makes good on.

Implementations§

Source§

impl Server

Source

pub fn bind(port: u16) -> Result<Self>

Binds the control port. Pass 0 to let the OS choose (tests do).

§Errors

Returns the OS error when the address cannot be bound.

Source

pub fn control_port(&self) -> u16

The port clients send HELLO to.

Source

pub fn events(&self) -> &Receiver<ServerEvent>

Events for the UI to drain.

Source

pub fn live_count(&self) -> usize

Number of sessions with a live data socket.

§Panics

If the internal session-map mutex is poisoned.

Source

pub fn reap(&mut self, ttl: Duration)

Drops sessions that have been detached longer than ttl, sending a ServerEvent::Closed for each one on the same channel as every other lifecycle event — the coherent way for a caller draining Server::events to learn what to close, whether it comes from a live connection or from reaping.

Each reaped session’s data-port listener thread is told to stop and its listener is dropped, releasing the port: a session’s TCP port does not outlive the session. Simply dropping a TcpListener while another thread is blocked in accept() does not reliably wake that thread (the behaviour is platform-dependent), so a shutdown flag is set first and then a throwaway self-connect forces one more iteration of the accept loop, which observes the flag and exits.

A connected session, or one that has reconnected since it last detached, never expires: idle_since is None in both cases.

§Panics

If the internal session-map mutex is poisoned.

Source

pub fn close_session(&mut self, id: SessionId)

Tears a session down immediately, regardless of its idle state: used when the UI window is closed by the user rather than by the idle TTL. Reuses reap’s shutdown mechanism (shutdown flag plus a self-connect to wake the blocked accept loop) so the session’s data port and accept thread are actually released, not just forgotten — see defect 2 in .superpowers/sdd/lifecycle-fixes-report.md for why closing a window must tear the server-side session down rather than leaving it live forever with no window to show it.

No event is sent: the caller (the UI) already knows it is closing this session and is not waiting to be told.

§Panics

If the internal session-map mutex is poisoned.

Trait Implementations§

Source§

impl Debug for Server

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more