actor-framework
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
caf::io::network::multiplexer Class Referenceabstract

Low-level backend for IO multiplexing. More...

#include <multiplexer.hpp>

Inheritance diagram for caf::io::network::multiplexer:
Inheritance graph
[legend]
Collaboration diagram for caf::io::network::multiplexer:
Collaboration graph
[legend]

Classes

class  runnable
 Simple wrapper for runnables. More...
 
class  supervisor
 Makes sure the multiplier does not exit its event loop until the destructor of supervisor has been called. More...
 

Public Types

using supervisor_ptr = std::unique_ptr< supervisor >
 

Public Member Functions

 multiplexer (actor_system &sys)
 
virtual scribe_ptr new_scribe (native_socket fd)=0
 Creates a new scribe from a native socket handle. More...
 
virtual expected< scribe_ptrnew_tcp_scribe (const std::string &host, uint16_t port)=0
 Tries to connect to host on given port and returns a scribe instance on success. More...
 
virtual doorman_ptr new_doorman (native_socket fd)=0
 Creates a new doorman from a native socket handle. More...
 
virtual expected< doorman_ptrnew_tcp_doorman (uint16_t port, const char *in=nullptr, bool reuse_addr=false)=0
 Tries to create an unbound TCP doorman bound to port, optionally accepting only connections from IP address in. More...
 
virtual datagram_servant_ptr new_datagram_servant (native_socket fd)=0
 Creates a new datagram_servant from a native socket handle. More...
 
virtual datagram_servant_ptr new_datagram_servant_for_endpoint (native_socket fd, const ip_endpoint &ep)=0
 
virtual expected< datagram_servant_ptrnew_remote_udp_endpoint (const std::string &host, uint16_t port)=0
 Create a new datagram_servant to contact a remote endpoint host and port. More...
 
virtual expected< datagram_servant_ptrnew_local_udp_endpoint (uint16_t port, const char *in=nullptr, bool reuse_addr=false)=0
 Create a new datagram_servant that receives datagrams on the local port, optionally only accepting connections from IP address in. More...
 
virtual supervisor_ptr make_supervisor ()=0
 Creates a supervisor to keep the event loop running.
 
virtual bool try_run_once ()=0
 Executes all pending events without blocking. More...
 
virtual void run_once ()=0
 Runs at least one event and blocks if needed.
 
virtual void run ()=0
 Runs events until all connection are closed.
 
template<class F >
void dispatch (F fun)
 Invokes fun in the multiplexer's event loop, calling fun() immediately when called from inside the event loop. More...
 
template<class F >
void post (F fun)
 Invokes fun in the multiplexer's event loop, forcing execution to be delayed when called from inside the event loop. More...
 
virtual multiplexer_backend * pimpl ()
 Retrieves a pointer to the implementation or nullptr if CAF was compiled using the default backend. More...
 
const std::thread::id & thread_id () const
 
void thread_id (std::thread::id tid)
 
actor_systemsystem ()
 
void start () override
 Starts this scheduler and all of its workers.
 
void stop () override
 Stops this scheduler and all of its workers.
 
- Public Member Functions inherited from caf::scheduler
virtual void schedule (resumable *what)=0
 Schedules what to run at some point in the future. More...
 
virtual void delay (resumable *what)=0
 Delay the next execution of what. More...
 

Static Public Member Functions

static std::unique_ptr< multiplexermake (actor_system &sys)
 Creates an instance using the networking backend compiled with CAF.
 
- Static Public Member Functions inherited from caf::scheduler
static std::unique_ptr< schedulermake_work_stealing (actor_system &sys)
 
static std::unique_ptr< schedulermake_work_sharing (actor_system &sys)
 

Protected Attributes

std::thread::id tid_
 Identifies the thread this multiplexer is running in. More...
 
actor_systemsys_
 Stores the actor system this multiplexer is part of.
 

Detailed Description

Low-level backend for IO multiplexing.

Member Function Documentation

◆ dispatch()

template<class F >
void caf::io::network::multiplexer::dispatch ( fun)
inline

Invokes fun in the multiplexer's event loop, calling fun() immediately when called from inside the event loop.

◆ new_datagram_servant()

virtual datagram_servant_ptr caf::io::network::multiplexer::new_datagram_servant ( native_socket  fd)
pure virtual

Creates a new datagram_servant from a native socket handle.

Implemented in caf::io::network::default_multiplexer.

◆ new_doorman()

virtual doorman_ptr caf::io::network::multiplexer::new_doorman ( native_socket  fd)
pure virtual

Creates a new doorman from a native socket handle.

Implemented in caf::io::network::default_multiplexer.

◆ new_local_udp_endpoint()

virtual expected<datagram_servant_ptr> caf::io::network::multiplexer::new_local_udp_endpoint ( uint16_t  port,
const char *  in = nullptr,
bool  reuse_addr = false 
)
pure virtual

Create a new datagram_servant that receives datagrams on the local port, optionally only accepting connections from IP address in.

Warning
Do not call from outside the multiplexer's event loop.

Implemented in caf::io::network::default_multiplexer.

◆ new_remote_udp_endpoint()

virtual expected<datagram_servant_ptr> caf::io::network::multiplexer::new_remote_udp_endpoint ( const std::string &  host,
uint16_t  port 
)
pure virtual

Create a new datagram_servant to contact a remote endpoint host and port.

Warning
Do not call from outside the multiplexer's event loop.

Implemented in caf::io::network::default_multiplexer.

◆ new_scribe()

virtual scribe_ptr caf::io::network::multiplexer::new_scribe ( native_socket  fd)
pure virtual

Creates a new scribe from a native socket handle.

Implemented in caf::io::network::default_multiplexer.

◆ new_tcp_doorman()

virtual expected<doorman_ptr> caf::io::network::multiplexer::new_tcp_doorman ( uint16_t  port,
const char *  in = nullptr,
bool  reuse_addr = false 
)
pure virtual

Tries to create an unbound TCP doorman bound to port, optionally accepting only connections from IP address in.

Warning
Do not call from outside the multiplexer's event loop.

Implemented in caf::io::network::default_multiplexer.

◆ new_tcp_scribe()

virtual expected<scribe_ptr> caf::io::network::multiplexer::new_tcp_scribe ( const std::string &  host,
uint16_t  port 
)
pure virtual

Tries to connect to host on given port and returns a scribe instance on success.

Implemented in caf::io::network::default_multiplexer.

◆ pimpl()

multiplexer_backend * caf::io::network::multiplexer::pimpl ( )
virtual

Retrieves a pointer to the implementation or nullptr if CAF was compiled using the default backend.

◆ post()

template<class F >
void caf::io::network::multiplexer::post ( fun)
inline

Invokes fun in the multiplexer's event loop, forcing execution to be delayed when called from inside the event loop.

◆ try_run_once()

virtual bool caf::io::network::multiplexer::try_run_once ( )
pure virtual

Executes all pending events without blocking.

Returns
true if at least one event was called, false otherwise.

Implemented in caf::io::network::default_multiplexer.

Member Data Documentation

◆ tid_

std::thread::id caf::io::network::multiplexer::tid_
protected

Identifies the thread this multiplexer is running in.

Must be set by the subclass.


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