Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Friends | List of all members
pw::channel::AnyPacketChannel< T > Class Template Referenceabstract
Inheritance diagram for pw::channel::AnyPacketChannel< T >:
pw::channel::PacketChannel< T, kReadable > pw::channel::PacketChannel< T, kWritable > pw::channel::PacketChannel< T, kReadable, kWritable > pw::channel::internal::BasePacketChannelImpl< Packet, kReadable > pw::channel::internal::BasePacketChannelImpl< Packet, kReadable, kWritable > pw::channel::internal::BasePacketChannelImpl< Packet, kWritable > pw::channel::internal::PacketChannelImpl< Packet, kReadable > pw::channel::internal::PacketChannelImpl< Packet, kReadable, kWritable > pw::channel::internal::PacketChannelImpl< Packet, kWritable >

Public Types

using Packet = T
 

Public Member Functions

constexpr bool readable () const
 Returns whether the channel implementation is readable.
 
constexpr bool writable () const
 Returns whether the channel implementation is writable.
 
constexpr bool is_read_open () const
 
constexpr bool is_write_open () const
 
constexpr bool is_read_or_write_open () const
 True if the channel is open for either reading or writing.
 
async2::Poll< Result< Packet > > PendRead (async2::Context &cx)
 
async2::Poll< Result< PendingWrite< Packet > > > PendReadyToWrite (async2::Context &cx, size_t num=1)
 
async2::Poll PendWrite (async2::Context &cx)
 
void SetAvailableWrites (uint16_t available_writes)
 
void AcknowledgeWrites (uint16_t num_completed)
 
async2::Poll< StatusPendClose (async2::Context &cx)
 

Protected Member Functions

uint16_t GetAvailableWrites () const
 
void set_read_closed ()
 
void set_write_closed ()
 
void set_read_write_closed ()
 
async2::Wakerwrite_waker ()
 Allows implementations to access the write waker.
 

Friends

template<typename , Property... >
class PacketChannel
 
template<typename , Property... >
class internal::BasePacketChannelImpl
 

Detailed Description

template<typename T>
class pw::channel::AnyPacketChannel< T >

PacketChannel that optionally supports reading and writing. Generally, prefer PacketChannel, which expresses readability and writability in the type.

Warning
This class is in an early, experimental state. Do not use it until this warning is removed (https://pwbug.dev/421962771).

Member Function Documentation

◆ AcknowledgeWrites()

template<typename Packet >
void pw::channel::AnyPacketChannel< Packet >::AcknowledgeWrites ( uint16_t  num_completed)

Increases the number of available writes and wakes. Equivalent to SetAvailableWrites(GetAvailableWrites() + num_completed). Wakes a task waiting for PendReadyToWrite, if any.

Crashes if GetAvailableWrites() is kNoFlowControl.

◆ GetAvailableWrites()

template<typename T >
uint16_t pw::channel::AnyPacketChannel< T >::GetAvailableWrites ( ) const
inlineprotected

Indicates how many additional packets can currently be sent to the remote receiver.

◆ is_read_open()

template<typename T >
constexpr bool pw::channel::AnyPacketChannel< T >::is_read_open ( ) const
inlineconstexpr

True if the channel is open for reading. Always false for write-only channels.

◆ is_write_open()

template<typename T >
constexpr bool pw::channel::AnyPacketChannel< T >::is_write_open ( ) const
inlineconstexpr

True if the channel is open for writing. Always false for read-only channels.

◆ PendClose()

template<typename Packet >
async2::Poll< Status > pw::channel::AnyPacketChannel< Packet >::PendClose ( async2::Context cx)

Marks the channel as closed. Flushes any remaining data.

Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The channel was closed and all data was sent successfully.
* 
*     DATA_LOSS: The channel was closed, but not all previously written
*     data was delivered.
* 
*  

◆ PendRead()

template<typename T >
async2::Poll< Result< Packet > > pw::channel::AnyPacketChannel< T >::PendRead ( async2::Context cx)
inline

Returns async2::Ready with a new packet when one arrives. If no packet is ready yet, returns async2::Pending. Returns async2::Ready with a non-OK status if there was an unrecoverable error.

Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: A packet was read
* 
*     UNIMPLEMENTED: The channel does not support reading.
* 
*     FAILED_PRECONDITION: The channel is closed for reading.
* 
*     OUT_OF_RANGE: The end of the stream was reached and no further reads
*     will succeed.
* 
*  

◆ PendReadyToWrite()

template<typename Packet >
async2::Poll< Result< PendingWrite< Packet > > > pw::channel::AnyPacketChannel< Packet >::PendReadyToWrite ( async2::Context cx,
size_t  num = 1 
)

Returns async2::Ready if num packets can currently be staged, and async2::Pending otherwise. Returns async2::Ready with a non-OK status if there was an unrecoverable error.

TODO: b/421961717 - Determine whether to keep this method.

Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: The channel is currently writable. The returned `PendingWrite` may
*     be used to write a packet.
* 
*     UNIMPLEMENTED: The channel does not support writing.
* 
*     FAILED_PRECONDITION: The channel is closed for writing.
* 
*  

◆ PendWrite()

template<typename Packet >
async2::Poll pw::channel::AnyPacketChannel< Packet >::PendWrite ( async2::Context cx)

Processes staged write packets. PendWrite must be called after a write is staged so the channel can complete the write. This could involve writing to physical hardware, pushing data into a queue, or be a no-op.

PendReadyToWrite also allows the channel to send staged packets, but it is only called when there is a new outbound packet. PendWrite should be called after a write to avoid blocking outbound data until there is another packet to write.

If the packets have a deallocator set, they will be automatically deallocated after they are written.

Returns
async2::Ready when the channel has completed the write operation for all outbound data. Returns async2::Pending otherwise.

◆ set_read_closed()

template<typename T >
void pw::channel::AnyPacketChannel< T >::set_read_closed ( )
inlineprotected

Marks the channel as closed for reading, but does nothing else.

PendClose() always marks the channel closed when DoPendClose() returns Ready(), regardless of the status.

◆ set_read_write_closed()

template<typename T >
void pw::channel::AnyPacketChannel< T >::set_read_write_closed ( )
inlineprotected

Marks the channel as close for both reading and writing, but does nothing else.

PendClose() always marks the channel closed when DoPendClose() returns Ready(), regardless of the status.

◆ set_write_closed()

template<typename T >
void pw::channel::AnyPacketChannel< T >::set_write_closed ( )
inlineprotected

Marks the channel as closed for writing, but does nothing else.

PendClose() always marks the channel closed when DoPendClose() returns Ready(), regardless of the status.

◆ SetAvailableWrites()

template<typename Packet >
void pw::channel::AnyPacketChannel< Packet >::SetAvailableWrites ( uint16_t  available_writes)

Sets the number of packets the remote receiver can currently receive. This is typically set based on information from the receiver. Wakes any task waiting for PendReadyToWrite if the number of available writes increased.

Set available_writes to kNoFlowControl to disable flow control and wake any pending task.


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