Skip to main content

Socket

Struct Socket 

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

A connection to a Unix socket, from cx.socket(path). It connects at once, passes each line it reads to on_line, and writes what write is given. A clone is cheap and shares the connection.

It closes when the context that opened it goes. When the other end closes it, connected turns false and it stays closed until reconnect: nothing retries on its own, so a socket that isn’t there never wakes the shell.

Implementations§

Source§

impl Socket

Source

pub fn connected(&self) -> ReadSignal<bool>

Whether it is connected: true from a connect that worked until the other end closes it, it breaks, or close.

Source

pub fn on_line(self, on_line: impl Fn(&str) + 'static) -> Socket

Calls on_line with each line read, without its \n, decoded as UTF-8 with bad bytes replaced. What is left when the other end closes counts as a last line. A line over 1 MiB is dropped and logged.

It runs on the main thread. If it panics, that is logged with the socket’s path and where on_line was called, and it isn’t called again; the socket stays open.

Source

pub fn write(&self, data: impl AsRef<[u8]>)

Sends data, all of it, as the other end takes it. While not connected it is dropped, and that is logged. If more than 4 MiB wait because the other end reads nothing, the socket is closed.

Source

pub fn reconnect(&self)

Closes it and connects again, as after the other end restarted. Lines the old connection read and on_line hasn’t had yet are dropped.

Source

pub fn close(&self)

Closes it. reconnect opens it again. Lines read and not yet passed on are dropped.

Trait Implementations§

Source§

impl Clone for Socket

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§

§

impl !RefUnwindSafe for Socket

§

impl !Send for Socket

§

impl !Sync for Socket

§

impl !UnwindSafe for Socket

§

impl Forget for Socket

§

impl Freeze for Socket

§

impl Move for Socket

§

impl Unpin for Socket

§

impl UnsafeUnpin for Socket

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