libcaf  0.14.4
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
caf::io Namespace Reference

Contains all IO-related classes and functions. More...

Namespaces

 basp
 Contains all classes and functions for the Binary Actor Sytem Protocol.
 
 network
 Contains classes and functions used for network abstraction.
 

Classes

class  abstract_broker
 A broker mediates between actor systems and other components in the network. More...
 
class  accept_handle
 Generic handle type for managing incoming connections. More...
 
struct  acceptor_closed_msg
 Signalizes that a broker acceptor has been closed. More...
 
class  basp_broker
 A broker implementation for the Binary Actor System Protocol (BASP). More...
 
class  broker
 Describes a dynamically typed broker. More...
 
class  broker_servant
 Base class for scribe and doorman. More...
 
struct  connection_closed_msg
 Signalizes that a broker connection has been closed. More...
 
class  connection_handle
 Generic handle type for identifying connections. More...
 
class  doorman
 Manages incoming connections. More...
 
class  hook
 Interface to define hooks into the IO layer. More...
 
class  middleman
 Manages brokers and network backends. More...
 
struct  new_connection_msg
 Signalizes a newly accepted connection from a broker. More...
 
struct  new_data_msg
 Signalizes newly arrived data for a broker. More...
 
class  scribe
 Manages a stream. More...
 

Typedefs

using broker_ptr = intrusive_ptr< broker >
 
using doorman_base = broker_servant< network::acceptor_manager, accept_handle, new_connection_msg >
 
using middleman_actor = typed_actor< replies_to< publish_atom, uint16_t, actor_addr, std::set< std::string >, std::string, bool >::with_either< ok_atom, uint16_t >::or_else< error_atom, std::string >, replies_to< open_atom, uint16_t, std::string, bool >::with_either< ok_atom, uint16_t >::or_else< error_atom, std::string >, replies_to< connect_atom, std::string, uint16_t >::with_either< ok_atom, node_id, actor_addr, std::set< std::string >>::or_else< error_atom, std::string >, replies_to< unpublish_atom, actor_addr, uint16_t >::with_either< ok_atom >::or_else< error_atom, std::string >, replies_to< close_atom, uint16_t >::with_either< ok_atom >::or_else< error_atom, std::string >, replies_to< spawn_atom, node_id, std::string, message >::with_either< ok_atom, actor_addr, std::set< std::string >>::or_else< error_atom, std::string >>
 A message passing interface for asynchronous networking operations. More...
 
using scribe_base = broker_servant< network::stream_manager, connection_handle, new_data_msg >
 

Enumerations

enum  receive_policy_flag {
  at_least,
  at_most,
  exactly
}
 

Functions

void max_msg_size (size_t size)
 Sets the maximum size of a message over network. More...
 
size_t max_msg_size ()
 Queries the maximum size of messages over network. More...
 
middleman_actor get_middleman_actor ()
 Returns a handle for asynchronous networking operations.
 
uint16_t publish_impl (uint16_t port, actor_addr whom, std::set< std::string > sigs, const char *in, bool reuse_addr)
 
uint16_t publish (caf::actor whom, uint16_t port, const char *in=nullptr, bool reuse_addr=false)
 Publishes whom at port. More...
 
template<class... Sigs>
uint16_t typed_publish (typed_actor< Sigs...> whom, uint16_t port, const char *in=nullptr, bool reuse_addr=false)
 
uint16_t publish_local_groups (uint16_t port, const char *addr=nullptr, bool reuse_addr=false)
 Makes all local groups accessible via network on address addr and port. More...
 
actor_addr remote_actor_impl (std::set< std::string > ifs, std::string host, uint16_t port)
 
actor remote_actor (std::string host, uint16_t port)
 Establish a new connection to the actor at host on given port. More...
 
template<class ActorHandle >
ActorHandle typed_remote_actor (std::string host, uint16_t port)
 Establish a new connection to the typed actor at host on given port. More...
 
