MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Vruta::NetworkSource Class Reference

Awaitable broadcast message stream for a network endpoint. More...

#include <NetworkSource.hpp>

+ Collaboration diagram for MayaFlux::Vruta::NetworkSource:

Public Member Functions

void clear ()
 Clear all pending messages.
 
bool has_pending () const
 Check if messages are pending.
 
 NetworkSource (const Core::EndpointInfo &info)
 Open a network endpoint and begin receiving.
 
 NetworkSource (const NetworkSource &)=delete
 
 NetworkSource (NetworkSource &&) noexcept=default
 
Kriya::NetworkAwaiter next_message ()
 Create an awaiter for the next message.
 
NetworkSourceoperator= (const NetworkSource &)=delete
 
NetworkSourceoperator= (NetworkSource &&) noexcept=default
 
size_t pending_count () const
 Get number of pending messages.
 
void signal (const Core::NetworkMessage &message)
 Signal that a message arrived (called from Asio IO thread)
 
 ~NetworkSource ()
 Close the endpoint and release all resources.
 

Private Member Functions

std::optional< Core::NetworkMessagepop_message ()
 
void register_waiter (Kriya::NetworkAwaiter *awaiter)
 
void unregister_waiter (Kriya::NetworkAwaiter *awaiter)
 

Private Attributes

uint64_t m_endpoint_id {}
 
Memory::LockFreeQueue< Core::NetworkMessage, QUEUE_CAPACITYm_queue
 
std::atomic< Kriya::NetworkAwaiter * > m_waiters_head { nullptr }
 Head of the intrusive lock-free waiter list.
 

Static Private Attributes

static constexpr size_t QUEUE_CAPACITY = 256
 

Friends

class Kriya::NetworkAwaiter
 

Detailed Description

Awaitable broadcast message stream for a network endpoint.

Opens and owns a network endpoint on construction. Any number of coroutines may co_await the same source simultaneously via next_message(). signal() broadcasts to all registered waiters on every incoming message.

Fully lock-free on all paths. Waiter registration uses an intrusive singly-linked list with an atomic head. signal() atomically detaches the entire list and resumes each awaiter. The message queue is a lock-free ring buffer shared by all waiters — each awaiter pops its own copy on resumption.

Endpoint lifecycle is internal. BackendRegistry is consulted in the constructor and destructor; the caller never touches NetworkService.

Vruta::NetworkSource source({ .transport = NetworkTransport::UDP, .local_port = 8000 });
auto handler = [&source]() -> Vruta::Event {
while (true) {
auto msg = co_await source.next_message();
std::cout << msg.data.size() << " bytes from "
<< msg.sender_address << "\n";
}
};
Coroutine type for event-driven suspension.
Definition Event.hpp:26
Awaitable broadcast message stream for a network endpoint.

Definition at line 41 of file NetworkSource.hpp.


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