pub struct Driver<T> { /* private fields */ }tokio only.Expand description
Pumps a session over a transport.
One step flushes everything the session wants to send, then waits for whichever
comes first: an inbound frame, the session’s next deadline, or the keep-alive
interval. The application keeps the loop, and with it the freedom to do anything else
between steps.
Implementations§
Source§impl<T: TextTransport> Driver<T>
impl<T: TextTransport> Driver<T>
Sourcepub fn with_span(self, span: Span) -> Self
Available on crate feature tracing only.
pub fn with_span(self, span: Span) -> Self
tracing only.Record this session’s log lines in span instead of the default s2.session.
The way to put a resource id, a peer address or a tenant on every line:
let driver = Driver::new(socket).with_span(tracing::info_span!(
"s2.session",
resource = %resource_id,
state = tracing::field::Empty,
version = tracing::field::Empty,
));Declare state and version as empty fields to have the driver fill them in;
tracing ignores a record of a field the span did not declare.
Sourcepub fn with_clock(self, now: fn() -> Timestamp) -> Self
pub fn with_clock(self, now: fn() -> Timestamp) -> Self
Use a different clock — a virtual one, in a test.
Sourcepub fn with_idle_limit(self, limit: Option<Duration>) -> Self
pub fn with_idle_limit(self, limit: Option<Duration>) -> Self
Treat the transport as closed after this long without a frame from the peer, or
never (None). Defaults to IDLE_LIMIT; keep it a few ping intervals long.
Sourcepub fn with_ping_interval(self, interval: Duration) -> Self
pub fn with_ping_interval(self, interval: Duration) -> Self
Send pings at a different interval. S2 Connect allows up to sixty seconds.
Sourcepub fn transport_mut(&mut self) -> &mut T
pub fn transport_mut(&mut self) -> &mut T
The transport, for a caller that wants to close it itself.
Sourcepub async fn step<S: Session>(&mut self, session: &mut S) -> Result<(), Error>
pub async fn step<S: Session>(&mut self, session: &mut S) -> Result<(), Error>
Run one step of a session, whichever role it is.
Flush, wait for the first of {a frame, the session’s deadline, the keep-alive interval}, feed the result back in, flush again. Everything that decides anything is in the session; this function decides only what to wait on.
Sourcepub async fn run<S, F>(
&mut self,
session: &mut S,
on_event: F,
) -> Result<(), Error>
pub async fn run<S, F>( &mut self, session: &mut S, on_event: F, ) -> Result<(), Error>
Run a session to completion: steps until it closes.
The application still sees every event, through the callback, but no longer owns
the loop. For anything that wants to do other work between steps, use
Self::step.