pub struct Responder { /* private fields */ }Expand description
Handle for answering one incoming request through the session that received it. The handler selects the success content, without a static request/response map. This handle cannot keep its session open or address a replacement session.
Dropping an unanswered responder queues an UNANSWERED error without blocking
on I/O, using the session’s current autoreply timeout.
Configure it with super::Session::set_autoreply_timeout or
super::Server::set_autoreply_timeout. If the session has closed, no reply
is queued.
A held responder counts toward the session’s inbound request limit. Queuing a
reply keeps that slot until the writer takes it or the reply is discarded.
See super::Session::set_inbound_limits.
Both Self::reply and Self::fail consume the responder, so it cannot be reused:
use darkbio_wire::protocol::{Responder, schema};
use std::time::Instant;
fn answer_twice(responder: Responder, deadline: Instant) {
let _ = responder.reply(schema::DeviceInfoResponse::default(), deadline);
let _ = responder.fail(schema::Error::new(0x100, "refused"), deadline);
}Responders cannot be cloned either:
use darkbio_wire::protocol::Responder;
fn duplicate(responder: Responder) { let _ = responder.clone(); }Implementations§
Source§impl Responder
impl Responder
Sourcepub fn reply(
self,
response: impl Into<Message>,
deadline: Instant,
) -> Result<Promise<()>, Error>
pub fn reply( self, response: impl Into<Message>, deadline: Instant, ) -> Result<Promise<()>, Error>
Queues a successful response and consumes the responder. Returns a promise for writing and flushing it. A closed session returns an error immediately. The deadline includes time in the queue and I/O. Waiting on the promise does not restart it.
A message invalid for this session’s direction fails the promise with
Error::WrongDirection.
A reply needs no further acknowledgment. Dropping its promise leaves it queued.
Accepts a protobuf response or Message directly. Use Self::fail to
return an error instead.
Sourcepub fn fail(
self,
error: impl Into<Error>,
deadline: Instant,
) -> Result<Promise<()>, Error>
pub fn fail( self, error: impl Into<Error>, deadline: Instant, ) -> Result<Promise<()>, Error>
Queues an error response and consumes the responder. The deadline and write
promise work as in Self::reply. The error itself does not close the session.
Accepts an application error implementing super::CodedError directly. Use
schema::Error::reserved for a named protocol error or
schema::Error::new for a bare numeric code.