Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::netio::NetworkLoop Class Reference

Network event loop thread. More...

#include <network_loop.h>

Inheritance diagram for roc::netio::NetworkLoop:
Collaboration diagram for roc::netio::NetworkLoop:

Classes

class  Tasks
 Subclasses for specific tasks. More...
 

Public Types

typedef struct PortHandlePortHandle
 Opaque port handle. More...
 

Public Member Functions

 NetworkLoop (core::IPool &packet_pool, core::IPool &buffer_pool, core::IArena &arena)
 Initialize. More...
 
virtual ~NetworkLoop ()
 Destroy. Stop all receivers and senders. More...
 
bool is_valid () const
 Check if the object was successfully constructed. More...
 
size_t num_ports () const
 Get number of receiver and sender ports. More...
 
void schedule (NetworkTask &task, INetworkTaskCompleter &completer)
 Enqueue a task for asynchronous execution and return. The task should not be destroyed until the callback is called. The completer will be invoked on event loop thread after the task completes. More...
 
ROC_ATTR_NODISCARD bool schedule_and_wait (NetworkTask &task)
 Enqueue a task for asynchronous execution and wait for its completion. The task should not be destroyed until this method returns. Should not be called from schedule() callback. More...
 

Detailed Description

Network event loop thread.

Remarks
This class is a task-based facade for the whole roc_netio module.

Definition at line 49 of file network_loop.h.

Member Typedef Documentation

◆ PortHandle

Opaque port handle.

Definition at line 55 of file network_loop.h.

Constructor & Destructor Documentation

◆ NetworkLoop()

roc::netio::NetworkLoop::NetworkLoop ( core::IPool packet_pool,
core::IPool buffer_pool,
core::IArena arena 
)

Initialize.

Remarks
Start background thread if the object was successfully constructed.

◆ ~NetworkLoop()

virtual roc::netio::NetworkLoop::~NetworkLoop ( )
virtual

Destroy. Stop all receivers and senders.

Remarks
Wait until background thread finishes.

Member Function Documentation

◆ is_valid()

bool roc::netio::NetworkLoop::is_valid ( ) const

Check if the object was successfully constructed.

◆ num_ports()

size_t roc::netio::NetworkLoop::num_ports ( ) const

Get number of receiver and sender ports.

◆ schedule()

void roc::netio::NetworkLoop::schedule ( NetworkTask task,
INetworkTaskCompleter completer 
)

Enqueue a task for asynchronous execution and return. The task should not be destroyed until the callback is called. The completer will be invoked on event loop thread after the task completes.

◆ schedule_and_wait()

ROC_ATTR_NODISCARD bool roc::netio::NetworkLoop::schedule_and_wait ( NetworkTask task)

Enqueue a task for asynchronous execution and wait for its completion. The task should not be destroyed until this method returns. Should not be called from schedule() callback.

Returns
true if the task succeeded or false if it failed.

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