polyoxide-ws
The WebSocket kit the polyoxide socket clients share, one copy of each block they would otherwise each carry:
ensure_crypto_providerinstalls the process-default rustls provider atokio-tungsteniteconnect needs.Backoffis the reconnect delay schedule, andTimingholds a supervised connection's ping, staleness, backoff, connect and rotation timings, withtiming_setters!for a builder andnext_waitfor the wait until the next deadline.connectopens a connection within a timeout (DEFAULT_CONNECT_TIMEOUT, 10 s),connect_overupgrades a TCP connection the caller opened itself,with_timeoutbounds a connect of the caller's own, andretrying_can_fixsays whether a reconnect can help after one failed, by a status rule the caller passes in.- The transport seam decides how a connection is dialled:
SocketTransportis the dial,BoxSocketthe connection it returns, andCapabilitiessays what the transport's sockets can do (send pings, see the server's pings, carry handshake headers).TungsteniteTransportis the native dial anddefault_socket_transportthe target's choice.transport_setters!gives a builder itsruntimeandsocket_transportsetters,Connection::with_runtimeand theSupervisor'sruntimeandsocket_transportsetters put a connection's and a supervisor's clocks, timers and spawns on the injected runtime and its dial on the injected transport, and a transport that cannot do what a caller asks fails asKind::Unsupported. Connectionis the bare tier: one connection as aStreamof its frames, inMode::Data(text and binary) orMode::All(every frame). It answers the server's close with the RFC 6455 reply, says how the server closed, and correlates requests with their answers through a caller's builder and matcher (Correlated), with optional pacing and an answer timeout.Supervisorruns one supervised connection for a venue'sProtocol: pings on the wall clock, even while the consumer's queue is full, staleness, reconnect with backoff and a replay of the membership, rotation, outage markers, and membership changes through aMembershipHandle, all as oneSupervisedstream. A venue keeps only what is its own: its frames, its ping, what counts as liveness, how it recovers and whether it announces an outage.WsErroris the one socket error, read through itsKind.polyoxide_venue::impl_ws_classification!classifies it in the venue crate that wraps it.tungsteniteis re-exported, so a venue namesMessageandCloseFramethrough this crate.
The test-server feature adds a doc-hidden scripted local server and the
helpers the offline suites share. It is for tests, not consumers.
It depends on neither polyoxide-core nor polyoxide-venue, and builds no
HTTP or signing stack, so a credential-free feed built on it stays light. It
logs under the polyoxide_ws target and never installs a subscriber.
On wasm32 the kit builds no TLS or TCP stack. WebSocketTransport, the browser's
WebSocket, is the default socket transport there; connect_over,
ensure_crypto_provider, the scripted test server and TungsteniteTransport are built for
native targets only, and the test-server feature turns on nothing.
More information about this crate can be found in the crate documentation.
Installation
[]
= "0.47"
Usage
A request on the bare tier, then the frames that follow it:
use Duration;
use StreamExt;
use ;
# async
A supervised builder takes the shared timings, and its reconnect loop waits out the schedule they describe:
use Duration;
use Timing;
let timing = default
.backoff
.timing;
let mut backoff = timing.backoff;
let waits: = .map.collect;
assert_eq!;
// A connection that delivered something starts the schedule over.
backoff.after_connection_ended;
assert_eq!;