group remote_group (const std::string &group_uri)
 <group-name><host>:<port>
 
group remote_group (const std::string &group_identifier, const std::string &host, uint16_t port)
 
void set_middleman (network::multiplexer *ptr)
 Sets a user-defined middleman using given network backend. More...
 
template<class Multiplexer >
void set_middleman ()
 Sets a user-defined middleman using given network backend. More...
 
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
infer_handle_from_fun< F >::type spawn_io (F fun, Ts &&...xs)
 Spawns a new functor-based broker.
 
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
infer_handle_from_fun< F >::type spawn_io_client (F fun, const std::string &host, uint16_t port, Ts &&...xs)
 Spawns a new functor-based broker connecting to host:port.
 
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
infer_handle_from_fun< F >::type spawn_io_server (F fun, uint16_t port, Ts &&...xs)
 Spawns a new broker as server running on given port.
 
void unpublish_impl (const actor_addr &whom, uint16_t port, bool block_caller)
 
template<class Handle >
void unpublish (const Handle &whom, uint16_t port=0)
 Unpublishes whom by closing port or all assigned ports if port == 0. More...
 

Variables

constexpr invalid_accept_handle_t invalid_accept_handle = invalid_accept_handle_t{}
 
constexpr invalid_connection_handle_t invalid_connection_handle = invalid_connection_handle_t{}
 

Detailed Description

Contains all IO-related classes and functions.

Typedef Documentation

using caf::io::middleman_actor = typedef typed_actor< replies_to<publish_atom, uint16_t, actor_addr, std::set<std::string>, std::string, bool> ::with_either<ok_atom, uint16_t> ::or_else<error_atom, std::string>, replies_to<open_atom, uint16_t, std::string, bool> ::with_either<ok_atom, uint16_t> ::or_else<error_atom, std::string>, replies_to<connect_atom, std::string, uint16_t> ::with_either<ok_atom, node_id, actor_addr, std::set<std::string>> ::or_else<error_atom, std::string>, replies_to<unpublish_atom, actor_addr, uint16_t> ::with_either<ok_atom> ::or_else<error_atom, std::string>, replies_to<close_atom, uint16_t> ::with_either<ok_atom> ::or_else<error_atom, std::string>, replies_to<spawn_atom, node_id, std::string, message> ::with_either<ok_atom, actor_addr, std::set<std::string>> ::or_else<error_atom, std::string>>

A message passing interface for asynchronous networking operations.

The interface implements the following pseudo code.

