#include <channel.h>
Public Member Functions | |
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 reading or writing. | |
async2::Poll< Result< multibuf::MultiBuf > > | PendRead (async2::Context &cx) |
async2::Poll< Status > | PendReadyToWrite (pw::async2::Context &cx) |
async2::Poll< std::optional< multibuf::MultiBuf > > | PendAllocateWriteBuffer (async2::Context &cx, size_t min_bytes) |
Status | StageWrite (multibuf::MultiBuf &&data) |
async2::Poll< Status > | PendWrite (async2::Context &cx) |
async2::Poll< pw::Status > | PendClose (async2::Context &cx) |
template<typename Sibling , typename = internal::EnableIfConversionIsValid<Channel, Sibling>> | |
constexpr | operator Sibling & () |
Channels may be implicitly converted to other compatible channel types. | |
template<typename Sibling , typename = internal::EnableIfConversionIsValid<Channel, Sibling>> | |
constexpr | operator const Sibling & () const |
template<typename Sibling > | |
Sibling & | as () |
Returns a reference to this channel as another compatible channel type. | |
template<typename Sibling > | |
const Sibling & | as () const |
template<Property... kOtherChannelProperties> | |
auto & | as () |
template<Property... kOtherChannelProperties> | |
const auto & | as () const |
Channel< DataType::kByte, kProperties... > & | IgnoreDatagramBoundaries () |
const Channel< DataType::kByte, kProperties... > & | IgnoreDatagramBoundaries () const |
Friends | |
class | AnyChannel |
The basic Channel
type. Unlike AnyChannel
, the Channel
's properties are expressed in template parameters and thus reflected in the type.
Properties must be specified in order (kDatagram
, kReliable
, kReadable
, kWritable
, kSeekable
) and without duplicates.
To implement a Channel
, inherit from ChannelImpl
with the specified properties.
|
inline |
Returns a reference to this channel as another channel with the specified properties, which must be compatible.
|
constexpr |
True if the channel type supports and is open for reading. Always false for write-only channels.
|
constexpr |
True if the channel type supports and is open for writing. Always false for read-only channels.
async2::Poll< std::optional< multibuf::MultiBuf > > pw::channel::Channel< kDataType, kProperties >::PendAllocateWriteBuffer | ( | async2::Context & | cx, |
size_t | min_bytes | ||
) |
async2::Poll< pw::Status > pw::channel::Channel< kDataType, kProperties >::PendClose | ( | async2::Context & | cx | ) |
Closes the channel, flushing any 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. * * FAILED_PRECONDITION: Channel was already closed, which can happen * out-of-band due to errors. * *
async2::Poll< Result< multibuf::MultiBuf > > pw::channel::Channel< kDataType, kProperties >::PendRead | ( | async2::Context & | cx | ) |
Returns a pw::multibuf::MultiBuf
with read data, if available. If data is not available, invokes cx.waker()
when it becomes available.
For datagram channels, each successful read yields one complete datagram, which may contain zero or more bytes. For byte stream channels, each successful read yields one or more bytes.
Channels only support one read operation / waker at a time.
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: Data was read into a MultiBuf. * * UNIMPLEMENTED: The channel does not support reading. * * FAILED_PRECONDITION: The channel is closed. * * OUT_OF_RANGE: The end of the stream was reached. This may be though * of as reaching the end of a file. Future reads may succeed after * ``Seek`` ing backwards, but no more new data will be produced. The * channel is still open; writes and seeks may succeed. * *
async2::Poll< Status > pw::channel::Channel< kDataType, kProperties >::PendReadyToWrite | ( | pw::async2::Context & | cx | ) |
Checks whether a writeable channel is currently writeable.
This should be called before attempting to Write
, and may be called before allocating a write buffer if trying to reduce memory pressure.
This method will return:
Write
.cx
will be awoken when the channel becomes writeable again.Note: this method will always return Ready
for non-writeable channels.
async2::Poll< Status > pw::channel::Channel< kDataType, kProperties >::PendWrite | ( | async2::Context & | cx | ) |
Completes pending writes.
Returns a async2::Poll
indicating whether or the write has completed.
Status pw::channel::Channel< kDataType, kProperties >::StageWrite | ( | multibuf::MultiBuf && | data | ) |
Writes using a previously allocated MultiBuf. Returns a token that refers to this write. These tokens are monotonically increasing, and PendWrite() returns the value of the latest token it has flushed.
The MultiBuf
argument to Write
may consist of either: (1) A single MultiBuf
allocated by PendAllocateWriteBuffer
that has not been combined with any other MultiBuf
s or Chunk
s OR (2) A MultiBuf
containing any combination of buffers from sources other than PendAllocateWriteBuffer
.
This requirement allows for more efficient use of memory in case (1). For example, a ring-buffer implementation of a Channel
may specialize PendAllocateWriteBuffer
to return the next section of the buffer available for writing.
embed:rst:leading-asterisk * May fail with the following error codes: * * .. pw-status-codes:: * * OK: Data was accepted by the channel. * * UNIMPLEMENTED: The channel does not support writing. * * UNAVAILABLE: The write failed due to a transient error (only applies * to unreliable channels). * * FAILED_PRECONDITION: The channel is closed. * *