ShmemExchange Class Reference

Space-ng SDK: sol3::core::ShmemExchange Class Reference
Space-ng SDK
sol3::core::ShmemExchange Class Reference

#include <sol3/core/shmem_exchange.h>

Inheritance diagram for sol3::core::ShmemExchange:
sol3::core::IBufferExchange

Public Types

using Endpoint = IBufferExchange::Endpoint
 
using EndpointPort = sol3::core::EndpointPort
 
using PortIdx = sol3::core::PortIdx
 
- Public Types inherited from sol3::core::IBufferExchange
using Endpoint = boost::asio::local::datagram_protocol::endpoint
 
using EndpointPort = sol3::core::EndpointPort
 
using PortIdx = sol3::core::PortIdx
 

Public Member Functions

 ShmemExchange (Endpoint const &local_endpoint)
 
 ShmemExchange (Endpoint const &local_endpoint, msg::ExchangeConfigT exchange_config)
 
 ~ShmemExchange () override
 Stops and releases socket/IO resources. More...
 
 ShmemExchange (ShmemExchange const &)=delete
 
ShmemExchangeoperator= (ShmemExchange const &)=delete
 
 ShmemExchange (ShmemExchange &&)=delete
 
ShmemExchangeoperator= (ShmemExchange &&)=delete
 
void start () override
 Start running in a background thread. More...
 
void stop () override
 Request the event loop to stop. More...
 
bool stopped () const override
 True if the exchange has been stopped. More...
 
void addPeer (Endpoint const &peer_endpoint) override
 
void mapLocalToPeer (uint32_t local_port, Endpoint peer_endpoint, uint32_t peer_port=0) override
 
void configure (msg::ExchangeConfigT const &config) override
 
void registerBuffer (IBufferMutable const &buffer) override
 
void unregisterBuffer (IBufferMutable const &buffer) override
 Unregister a previously shared mutable buffer. More...
 
Endpoint const & localEndpoint () const override
 Local endpoint used by this exchange. More...
 
std::shared_ptr< IBufferConstget (uint32_t port, uint32_t idx) const override
 
std::shared_ptr< IBufferConstget (Endpoint const &ep, uint32_t port, uint32_t idx) const override
 
void dispose (std::shared_ptr< IBufferConst > &&buffer) override
 Release resources associated with a previously retrieved buffer. More...
 
void listPorts (std::vector< EndpointPort > &ports) const override
 List all ports this exchange has received from peers or shared locally. More...
 
void listMappings (std::map< uint32_t, std::vector< std::pair< Endpoint, uint32_t >>> &mappings) const override
 
void listResolvedBuffers (std::map< PortIdx, std::shared_ptr< IBufferConst >> &buffers) const override
 
- Public Member Functions inherited from sol3::core::IBufferExchange
virtual ~IBufferExchange ()=default
 

Additional Inherited Members

- Static Public Member Functions inherited from sol3::core::IBufferExchange
static std::shared_ptr< IBufferExchangemakeProcessLocal ()
 

Detailed Description

UNIX-domain-socket-based buffer exchange for registering and discovering shared-memory buffers across peer processes.

Member Typedef Documentation

◆ Endpoint

◆ EndpointPort

◆ PortIdx

Constructor & Destructor Documentation

◆ ShmemExchange() [1/4]

sol3::core::ShmemExchange::ShmemExchange ( Endpoint const &  local_endpoint)

Create an exchange bound to the given local UNIX domain socket endpoint. Creates an exchange with an empty routing config.

◆ ShmemExchange() [2/4]

sol3::core::ShmemExchange::ShmemExchange ( Endpoint const &  local_endpoint,
msg::ExchangeConfigT  exchange_config 
)

Create an exchange bound to the given local UNIX domain socket endpoint. Always applies exchange_config.

◆ ~ShmemExchange()

sol3::core::ShmemExchange::~ShmemExchange ( )
override

Stops and releases socket/IO resources.

◆ ShmemExchange() [3/4]

sol3::core::ShmemExchange::ShmemExchange ( ShmemExchange const &  )
delete

◆ ShmemExchange() [4/4]

sol3::core::ShmemExchange::ShmemExchange ( ShmemExchange &&  )
delete

Member Function Documentation

◆ addPeer()

void sol3::core::ShmemExchange::addPeer ( Endpoint const &  peer_endpoint)
overridevirtual

Add a peer endpoint to poll for its shared buffers.

The endpoint is expected to be the path on disk of the peer's UNIX domain socket.

Implements sol3::core::IBufferExchange.

◆ configure()

void sol3::core::ShmemExchange::configure ( msg::ExchangeConfigT const &  config)
overridevirtual

Apply configuration to this exchange.

