LibQuicR
quicr::Connection Class Referenceabstract

Transport-independent state and callback dispatch for one connection. More...

#include <connection.h>

Inheritance diagram for quicr::Connection:

Classes

class  Delegate
 Async Callback API on the transport. More...
 

Public Types

enum class  Protocol : std::uint8_t { kNativeQuic , kWebTransport }
 Network protocol negotiated for this connection. More...
 
enum class  Status : std::uint8_t {
  kReady = 0 , kConnecting , kRemoteRequestClose , kDisconnected ,
  kIdleTimeout , kShutdown , kShuttingDown
}
 Connection lifecycle state. More...
 

Public Member Functions

 Connection (std::uint64_t id, Protocol protocol=Protocol::kNativeQuic)
 Construct connection state in Status::kConnecting. More...
 
virtual ~Connection ()=default
 Destroy the connection. More...
 
std::uint64_t GetID () const noexcept
 Return the transport-defined connection identifier. More...
 
Protocol GetProtocol () const noexcept
 Return the network protocol used by this connection. More...
 
void SetStatus (Status new_status)
 Change connection status and notify the delegate. More...
 
Status GetStatus () const noexcept
 Return the current connection status. More...
 
void SetDelegate (const std::shared_ptr< Delegate > &session)
 Replace the non-owning callback delegate. More...
 
virtual QuicMetricsSample TakeMetricsSample ()=0
 Close the sample period, taking its metrics off the connection. More...
 
virtual void ReportMetricsSample (const MetricsTimeStamp &sample_time, const QuicMetricsSample &sample)=0
 Report a taken sample to the delegate. More...
 
virtual void OnStatusChanged (Status status)
 Event notification for connection status changes. More...
 
virtual void OnRecvDgram ()
 callback notification that datagram data has been received and should be processed More...
 
virtual bool OnRecvStream (const std::shared_ptr< Stream > &stream)
 callback notification that data has been received and should be processed More...
 
virtual void OnStreamClosed (const std::shared_ptr< Stream > &stream, StreamClosedFlag flag)
 Callback notification that a stream has been closed by either FIN or RST. More...
 
bool RecordSetupSent ()
 
bool RecordSetupReceived ()
 
bool IsSetupComplete () const
 
void SetRxControlStreamId (std::uint64_t stream_id)
 
std::optional< std::uint64_t > GetRxControlStreamId () const
 
void SetTxControlStream (std::shared_ptr< Stream > stream)
 
std::shared_ptr< Stream > GetTxControlStream () const
 
void SetFirstUnprocessedRequestId (std::uint64_t request_id)
 
std::optional< std::uint64_t > GetFirstUnprocessedRequestId () const
 

Public Attributes

ConnectionMetrics metrics {}
 Application-facing cumulative and current-period connection metrics. More...
 

Protected Member Functions

std::shared_ptr< Delegate > GetDelegate () const
 Lock and promote the current weak delegate. More...
 

Protected Attributes

std::uint64_t id { 0 }
 Transport-defined connection identifier. More...
 
Protocol protocol_ { Protocol::kNativeQuic }
 The protocol the connection uses. Default is Native Quic. More...
 
std::atomic< Status > status_
 Current lifecycle state. More...
 
std::mutex mutex_
 
std::weak_ptr< Delegate > delegate_
 Non-owning event delegate guarded by the connection mutex. More...
 
bool setup_sent_ { false }
 
bool setup_received_ { false }
 
std::optional< std::uint64_t > rx_ctrl_stream_id_
 
std::shared_ptr< Stream > tx_ctrl_stream_
 
std::optional< std::uint64_t > first_unprocessed_request_id_
 

Detailed Description

Transport-independent state and callback dispatch for one connection.

Member Enumeration Documentation

◆ Protocol

enum quicr::Connection::Protocol : std::uint8_t
strong

Network protocol negotiated for this connection.

Enumerator
kNativeQuic 

Native MoQ over QUIC.

kWebTransport 

MoQ over a WebTransport session.

◆ Status

enum quicr::Connection::Status : std::uint8_t
strong

Connection lifecycle state.

Enumerator
kReady 

Ready for application traffic.

kConnecting 

Connection establishment is in progress.

kRemoteRequestClose 

The peer requested closure.

kDisconnected 

No longer connected.

kIdleTimeout 

Closed because the idle timeout elapsed.

kShutdown 

Transport shutdown is complete.

kShuttingDown 

Transport shutdown is in progress.

Constructor & Destructor Documentation

◆ Connection()

quicr::Connection::Connection ( std::uint64_t  id,
Protocol  protocol = Protocol::kNativeQuic 
)

Construct connection state in Status::kConnecting.

Parameters
idTransport-defined connection identifier.
protocolNetwork protocol used by the connection.

◆ ~Connection()

virtual quicr::Connection::~Connection ( )
virtualdefault

Destroy the connection.

Member Function Documentation

◆ GetDelegate()

std::shared_ptr<Delegate> quicr::Connection::GetDelegate ( ) const
protected

Lock and promote the current weak delegate.

Returns
Shared delegate, or null if detached or expired.

◆ GetFirstUnprocessedRequestId()

std::optional<std::uint64_t> quicr::Connection::GetFirstUnprocessedRequestId ( ) const

