C++ Actor Framework 0.19
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
caf::net::multiplexer Class Reference

Multiplexes any number of ::socket_manager objects with a ::socket. More...

#include <multiplexer.hpp>

Inheritance diagram for caf::net::multiplexer:
caf::detail::atomic_ref_counted caf::async::execution_context

Public Types

using poll_update_map = unordered_flat_map< socket, poll_update >
 
using pollfd_list = std::vector< pollfd >
 
using manager_list = std::vector< socket_manager_ptr >
 

Public Member Functions

error init ()
 
size_t num_socket_managers () const noexcept
 Returns the number of currently active socket managers.
 
ptrdiff_t index_of (const socket_manager_ptr &mgr) const noexcept
 Returns the index of mgr in the pollset or -1.
 
ptrdiff_t index_of (socket fd) const noexcept
 Returns the index of fd in the pollset or -1.
 
middlemanowner ()
 Returns the owning middleman instance.
 
actor_systemsystem ()
 Returns the enclosing actor_system.
 
void ref_execution_context () const noexcept override
 Increases the reference count of the execution_context.
 
void deref_execution_context () const noexcept override
 Decreases the reference count of the execution context and destroys the object if necessary.
 
void schedule (action what) override
 Schedules what to run on the event loop of the execution context.
 
void watch (disposable what) override
 Asks the coordinator to keep its event loop running until what becomes disposed since it depends on external events or produces events that are visible to outside observers.
 
void start (socket_manager_ptr mgr)
 Registers mgr for initialization in the multiplexer's thread.
 
void shutdown ()
 Signals the multiplexer to initiate shutdown.
 
void register_reading (socket_manager *mgr)
 Registers mgr for read events.
 
void register_writing (socket_manager *mgr)
 Registers mgr for write events.
 
void deregister_reading (socket_manager *mgr)
 Deregisters mgr from read events.
 
void deregister_writing (socket_manager *mgr)
 Deregisters mgr from write events.
 
void deregister (socket_manager *mgr)
 Deregisters mgr from read and write events.
 
bool is_reading (const socket_manager *mgr) const noexcept
 Queries whether mgr is currently registered for reading.
 
bool is_writing (const socket_manager *mgr) const noexcept
 Queries whether mgr is currently registered for writing.
 
bool poll_once (bool blocking)
 Polls I/O activity once and runs all socket event handlers that become ready as a result.
 
