pub struct Session { /* private fields */ }Expand description
Owner of one session and its incoming request queue.
Incoming requests use Message, paired with a common responder. The
application selects the reply type; there is no static request/response pairing
table. The host/server role and envelope direction are handled internally.
Closing or dropping the session fails pending promises, discards queued requests,
and wakes blocked Self::recv calls. Completed promises keep their results.
Application jobs keep running, but their handles still refer to the closed
session and cannot send messages through a replacement session.
A client session also closes its stream. A server session leaves the server’s stream available for another handshake. Handles do not keep the session open. The owner cannot be cloned; obtain requesters or closers for other threads:
use darkbio_wire::protocol::Session;
fn duplicate(session: Session) { let _ = session.clone(); }Implementations§
Source§impl Session
impl Session
Sourcepub fn clock(&self) -> Clock
pub fn clock(&self) -> Clock
Returns the clock of the stream this session runs on, which request and reply deadlines are measured on.
Sourcepub fn set_autoreply_timeout(self, timeout: Duration) -> Self
pub fn set_autoreply_timeout(self, timeout: Duration) -> Self
Sets the timeout for automatic UNANSWERED and UNKNOWN replies.
Defaults to DEFAULT_AUTOREPLY_TIMEOUT. Replies already queued keep
their deadlines.
The budget starts when a responder is dropped or an unknown request is
received, and includes queueing. Expiry discards a queued reply, while a
write already started still runs under the transport’s independent
timeout. Explicit request and reply deadlines are unaffected. Zero or an
unrepresentable deadline expires immediately.
Use super::Server::set_autoreply_timeout to also set the timeout for
future server sessions.
Sourcepub fn set_inbound_limits(self, requests: usize, bytes: usize) -> Self
pub fn set_inbound_limits(self, requests: usize, bytes: usize) -> Self
Sets the maximum accepted peer requests and buffered incoming bytes together.
Defaults to DEFAULT_MAX_INBOUND_REQUESTS and DEFAULT_MAX_INBOUND_BYTES.
requests counts queued requests, held responders and queued replies,
including automatic replies to requests with unknown content.
A slot is freed when the writer takes the reply or the reply is discarded.
Zero refuses all peer requests but still allows responses to our requests.
bytes counts the full encoded envelopes of queued requests and unread
responses. Self::recv, Promise::wait or dropping a response promise
releases that space in the budget. Zero allows no buffered envelopes.
Decoded application data, outgoing messages and transport buffers are
excluded.
Exceeding either limit closes this session with
Error::InboundRequestLimitExceeded or Error::InboundByteLimitExceeded.
The reader never waits for space. Lowering a limit below usage also closes
the session. Completed promises keep their results and bytes until read or
dropped. Raising limits does not reopen a closed session.
Sourcepub fn recv(&mut self) -> Result<(Message, Responder), Error>
pub fn recv(&mut self) -> Result<(Message, Responder), Error>
Blocks for the next peer request and its Responder.
Closing the session wakes this call with the error that closed it. The caller decides how to handle each request.
Taking a request removes its bytes from the inbound byte count before
decoding it. The request still counts toward the inbound request limit
while its responder is held. Invalid protobuf returns Error::Malformed
and closes this session, which runs the notify callbacks of its pending
promises on the calling thread.
If another thread closes the session after this call takes a request from the queue, it can still return that request. Replying after closure returns an error.
Sourcepub fn closer(&self) -> Closer
pub fn closer(&self) -> Closer
Returns a clonable handle for closing this session from another thread,
including while its owner is blocked in Self::recv.
Sourcepub fn close(&self)
pub fn close(&self)
Closes this session, discarding queued messages and failing pending promises.
Repeated calls have no further effect. A client session also closes its stream, waiting for adapter calls in progress to return. This does not wait for application jobs or guarantee the peer has observed closure. A transport write already started may still finish, but cannot change a completed promise’s result or affect a replacement session.