◆ GetID()

std::uint64_t quicr::Connection::GetID ( ) const
noexcept

Return the transport-defined connection identifier.

Returns
Identifier unique within the owning transport.

◆ GetProtocol()

Protocol quicr::Connection::GetProtocol ( ) const
noexcept

Return the network protocol used by this connection.

Returns
Negotiated native QUIC or WebTransport protocol.

◆ GetRxControlStreamId()

std::optional<std::uint64_t> quicr::Connection::GetRxControlStreamId ( ) const

◆ GetStatus()

Status quicr::Connection::GetStatus ( ) const
inlinenoexcept

Return the current connection status.

Returns
Atomically loaded lifecycle state.

◆ GetTxControlStream()

std::shared_ptr<Stream> quicr::Connection::GetTxControlStream ( ) const

◆ IsSetupComplete()

bool quicr::Connection::IsSetupComplete ( ) const

◆ OnRecvDgram()

virtual void quicr::Connection::OnRecvDgram ( )
virtual

callback notification that datagram data has been received and should be processed

◆ OnRecvStream()

virtual bool quicr::Connection::OnRecvStream ( const std::shared_ptr< Stream > &  stream)
virtual

callback notification that data has been received and should be processed

Parameters
streamStream the data arrived on, carrying its receive queue and the handler consuming it.
Returns
True if the stream was left with more that can be read now, and so wants another turn; false if there is no delegate to read it

◆ OnStatusChanged()

virtual void quicr::Connection::OnStatusChanged ( Status  status)
virtual

Event notification for connection status changes.

Called when the connection changes state/status

Parameters
statusTransport status value.

◆ OnStreamClosed()

virtual void quicr::Connection::OnStreamClosed ( const std::shared_ptr< Stream > &  stream,
StreamClosedFlag  flag 
)
virtual

Callback notification that a stream has been closed by either FIN or RST.

Parameters
streamStream that closed, carrying the handler it belonged to
flagFlag value for how the stream was closed. Values are FIN or RST

◆ RecordSetupReceived()

bool quicr::Connection::RecordSetupReceived ( )

◆ RecordSetupSent()

bool quicr::Connection::RecordSetupSent ( )

◆ ReportMetricsSample()

virtual void quicr::Connection::ReportMetricsSample ( const MetricsTimeStamp &  sample_time,
const QuicMetricsSample &  sample 
)
pure virtual

Report a taken sample to the delegate.

Separate from taking it so the reporting can be handed to the delegate's thread without leaving the counters exposed to it.

Parameters
sample_timeWall-clock time associated with the sample.
sampleMetrics previously returned by TakeMetricsSample.

◆ SetDelegate()

void quicr::Connection::SetDelegate ( const std::shared_ptr< Delegate > &  session)

Replace the non-owning callback delegate.

Parameters
sessionDelegate to observe events, or null to detach it.

The connection stores a weak reference. Attaching after connection establishment immediately replays the current non-connecting status.

◆ SetFirstUnprocessedRequestId()

void quicr::Connection::SetFirstUnprocessedRequestId ( std::uint64_t  request_id)

◆ SetRxControlStreamId()

void quicr::Connection::SetRxControlStreamId ( std::uint64_t  stream_id)

◆ SetStatus()

void quicr::Connection::SetStatus ( Status  new_status)

Change connection status and notify the delegate.

Parameters
new_statusNew lifecycle state.
Note
Reapplying the current status is a no-op.

◆ SetTxControlStream()

void quicr::Connection::SetTxControlStream ( std::shared_ptr< Stream >  stream)

◆ TakeMetricsSample()

virtual QuicMetricsSample quicr::Connection::TakeMetricsSample ( )
pure virtual

Close the sample period, taking its metrics off the connection.

Warning
Must be called with whatever excludes the threads that write those counters, since it resets them; see PicoQuicTransport::EmitMetrics for the transport's.
Returns
Metrics removed from the connection and its streams for the completed period.

Member Data Documentation

◆ delegate_

std::weak_ptr<Delegate> quicr::Connection::delegate_
protected

Non-owning event delegate guarded by the connection mutex.

◆ first_unprocessed_request_id_

std::optional<std::uint64_t> quicr::Connection::first_unprocessed_request_id_
protected

◆ id

std::uint64_t quicr::Connection::id { 0 }
protected

Transport-defined connection identifier.

◆ metrics

ConnectionMetrics quicr::Connection::metrics {}

Application-facing cumulative and current-period connection metrics.

◆ mutex_

std::mutex quicr::Connection::mutex_
mutableprotected

◆ protocol_

Protocol quicr::Connection::protocol_ { Protocol::kNativeQuic }
protected

The protocol the connection uses. Default is Native Quic.

◆ rx_ctrl_stream_id_

std::optional<std::uint64_t> quicr::Connection::rx_ctrl_stream_id_
protected

◆ setup_received_

bool quicr::Connection::setup_received_ { false }
protected

◆ setup_sent_

bool quicr::Connection::setup_sent_ { false }
protected

◆ status_

std::atomic<Status> quicr::Connection::status_
protected

Current lifecycle state.

◆ tx_ctrl_stream_

std::shared_ptr<Stream> quicr::Connection::tx_ctrl_stream_
protected

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