void poll ()
 Runs poll_once(false) until it returns true.`.
 
void apply_updates ()
 Applies all pending updates.
 
void run_actions ()
 Runs all pending actions.
 
void set_thread_id ()
 Sets the thread ID to std::this_thread::id().
 
void run ()
 Runs the multiplexer until no socket event handler remains active.
 
- Public Member Functions inherited from caf::detail::atomic_ref_counted
 atomic_ref_counted (const atomic_ref_counted &)
 
atomic_ref_countedoperator= (const atomic_ref_counted &)
 
void ref () const noexcept
 Increases reference count by one.
 
void deref () const noexcept
 Decreases reference count by one and calls request_deletion when it drops to zero.
 
bool unique () const noexcept
 Queries whether there is exactly one reference.
 
size_t get_reference_count () const noexcept
 Queries the current reference count for this object.
 
- Public Member Functions inherited from caf::async::execution_context
virtual void ref_execution_context () const noexcept=0
 Increases the reference count of the execution_context.
 
virtual void deref_execution_context () const noexcept=0
 Decreases the reference count of the execution context and destroys the object if necessary.
 
virtual void schedule (action what)=0
 Schedules what to run on the event loop of the execution context.
 
template<class F >
void schedule_fn (F &&what)
 Schedules what to run on the event loop of the execution context.
 
virtual void watch (disposable what)=0
 Asks the coordinator to keep its event loop running until what becomes disposed since it depends on external events or produces events that are visible to outside observers.
 

Static Public Member Functions

static void block_sigpipe ()
 Blocks the PIPE signal on the current thread when running on a POSIX windows.
 
static multiplexerfrom (actor_system &sys)
 Returns a pointer to the multiplexer from the actor system.
 
static multiplexer_ptr make (middleman *parent)
 

Protected Member Functions

void handle (const socket_manager_ptr &mgr, short events, short revents)
 Handles an I/O event on given manager.
 
poll_update & update_for (ptrdiff_t index)
 Returns a change entry for the socket at given index.
 
poll_update & update_for (socket_manager *mgr)
 Returns a change entry for the socket of the manager.
 
template<class T >
void write_to_pipe (uint8_t opcode, T *ptr)
 Writes opcode and pointer to mgr the the pipe for handling an event later via the pollset updater.
 
template<class Enum , class T >
std::enable_if_t< std::is_enum_v< Enum > > write_to_pipe (Enum opcode, T *ptr)
 Writes opcode and pointer to mgr the the pipe for handling an event later via the pollset updater.
 
short active_mask_of (const socket_manager *mgr) const noexcept
 Queries the currently active event bitmask for mgr.
 

Protected Attributes

pollfd_list pollset_
 Bookkeeping data for managed sockets.
 
manager_list managers_
 Maps sockets to their owning managers by storing the managers in the same order as their sockets appear in pollset_.
 
poll_update_map updates_
 Caches changes to the events mask of managed sockets until they can safely take place.
 
std::thread::id tid_
 Stores the ID of the thread this multiplexer is running in.
 
std::mutex write_lock_
 Guards write_handle_.
 
pipe_socket write_handle_
 Used for pushing updates to the multiplexer's thread.
 
middlemanowner_
 Points to the owning middleman.
 
bool shutting_down_ = false
 Signals whether shutdown has been requested.
 
std::deque< actionpending_actions_
 Pending actions via schedule.
 
std::vector< disposablewatched_
 Keeps track of watched disposables.
 
- Protected Attributes inherited from caf::detail::atomic_ref_counted
std::atomic< size_t > rc_
 

Friends

class detail::pollset_updater
 

Additional Inherited Members

Detailed Description

Multiplexes any number of ::socket_manager objects with a ::socket.

Member Function Documentation

◆ block_sigpipe()

static void caf::net::multiplexer::block_sigpipe ( )
static

Blocks the PIPE signal on the current thread when running on a POSIX windows.

Has no effect when running on Windows.

◆ deref_execution_context()

void caf::net::multiplexer::deref_execution_context ( ) const
overridevirtualnoexcept

Decreases the reference count of the execution context and destroys the object if necessary.

Implements caf::async::execution_context.

◆ make()

static multiplexer_ptr caf::net::multiplexer::make ( middleman parent)
static
Parameters
parentPoints to the owning middleman instance. May be nullptr only for the purpose of unit testing if no socket_manager requires access to the middleman or the actor_system.

◆ ref_execution_context()

void caf::net::multiplexer::ref_execution_context ( ) const
overridevirtualnoexcept

Increases the reference count of the execution_context.

Implements caf::async::execution_context.

◆ schedule()

void caf::net::multiplexer::schedule ( action  what)
overridevirtual

Schedules what to run on the event loop of the execution context.

This member function may get called from external sources or threads. @thread-safe

Implements caf::async::execution_context.

◆ shutdown()

void caf::net::multiplexer::shutdown ( )

Signals the multiplexer to initiate shutdown.

@thread-safe

◆ start()

void caf::net::multiplexer::start ( socket_manager_ptr  mgr)

Registers mgr for initialization in the multiplexer's thread.

@thread-safe

◆ update_for()

poll_update & caf::net::multiplexer::update_for ( ptrdiff_t  index)
protected

Returns a change entry for the socket at given index.

Lazily creates a new entry before returning if necessary.

◆ watch()

void caf::net::multiplexer::watch ( disposable  what)
overridevirtual

Asks the coordinator to keep its event loop running until what becomes disposed since it depends on external events or produces events that are visible to outside observers.

Must be called from within the event loop of the execution context.

Implements caf::async::execution_context.

◆ write_to_pipe() [1/2]

template<class Enum , class T >
std::enable_if_t< std::is_enum_v< Enum > > caf::net::multiplexer::write_to_pipe ( Enum  opcode,
T *  ptr 
)
protected

Writes opcode and pointer to mgr the the pipe for handling an event later via the pollset updater.

Warning
assumes ownership of ptr.

◆ write_to_pipe() [2/2]

template<class T >
void caf::net::multiplexer::write_to_pipe ( uint8_t  opcode,
T *  ptr 
)
protected

Writes opcode and pointer to mgr the the pipe for handling an event later via the pollset updater.

Warning
assumes ownership of ptr.

Member Data Documentation

◆ tid_

std::thread::id caf::net::multiplexer::tid_
protected

Stores the ID of the thread this multiplexer is running in.

Set when calling init().


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