A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
Loading...
Searching...
No Matches
a11::net::WireStreamWithRecv Class Referencefinal

Pull-oriented adapter for a callback-driven WireStream. More...

#include <cpp/a11/net/wire_stream_with_recv.h>

Inheritance diagram for a11::net::WireStreamWithRecv:
[legend]

Classes

struct  State
 

Public Member Functions

absl::Status Send (data::WireMessage message) override
 Enqueue a message for delivery to the peer.
 
a11::Task Start (OnMessage on_message, OnDone on_done) override
 Begin the stream as the initiating ("start") side.
 
a11::Task Accept (OnMessage on_message, OnDone on_done) override
 Begin the stream as the accepting ("accept") side.
 
a11::Task Start ()
 Start the wrapped stream and route inbound messages to Receive().
 
a11::Task Accept ()
 Accept the wrapped stream and route inbound messages to Receive().
 
absl::Status HalfClose (data::ByteMap trailers) override
 Signal that this side will send no more messages.
 
a11::Task DrainOutgoingMessages () override
 Await delivery of all buffered outbound messages.
 
absl::Status Abort (absl::Status status) override
 Abort the stream, discarding buffered work.
 
absl::Status SetDeadline (absl::Time deadline) override
 Set the absolute deadline after which the stream is aborted.
 
absl::Time deadline () const override
 
absl::Status GetStatus () const override
 
std::optional< data::ByteMapGetTrailers () const override
 
std::string GetId () const override
 
void *absl_nullable GetImpl () const override
 
a11::Future< std::optional< data::WireMessage > > Receive (absl::Duration timeout=absl::InfiniteDuration())
 Await one inbound message, or nullopt after the peer half-closes.
 
std::shared_ptr< WireStreamwrapped_stream () const
 Return the underlying callback-oriented stream.
 
 WireStreamWithRecv (ConstructorToken, std::shared_ptr< WireStream > stream, std::string id, std::shared_ptr< State > state)
 
absl::Status HalfClose ()
 Half-close with no trailers.
 
virtual absl::Status HalfClose (data::ByteMap trailers)=0
 Signal that this side will send no more messages.
 
absl::Status SetDeadline ()
 Clear any deadline (equivalent to an infinite deadline).
 
virtual absl::Status SetDeadline (absl::Time deadline)=0
 Set the absolute deadline after which the stream is aborted.
 
- Public Member Functions inherited from a11::net::WireStream
virtual ~WireStream ()=default
 
absl::Status HalfClose ()
 Half-close with no trailers.
 
absl::Status SetDeadline ()
 Clear any deadline (equivalent to an infinite deadline).
 

Static Public Member Functions

static absl::StatusOr< std::shared_ptr< WireStreamWithRecv > > Create (std::shared_ptr< WireStream > stream)
 Wrap stream, preserving its id, lifecycle, and transport handle.
 

Detailed Description

Pull-oriented adapter for a callback-driven WireStream.

Wrap a stream when an agent loop would rather await Receive() than implement callbacks. Its single message slot preserves transport backpressure. A remote abort takes priority over buffered data and is observed by every current and future receiver.

Constructor & Destructor Documentation

◆ WireStreamWithRecv()

a11::net::WireStreamWithRecv::WireStreamWithRecv ( ConstructorToken  ,
std::shared_ptr< WireStream stream,
std::string  id,
std::shared_ptr< State state 
)
inline

Member Function Documentation

◆ Abort()

absl::Status a11::net::WireStreamWithRecv::Abort ( absl::Status  status)
overridevirtual

Abort the stream, discarding buffered work.

Parameters
statusA non-OK status reported to the peer as the abort reason.
Returns
OK if the abort was accepted.

Implements a11::net::WireStream.

◆ Accept() [1/2]

a11::Task a11::net::WireStreamWithRecv::Accept ( )

Accept the wrapped stream and route inbound messages to Receive().

◆ Accept() [2/2]

a11::Task a11::net::WireStreamWithRecv::Accept ( OnMessage  on_message,
OnDone  on_done 
)
overridevirtual

Begin the stream as the accepting ("accept") side.

Parameters
on_messageInvoked for each inbound message (nullopt = peer half-closed).
on_doneInvoked once when the stream has finished.
Returns
An awaitable that resolves once the stream is accepted.

Implements a11::net::WireStream.

◆ Create()

absl::StatusOr< std::shared_ptr< WireStreamWithRecv > > a11::net::WireStreamWithRecv::Create ( std::shared_ptr< WireStream stream)
static

Wrap stream, preserving its id, lifecycle, and transport handle.

◆ deadline()

absl::Time a11::net::WireStreamWithRecv::deadline ( ) const
overridevirtual
Returns
The stream's current deadline.

Implements a11::net::WireStream.

◆ DrainOutgoingMessages()

a11::Task a11::net::WireStreamWithRecv::DrainOutgoingMessages ( )
overridevirtual