interface middleman_actor {
// Establishes a new `port <-> actor` mapping and returns the actual
// port in use on success. Passing 0 as port instructs the OS to choose
// the next high-level port available for binding.
// port: Unused TCP port or 0 for any.
// whom: Actor that should be published at given port.
// ifs: Interface of given actor.
// addr: IP address to listen to or empty for any.
// reuse:_addr: Enables or disables SO_REUSEPORT option.
(publish_atom, uint16_t port, actor_addr whom,
set<string> ifs, string addr, bool reuse_addr)
-> either (ok_atom, uint16_t port)
or (error_atom, string error_string)
// Opens a new port other CAF instances can connect to. The
// difference between `PUBLISH` and `OPEN` is that no actor is mapped to
// this port, meaning that connecting nodes only get a valid `node_id`
// handle when connecting.
// port: Unused TCP port or 0 for any.
// addr: IP address to listen to or empty for any.
// reuse:_addr: Enables or disables SO_REUSEPORT option.
(open_atom, uint16_t port, string addr, bool reuse_addr)
-> either (ok_atom, uint16_t port)
or (error_atom, string error_string)
// Queries a remote node and returns an ID to this node as well as
// an `actor_addr` to a remote actor if an actor was published at this
// port. The actor address must be cast to either `actor` or
// `typed_actor` using `actor_cast` after validating `ifs`.
// hostname: IP address or DNS hostname.
// port: TCP port.
(connect_atom, string hostname, uint16_t port)
-> either (ok_atom, node_id nid, actor_addr remote_actor, set<string> ifs)
or (error_atom, string error_string)
// Closes `port` if it is mapped to `whom`.
// whom: A published actor.
// port: Used TCP port.
(unpublish_atom, actor_addr whom, uint16_t port)
-> either (ok_atom)
or (error_atom, string error_string)
// Unconditionally closes `port`, removing any actor
// published at this port.
// port: Used TCP port.
(close_atom, uint16_t port)
-> either (ok_atom)
or (error_atom, string error_string)
// Spawns an actor on a remote node, initializing it using the arguments
// stored in `msg` and returns the address of the spawned actor and its
// interface description on success; an error string otherwise.
// nid: ID of the remote node that should spawn the actor.
// name: Announced type name of the actor.
// args: Initialization arguments for the actor.
(spawn_atom, node_id nid, string name, message args)
-> either (ok_atom, actor_addr, set<string>
or (error_atom, string error_string)
}

Function Documentation

void caf::io::max_msg_size ( size_t  size)

Sets the maximum size of a message over network.

Parameters
sizeThe maximum number of bytes a message may occupy.
size_t caf::io::max_msg_size ( )

Queries the maximum size of messages over network.

Returns
The number maximum number of bytes a message may occupy.
uint16_t caf::io::publish ( caf::actor  whom,
uint16_t  port,
const char *  in = nullptr,
bool  reuse_addr = false 
)

Publishes whom at port.

The connection is managed by the middleman.

Parameters
whomActor that should be published at port.
portUnused TCP port.
inThe IP address to listen to or INADDR_ANY if in == nullptr.
Returns
The actual port the OS uses after bind(). If port == 0 the OS chooses a random high-level port.
Exceptions
bind_failure
uint16_t caf::io::publish_local_groups ( uint16_t  port,
const char *  addr = nullptr,
bool  reuse_addr = false 
)

Makes all local groups accessible via network on address addr and port.

Returns
The actual port the OS uses after bind(). If port == 0 the OS chooses a random high-level port.
Exceptions
bind_failure
network_error
actor caf::io::remote_actor ( std::string  host,
uint16_t  port 
)

Establish a new connection to the actor at host on given port.

Parameters
hostValid hostname or IP address.
portTCP port.
Returns
An actor_ptr to the proxy instance representing a remote actor.
Exceptions
network_errorThrown on connection error or when connecting to a typed actor.
void caf::io::set_middleman ( network::multiplexer ptr)

Sets a user-defined middleman using given network backend.

Note
This function must be used before actor is spawned. Dynamically changing the middleman at runtime is not supported.
Exceptions
std::logic_errorif a middleman is already defined
template<class Multiplexer >
void caf::io::set_middleman ( )

Sets a user-defined middleman using given network backend.

Note
This function must be used before actor is spawned. Dynamically changing the middleman at runtime is not supported.
Exceptions
std::logic_errorif a middleman is already defined
template<class... Sigs>
uint16_t caf::io::typed_publish ( typed_actor< Sigs...>  whom,
uint16_t  port,
const char *  in = nullptr,
bool  reuse_addr = false 
)

template<class ActorHandle >
ActorHandle caf::io::typed_remote_actor ( std::string  host,
uint16_t  port 
)

Establish a new connection to the typed actor at host on given port.

Parameters
hostValid hostname or IP address.
portTCP port.
Returns
An actor_ptr to the proxy instance representing a typed remote actor.
Exceptions
network_errorThrown on connection error or when connecting to an untyped otherwise unexpected actor.
template<class Handle >
void caf::io::unpublish ( const Handle &  whom,
uint16_t  port = 0 
)

Unpublishes whom by closing port or all assigned ports if port == 0.

Parameters
whomActor that should be unpublished at port.
portTCP port.