Skip to main content

Accepted

Struct Accepted 

Source
pub struct Accepted {
    pub accept: String,
    /* private fields */
}
Expand description

An accepted connection, before the socket is handed over.

Fields§

§accept: String

The value to answer Sec-WebSocket-Accept with.

Implementations§

Source§

impl Accepted

Source

pub fn serve(self, socket: Box<dyn Write + Send>)

Serve the connection on an upgraded socket until it ends. Blocking; the caller runs it on a thread of its own.

Source

pub fn serve_until( self, socket: Box<dyn Write + Send>, hung_up: impl Fn() -> bool, )

Accepted::serve, also ending as soon as hung_up says the client has gone: asked every LOOK while the channel is quiet, so a closed channel stops counting as use of the server within a second, not at its next write (I2131).

A client that has already gone ends the channel at the first look, long before the heartbeat would have found out by writing:

use std::sync::Arc;
use std::time::{Duration, Instant};
use majordomus_cli::execution::{ExecutionStore, Limits};
use majordomus_cli::http::events::{accept, PATH};
use majordomus_cli::http::Request;

let store = Arc::new(ExecutionStore::new(Limits::default()));
let req = Request::parse_target("GET", PATH, vec![]).with_headers(vec![
    ("Upgrade".into(), "websocket".into()),
    ("Connection".into(), "Upgrade".into()),
    ("Sec-WebSocket-Key".into(), "dGhlIHNhbXBsZSBub25jZQ==".into()),
    ("Sec-WebSocket-Version".into(), "13".into()),
]);
let accepted = accept(&store, &req, "/api/v1/executions/get").expect("an upgrade");
let started = Instant::now();
accepted.serve_until(Box::new(Vec::new()), || true);
assert!(started.elapsed() < Duration::from_secs(5), "a gone client ends the channel");

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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