pub enum AnyRequest {
ControlPlane {
request_id: VarInt,
draft: DraftVersion,
},
Draft16(NamespaceStream),
Draft17(RequestStream),
Draft18(RequestStream),
Draft19(RequestStream),
Draft20(RequestStream),
}Expand description
A request made through AnyConnection, in whichever form the negotiated
draft carries it.
Drafts 07-15 put every request on the single bidirectional control stream, so all a requester keeps is the request ID it was allocated. Draft-16 moved one request off it: Section 3.3 there names “two uses of bidirectional streams, the control stream, which begins with CLIENT_SETUP, and SUBSCRIBE_NAMESPACE”, so a namespace subscription on that draft owns a stream and everything else does not. From draft-17 on every request does, and the stream is the correlation — responses on those drafts carry no request ID at all. The variants reflect that split rather than hiding it.
Hold on to this value for as long as the request is live. Dropping a
per-request variant resets its stream, which the peer reads as a
cancellation; dropping AnyRequest::ControlPlane does nothing, because
there is no stream to reset.
The per-request variants are large — a RequestStream holds both halves of
a QUIC stream — and ControlPlane is two small fields. That disparity is
only visible when a single draft from 17 on is the only one enabled; with
more than one, the largest variants are the same size as each other.
Boxing them to close it would put an allocation on every request of every
draft to flatter a build no released configuration uses.
Variants§
ControlPlane
Drafts 07-16: the request was written on the control stream and is identified only by its request ID.
Fields
draft: DraftVersionThe draft that allocated it.
Draft16(NamespaceStream)
Draft-16: a namespace subscription, the one request on that draft that
owns a bidirectional stream. Every other draft-16 request comes back as
AnyRequest::ControlPlane.
Draft17(RequestStream)
Draft-17: the request owns a bidirectional stream.
Draft18(RequestStream)
Draft-18: the request owns a bidirectional stream.
Draft19(RequestStream)
Draft-19: the request owns a bidirectional stream.
Draft20(RequestStream)
Draft-20: the request owns a bidirectional stream.
Implementations§
Source§impl AnyRequest
impl AnyRequest
Sourcepub fn request_id(&self) -> VarInt
pub fn request_id(&self) -> VarInt
The request ID this request was allocated.
Sourcepub fn draft(&self) -> DraftVersion
pub fn draft(&self) -> DraftVersion
The draft that carries this request.
Sourcepub fn stream_id(&self) -> Option<u64>
pub fn stream_id(&self) -> Option<u64>
The transport stream ID this request owns, or None on a draft that
carries requests on the shared control stream.
This is the observable difference between the two variants: a caller
that needs to correlate a response by stream — which is the only
correlation drafts 17-19 offer — gets Some exactly when the draft
provides one.
Sourcepub fn cancel(&mut self, code: u64) -> Result<(), AnyConnectionError>
pub fn cancel(&mut self, code: u64) -> Result<(), AnyConnectionError>
Cancel the request by resetting its stream with code.
Only a request that owns a stream can do this, which is a draft-16 namespace subscription and every request from draft-17 on. Cancelling a request that lives on the control stream means sending a message (UNSUBSCRIBE, FETCH_CANCEL, and so on), which needs the connection and is therefore not reachable from the request handle alone. There this refuses rather than silently doing nothing.