Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::runtime::AsyncStream Class Reference

#include <async_stream.hpp>

Public Types

using Options = AsyncStreamOptions

Public Member Functions

 AsyncStream (std::unique_ptr< Stream > stream, Options options={})
 ~AsyncStream ()
 AsyncStream (const AsyncStream &)=delete
AsyncStream & operator= (const AsyncStream &)=delete
void on_data (AsyncDataCallback cb)
 Attach callbacks.
void on_error (AsyncErrorCallback cb)
void on_close (AsyncCloseCallback cb)
void on_drain (AsyncCloseCallback cb)
 fires when pending writes hit 0
void start ()
 Start the worker thread. No-op if already running.
void stop ()
 Stop the worker thread and wait for it to exit.
void cancel ()
 Request cancellation.
bool write_async (const std::uint8_t *data, std::size_t size, AsyncWriteCallback callback={})
 Queue an async write.
std::size_t pending_write_bytes () const
 Bytes currently queued for writing.
CancelToken cancellation_token () const
 Cancellation token shared with this stream's worker.
Stream * stream ()
 Underlying Stream, for advanced callers.

Member Typedef Documentation

◆ Options

Constructor & Destructor Documentation

◆ AsyncStream() [1/2]

pulp::runtime::AsyncStream::AsyncStream ( std::unique_ptr< Stream > stream,
Options options = {} )
explicit

◆ ~AsyncStream()

pulp::runtime::AsyncStream::~AsyncStream ( )

◆ AsyncStream() [2/2]

pulp::runtime::AsyncStream::AsyncStream ( const AsyncStream & )
delete

Member Function Documentation

◆ cancel()

void pulp::runtime::AsyncStream::cancel ( )

Request cancellation.

Pending writes complete with StreamError::Closed; the worker exits at its next scheduled point.

◆ cancellation_token()

CancelToken pulp::runtime::AsyncStream::cancellation_token ( ) const
inline

Cancellation token shared with this stream's worker.

Callers can pass this to user code that wants to observe cancellation alongside the stream lifetime.

◆ on_close()

void pulp::runtime::AsyncStream::on_close ( AsyncCloseCallback cb)

◆ on_data()

void pulp::runtime::AsyncStream::on_data ( AsyncDataCallback cb)

Attach callbacks.

Must be called before start() so the worker has somewhere to send events. Safe to overwrite between stop() and start(); not safe to reassign while the worker is running.

◆ on_drain()

void pulp::runtime::AsyncStream::on_drain ( AsyncCloseCallback cb)

fires when pending writes hit 0

◆ on_error()

void pulp::runtime::AsyncStream::on_error ( AsyncErrorCallback cb)

◆ operator=()

AsyncStream & pulp::runtime::AsyncStream::operator= ( const AsyncStream & )
delete

◆ pending_write_bytes()

std::size_t pulp::runtime::AsyncStream::pending_write_bytes ( ) const

Bytes currently queued for writing.

◆ start()

void pulp::runtime::AsyncStream::start ( )

Start the worker thread. No-op if already running.

◆ stop()

void pulp::runtime::AsyncStream::stop ( )

Stop the worker thread and wait for it to exit.

Fires on_close exactly once if it has not fired already.

◆ stream()

Stream * pulp::runtime::AsyncStream::stream ( )
inline

Underlying Stream, for advanced callers.

Not thread-safe with the worker; only touch from the worker thread or after stop().

◆ write_async()

bool pulp::runtime::AsyncStream::write_async ( const std::uint8_t * data,
std::size_t size,
AsyncWriteCallback callback = {} )
nodiscard

Queue an async write.

Returns false if the write would exceed the configured high-water mark (backpressure). The caller should wait for on_drain before trying again.


The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/runtime/include/pulp/runtime/async_stream.hpp