Skip to main content

SocketServer

Struct SocketServer 

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

A server on a Unix socket, from cx.socket_server(path), as Quickshell’s SocketServer. It listens from the start and hands each client that connects to on_connection as a Socket. A clone is cheap and shares the server.

It stops when the context that made it goes, or at close: every connection closes, and the socket file goes if it is still the one the server made. A socket file already at the path is replaced if nothing listens on it. One that something listens on, or anything that isn’t a socket, is left alone and logged, and the server never listens. The file gets the permissions the shell’s umask leaves, so keep it in a directory only the user can reach, such as $XDG_RUNTIME_DIR.

Implementations§

Source§

impl SocketServer

Source

pub fn on_connection( self, on_connection: impl Fn(&Cx, Socket) + 'static, ) -> SocketServer

Calls on_connection with each client that connects: a context of the connection’s own, which goes on the loop’s turn after the connection ends, and the connection as a Socket, connected, for on_line or on_split, write and close. Lines are capped as a Socket’s are. The socket’s connected signal goes with that context too, so code outside it reads it with try_get. A client that connects while nothing handles it is closed at once.

A client that only stops sending, as printf cmd | socat - UNIX-CONNECT:path does, has its last line passed on, and the connection stays open for the reply until the config closes it, a write fails or 5 s pass, as the shell’s own IPC socket waits. One that hangs up while still sending ends the connection at once; one that hangs up after it stopped sending, as socat does once its wait for a reply ends, keeps its place until a write fails or the 5 s pass, so a config that answers should close the connection.

It runs on the main thread. If it panics, that is logged with the server’s path and where on_connection was called, that connection is closed, and it isn’t called again; the server and its other connections go on.

Source

pub fn close(&self)

Stops it, as its context going does: every connection closes, and the socket file goes. Nothing opens it again.

Trait Implementations§

Source§

impl Clone for SocketServer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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