Replaces previously configured mappings.

Wildcard fallback behavior is expressed using mappings with local_port == 0 and peer_port == 0.

Implements sol3::core::IBufferExchange.

◆ dispose()

void sol3::core::ShmemExchange::dispose ( std::shared_ptr< IBufferConst > &&  buffer)
overridevirtual

Release resources associated with a previously retrieved buffer.

Implements sol3::core::IBufferExchange.

◆ get() [1/2]

std::shared_ptr<IBufferConst> sol3::core::ShmemExchange::get ( Endpoint const &  ep,
uint32_t  id,
uint32_t  idx 
) const
overridevirtual

Retrieve a shared buffer from a specific endpoint only.

This direct endpoint lookup does not apply resolution rules.

Implements sol3::core::IBufferExchange.

◆ get() [2/2]

std::shared_ptr<IBufferConst> sol3::core::ShmemExchange::get ( uint32_t  id,
uint32_t  idx 
) const
overridevirtual

Retrieve a shared buffer by port according to resolution rules.

Resolution order when one or more mappings exist: 1) explicit local-to-peer mappings, in registration order 2) wildcard fallback mappings (local_port_to_peer_ports[0]), in registration order 3) this exchange's local endpoint:port

idx is the index of the shared buffer associated with the port. For MessageInput/MessageOutput buffers, this is typically 0.

Implements sol3::core::IBufferExchange.

◆ listMappings()

void sol3::core::ShmemExchange::listMappings ( std::map< uint32_t, std::vector< std::pair< Endpoint, uint32_t >>> &  mappings) const
overridevirtual

Returns the current local-port-to-peer routing table.

Keyed by local port (0 = wildcard fallback). Each entry is an ordered list of (peer_endpoint, peer_port) pairs applied in registration order.

Implements sol3::core::IBufferExchange.

◆ listPorts()

void sol3::core::ShmemExchange::listPorts ( std::vector< EndpointPort > &  ports) const
overridevirtual

List all ports this exchange has received from peers or shared locally.

Implements sol3::core::IBufferExchange.

◆ listResolvedBuffers()

void sol3::core::ShmemExchange::listResolvedBuffers ( std::map< PortIdx, std::shared_ptr< IBufferConst >> &  buffers) const
overridevirtual

Returns resolved buffers, keyed by PortIdx.

Each buffer carries its source endpoint() and info().id().

Implements sol3::core::IBufferExchange.

◆ localEndpoint()

Endpoint const& sol3::core::ShmemExchange::localEndpoint ( ) const
inlineoverridevirtual

Local endpoint used by this exchange.

Implements sol3::core::IBufferExchange.

◆ mapLocalToPeer()

void sol3::core::ShmemExchange::mapLocalToPeer ( uint32_t  local_port,
Endpoint  peer_endpoint,
uint32_t  peer_port = 0 
)
overridevirtual

Add a resolution rule from a local logical buffer port to a peer endpoint/port tuple.

You can add more than one mapping per local_port; mappings are applied in registration order.

local_port and peer_port are typically computed by MessagePort::encoded().

Wildcard mappings:

  • local_port == 0 matches any requested local port.
  • peer_port == 0 means "use the requested local port". This is useful for fallback routing like (0 -> peer, 0).

Implements sol3::core::IBufferExchange.

◆ operator=() [1/2]

ShmemExchange& sol3::core::ShmemExchange::operator= ( ShmemExchange &&  )
delete

◆ operator=() [2/2]

ShmemExchange& sol3::core::ShmemExchange::operator= ( ShmemExchange const &  )
delete

◆ registerBuffer()

void sol3::core::ShmemExchange::registerBuffer ( IBufferMutable const &  buffer)
overridevirtual

Registers a mutable buffer to be shared with requesting peers.

The buffer is only shared in response to requests from other peers, and is not automatically shared with peers that this exchange polls.

The underlying shared-memory storage is kept alive for this exchange, and for any peer exchange that has received it.

Implements sol3::core::IBufferExchange.

◆ start()

void sol3::core::ShmemExchange::start ( )
overridevirtual

Start running in a background thread.

Implements sol3::core::IBufferExchange.

◆ stop()

void sol3::core::ShmemExchange::stop ( )
overridevirtual

Request the event loop to stop.

Implements sol3::core::IBufferExchange.

◆ stopped()

bool sol3::core::ShmemExchange::stopped ( ) const
overridevirtual

True if the exchange has been stopped.

Implements sol3::core::IBufferExchange.

◆ unregisterBuffer()

void sol3::core::ShmemExchange::unregisterBuffer ( IBufferMutable const &  buffer)
overridevirtual

Unregister a previously shared mutable buffer.

Implements sol3::core::IBufferExchange.


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