Skip to main content

Connection

Struct Connection 

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

A running connection.

Dropping it asks the thread to stop after its current wait.

Implementations§

Source§

impl Connection

Source

pub fn open( stream_url: &str, token: Option<String>, trust: &Trust, wake: impl Fn() + Send + 'static, ) -> Self

Opens the stream and keeps it open, reconnecting for as long as the connection lives.

token is optional, but a server with security on and allowReadonly off will open this stream, greet the client, and then send it nothing – see crate::access. Passing None is therefore a choice to be made knowingly, not a default to fall back on.

trust decides which server may answer a wss:// URL. It is asked for on every connection rather than defaulted, because the failure it prevents is silent: a client that trusted anything would reconnect happily to whatever took the boat’s address and hand it the token.

wake is called from this connection’s own thread once something is worth draining – see the module doc. A consumer with nothing better to do than poll on a fixed timer may pass || {} and get exactly today’s behaviour; passing the real thing is what lets the timer go away.

Source

pub fn publish(&self, delta_json: String) -> Result<(), ClientError>

Queues delta_json to be sent on the wire, as-is – building a well-formed delta is the caller’s own job (see [signalk::notification::mob_delta] for the one this exists for today). One-way: an ordinary delta carries no reply for this to wait on, unlike crate::resources::Client’s own writes.

§Errors

If the background thread this would be sent from is already gone – the connection was dropped, or never opened.

Source

pub fn drain(&self) -> impl Iterator<Item = Event> + '_

Whatever has arrived, without waiting.

Drained on the consumer’s own schedule rather than handed over message by message: the consumer decides when it is ready to draw, which is what keeps a burst of deltas from turning into a burst of redraws. wake (see the module doc) is what tells it when that schedule should run sooner than usual; this is still the only way the events themselves are read.

Marked not-pending before the drain, not after: a message arriving during this call must still cause a future wake, and clearing first means the worst case is one redundant wake, never a missed one.

Trait Implementations§

Source§

impl Debug for Connection

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Connection

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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, 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.