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.
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::PollResult< multibuf::MultiBuf > | PendRead (async2::Context &cx) |
async2::Poll< Status > | PendReadyToWrite (pw::async2::Context &cx) |
async2::PollOptional< 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 |
|
inline |
Returns a reference to this channel as another channel with the specified properties, which must be compatible.
|
inline |
|
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::PollOptional< 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.
async2::PollResult< 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.
MultiBuf
.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.