Pigweed
C/C++ API Reference
|
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< Status > | PendClose (async2::Context &cx) |
Protected Member Functions | |
uint16_t | GetAvailableWrites () const |
void | set_read_closed () |
void | set_write_closed () |
void | set_read_write_closed () |
async2::Waker & | write_waker () |
Allows implementations to access the write waker. | |
Friends | |
template<typename , Property... > | |
class | PacketChannel |
template<typename , Property... > | |
class | internal::BasePacketChannelImpl |
PacketChannel
that optionally supports reading and writing. Generally, prefer PacketChannel
, which expresses readability and writability in the type.
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
.
|
inlineprotected |
Indicates how many additional packets can currently be sent to the remote receiver.
|
inlineconstexpr |
True if the channel is open for reading. Always false for write-only channels.
|
inlineconstexpr |
True if the channel is open for writing. Always false for read-only channels.
async2::Poll< Status > pw::channel::AnyPacketChannel< Packet >::PendClose | ( | async2::Context & | cx | ) |
Marks the channel as closed. Flushes any remaining data.
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. * *
|
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.
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. * *
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.
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. * *
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.
async2::Ready
when the channel has completed the write operation for all outbound data. Returns async2::Pending
otherwise.
|
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.
|
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.
|
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.
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.