pub struct Accepted {
pub accept: String,
/* private fields */
}Expand description
An accepted connection, before the socket is handed over.
Fields§
§accept: StringThe value to answer Sec-WebSocket-Accept with.
Implementations§
Source§impl Accepted
impl Accepted
Sourcepub fn serve(self, socket: Box<dyn Write + Send>)
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.
Sourcepub fn serve_until(
self,
socket: Box<dyn Write + Send>,
hung_up: impl Fn() -> bool,
)
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§
impl Freeze for Accepted
impl RefUnwindSafe for Accepted
impl Send for Accepted
impl Sync for Accepted
impl Unpin for Accepted
impl UnsafeUnpin for Accepted
impl UnwindSafe for Accepted
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more