Await delivery of all buffered outbound messages.

Returns
An awaitable that resolves once this endpoint's queued messages have been flushed to the transport (requires a prior HalfClose).

Implements a11::net::WireStream.

◆ GetId()

std::string a11::net::WireStreamWithRecv::GetId ( ) const
overridevirtual
Returns
This stream's transport-assigned identifier.

Implements a11::net::WireStream.

◆ GetImpl()

void *absl_nullable a11::net::WireStreamWithRecv::GetImpl ( ) const
overridevirtual
Returns
An opaque handle to the underlying transport object (advanced; may be null).

Implements a11::net::WireStream.

◆ GetStatus()

absl::Status a11::net::WireStreamWithRecv::GetStatus ( ) const
overridevirtual
Returns
The stream's terminal status (OK unless it failed or was aborted).

Implements a11::net::WireStream.

◆ GetTrailers()

std::optional< data::ByteMap > a11::net::WireStreamWithRecv::GetTrailers ( ) const
overridevirtual
Returns
The peer's closing trailers, if the stream has received them.

Implements a11::net::WireStream.

◆ HalfClose() [1/3]

absl::Status a11::net::WireStream::HalfClose ( )
inline

Half-close with no trailers.

See also
HalfClose(data::ByteMap)

◆ HalfClose() [2/3]

absl::Status a11::net::WireStreamWithRecv::HalfClose ( data::ByteMap  trailers)
overridevirtual

Signal that this side will send no more messages.

The terminal marker is queued after buffered outbound messages and, once the peer also half-closes, the stream completes. Inbound messages continue to be delivered until then. Call DrainOutgoingMessages() to await local transport delivery.

Parameters
trailersOptional closing metadata delivered to the peer.
Returns
OK, or a non-OK status if the stream cannot be half-closed.

Implements a11::net::WireStream.

◆ HalfClose() [3/3]

virtual absl::Status a11::net::WireStream::HalfClose ( data::ByteMap  trailers)
virtual

Signal that this side will send no more messages.

The terminal marker is queued after buffered outbound messages and, once the peer also half-closes, the stream completes. Inbound messages continue to be delivered until then. Call DrainOutgoingMessages() to await local transport delivery.

Parameters
trailersOptional closing metadata delivered to the peer.
Returns
OK, or a non-OK status if the stream cannot be half-closed.

Implements a11::net::WireStream.

◆ Receive()

a11::Future< std::optional< data::WireMessage > > a11::net::WireStreamWithRecv::Receive ( absl::Duration  timeout = absl::InfiniteDuration())

Await one inbound message, or nullopt after the peer half-closes.

Parameters
timeoutMaximum duration to wait for the next lifecycle event.

◆ Send()

absl::Status a11::net::WireStreamWithRecv::Send ( data::WireMessage  message)
overridevirtual

Enqueue a message for delivery to the peer.

Non-blocking.

The message is admitted to this endpoint's outbound queue and delivered asynchronously by the transport task, which is also where backpressure is applied; there is no delivery-order guarantee across messages (see the class comment).

Parameters
messageThe message to send.
Returns
OK once the message is queued, or a non-OK status if the stream is not writable (e.g. already half-closed or aborted).

Implements a11::net::WireStream.

◆ SetDeadline() [1/3]

absl::Status a11::net::WireStream::SetDeadline ( )
inline

Clear any deadline (equivalent to an infinite deadline).

◆ SetDeadline() [2/3]

absl::Status a11::net::WireStreamWithRecv::SetDeadline ( absl::Time  deadline)
overridevirtual

Set the absolute deadline after which the stream is aborted.

Parameters
deadlineThe deadline; absl::InfiniteFuture() disables it.

Implements a11::net::WireStream.

◆ SetDeadline() [3/3]

virtual absl::Status a11::net::WireStream::SetDeadline ( absl::Time  deadline)
virtual

Set the absolute deadline after which the stream is aborted.

Parameters
deadlineThe deadline; absl::InfiniteFuture() disables it.

Implements a11::net::WireStream.

◆ Start() [1/2]

a11::Task a11::net::WireStreamWithRecv::Start ( )

Start the wrapped stream and route inbound messages to Receive().

◆ Start() [2/2]

a11::Task a11::net::WireStreamWithRecv::Start ( OnMessage  on_message,
OnDone  on_done 
)
overridevirtual

Begin the stream as the initiating ("start") side.

Parameters
on_messageInvoked for each inbound message (nullopt = peer half-closed).
on_doneInvoked once when the stream has finished.
Returns
An awaitable that resolves once the startup handshake completes.

Implements a11::net::WireStream.

◆ wrapped_stream()

std::shared_ptr< WireStream > a11::net::WireStreamWithRecv::wrapped_stream ( ) const
inline

Return the underlying callback-oriented stream.


The documentation for this class was generated from the following files: