join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicEndpoint< OutboundPolicy, InboundPolicy > Class Template Reference

basic endpoint class. More...

#include <endpoint.hpp>

Public Types

enum  Side { A , B }
 endpoint side identifier. More...
 
using Outbound = typename OutboundPolicy::Producer
 
using Inbound = typename InboundPolicy::Consumer
 

Public Member Functions

constexpr BasicEndpoint () noexcept
 default constructor.
 
 BasicEndpoint (const struct sockaddr *addr, socklen_t len) noexcept
 create instance using socket address.
 
struct sockaddr * addr () noexcept
 get socket address.
 
const struct sockaddr * addr () const noexcept
 get socket address.
 
 BasicEndpoint (Side side, const std::string &name, uint64_t elementSize=1472, uint64_t capacity=144)
 create instance.
 
 BasicEndpoint (const BasicEndpoint &other)=delete
 copy constructor.
 
BasicEndpointoperator= (const BasicEndpoint &other)=delete
 copy assignment operator.
 
 ~BasicEndpoint ()
 destroy the instance.
 
int open ()
 open the channel endpoint.
 
void close ()
 close the channel endpoint.
 
bool opened () const
 check if the endpoint is open.
 
int trySend (const void *element)
 try to send a message to the peer (non blocking).
 
int send (const void *element)
 send a message to the peer (blocking).
 
template<class Rep , class Period >
int timedSend (const void *element, std::chrono::duration< Rep, Period > timeout)
 send a message to the peer with timeout (blocking).
 
int tryReceive (void *element)
 try to receive a message from the peer (non blocking).
 
int receive (void *element)
 receive a message from the peer (blocking).
 
template<class Rep , class Period >
int timedReceive (void *element, std::chrono::duration< Rep, Period > timeout)
 receive a message from the peer with timeout (blocking).
 
uint64_t available () const
 get number of available slots for sending.
 
bool full () const
 check if outbound queue is full.
 
uint64_t pending () const
 get number of pending messages.
 
bool empty () const
 check if inbound queue is empty.
 
Side side () const
 get the side this endpoint represents.
 
const std::string & name () const
 get the channel name.
 
uint64_t elementSize () const
 get the element size.
 
uint64_t capacity () const
 get the buffer capacity.
 

Protected Attributes

struct sockaddr_storage _addr = {}
 socket address storage.
 

Detailed Description

template<typename OutboundPolicy, typename InboundPolicy>
class join::BasicEndpoint< OutboundPolicy, InboundPolicy >

basic endpoint class.

bidirectional shared memory communication endpoint.

Member Typedef Documentation

◆ Inbound

template<typename OutboundPolicy , typename InboundPolicy >
using join::BasicEndpoint< OutboundPolicy, InboundPolicy >::Inbound = typename InboundPolicy::Consumer

◆ Outbound

template<typename OutboundPolicy , typename InboundPolicy >
using join::BasicEndpoint< OutboundPolicy, InboundPolicy >::Outbound = typename OutboundPolicy::Producer

Member Enumeration Documentation

◆ Side

template<typename OutboundPolicy , typename InboundPolicy >
enum join::BasicEndpoint::Side

endpoint side identifier.

Enumerator

side A acts as outbound producer and inbound consumer.

side B acts as inbound producer and outbound consumer.

Constructor & Destructor Documentation

◆ BasicEndpoint() [1/4]

template<typename OutboundPolicy , typename InboundPolicy >
join::BasicEndpoint< OutboundPolicy, InboundPolicy >::BasicEndpoint ( )
inlineconstexprnoexcept

default constructor.

◆ BasicEndpoint() [2/4]

template<typename OutboundPolicy , typename InboundPolicy >
join::BasicEndpoint< OutboundPolicy, InboundPolicy >::BasicEndpoint ( const struct sockaddr * addr,
socklen_t len )
inlinenoexcept

create instance using socket address.

Parameters
addrsocket address.
lensocket address length.

◆ BasicEndpoint() [3/4]

template<typename OutboundPolicy , typename InboundPolicy >
join::BasicEndpoint< OutboundPolicy, InboundPolicy >::BasicEndpoint ( Side side,
const std::string & name,
uint64_t elementSize = 1472,
uint64_t capacity = 144 )
inline

create instance.

Parameters
siderole of this endpoint.
namechannel name.
elementSizethe size of each data element in the ring buffers.
capacitythe maximum number of elements the ring buffers can hold.

◆ BasicEndpoint() [4/4]

template<typename OutboundPolicy , typename InboundPolicy >
join::BasicEndpoint< OutboundPolicy, InboundPolicy >::BasicEndpoint ( const BasicEndpoint< OutboundPolicy, InboundPolicy > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ ~BasicEndpoint()

template<typename OutboundPolicy , typename InboundPolicy >
join::BasicEndpoint< OutboundPolicy, InboundPolicy >::~BasicEndpoint ( )
inline

destroy the instance.

Member Function Documentation

◆ addr() [1/2]

template<typename OutboundPolicy , typename InboundPolicy >
const struct sockaddr * join::BasicEndpoint< OutboundPolicy, InboundPolicy >::addr ( ) const
inlinenoexcept

get socket address.

Returns
socket address.

◆ addr() [2/2]

template<typename OutboundPolicy , typename InboundPolicy >
struct sockaddr * join::BasicEndpoint< OutboundPolicy, InboundPolicy >::addr ( )
inlinenoexcept

get socket address.

Returns
socket address.

◆ available()

template<typename OutboundPolicy , typename InboundPolicy >
uint64_t join::BasicEndpoint< OutboundPolicy, InboundPolicy >::available ( ) const
inline

get number of available slots for sending.

Returns
number of free slots in the outbound queue.

◆ capacity()

template<typename OutboundPolicy , typename InboundPolicy >
uint64_t join::BasicEndpoint< OutboundPolicy, InboundPolicy >::capacity ( ) const
inline

get the buffer capacity.

Returns
number of elements each buffer can hold.

◆ close()

template<typename OutboundPolicy , typename InboundPolicy >
void join::BasicEndpoint< OutboundPolicy, InboundPolicy >::close ( )
inline

close the channel endpoint.

◆ elementSize()

template<typename OutboundPolicy , typename InboundPolicy >
uint64_t join::BasicEndpoint< OutboundPolicy, InboundPolicy >::elementSize ( ) const
inline

get the element size.

Returns
size of each message element in bytes.

◆ empty()

template<typename OutboundPolicy , typename InboundPolicy >
bool join::BasicEndpoint< OutboundPolicy, InboundPolicy >::empty ( ) const
inline

check if inbound queue is empty.

Returns
true if no messages available.

◆ full()

template<typename OutboundPolicy , typename InboundPolicy >
bool join::BasicEndpoint< OutboundPolicy, InboundPolicy >::full ( ) const
inline

check if outbound queue is full.

Returns
true if cannot send without blocking.

◆ name()

template<typename OutboundPolicy , typename InboundPolicy >
const std::string & join::BasicEndpoint< OutboundPolicy, InboundPolicy >::name ( ) const
inline

get the channel name.

Returns
channel name.

◆ open()

template<typename OutboundPolicy , typename InboundPolicy >
int join::BasicEndpoint< OutboundPolicy, InboundPolicy >::open ( )
inline

open the channel endpoint.

Returns
0 on success, -1 on failure

◆ opened()

template<typename OutboundPolicy , typename InboundPolicy >
bool join::BasicEndpoint< OutboundPolicy, InboundPolicy >::opened ( ) const
inline

check if the endpoint is open.

Returns
true if both outbound and inbound queues are opened.

◆ operator=()

template<typename OutboundPolicy , typename InboundPolicy >
BasicEndpoint & join::BasicEndpoint< OutboundPolicy, InboundPolicy >::operator= ( const BasicEndpoint< OutboundPolicy, InboundPolicy > & other)
delete

copy assignment operator.

Parameters
otherother object to copy.
Returns
assigned object.

◆ pending()

template<typename OutboundPolicy , typename InboundPolicy >
uint64_t join::BasicEndpoint< OutboundPolicy, InboundPolicy >::pending ( ) const
inline

get number of pending messages.

Returns
number of messages waiting in inbound queue.

◆ receive()

template<typename OutboundPolicy , typename InboundPolicy >
int join::BasicEndpoint< OutboundPolicy, InboundPolicy >::receive ( void * element)
inline

receive a message from the peer (blocking).

Parameters
elementpointer to buffer for received element.
Returns
0 on success, -1 on failure.

◆ send()

template<typename OutboundPolicy , typename InboundPolicy >
int join::BasicEndpoint< OutboundPolicy, InboundPolicy >::send ( const void * element)
inline

send a message to the peer (blocking).

Parameters
elementpointer to the element to send
Returns
0 on success, -1 on failure.

◆ side()

template<typename OutboundPolicy , typename InboundPolicy >
Side join::BasicEndpoint< OutboundPolicy, InboundPolicy >::side ( ) const
inline

get the side this endpoint represents.

Returns
Side::A or Side::B.

◆ timedReceive()

template<typename OutboundPolicy , typename InboundPolicy >
template<class Rep , class Period >
int join::BasicEndpoint< OutboundPolicy, InboundPolicy >::timedReceive ( void * element,
std::chrono::duration< Rep, Period > timeout )
inline

receive a message from the peer with timeout (blocking).

Parameters
elementpointer to buffer for received element.
timeoutmaximum time to wait
Returns
0 on success, -1 on failure.

◆ timedSend()

template<typename OutboundPolicy , typename InboundPolicy >
template<class Rep , class Period >
int join::BasicEndpoint< OutboundPolicy, InboundPolicy >::timedSend ( const void * element,
std::chrono::duration< Rep, Period > timeout )
inline

send a message to the peer with timeout (blocking).

Parameters
elementpointer to the element to send
timeoutmaximum time to wait
Returns
0 on success, -1 on failure.

◆ tryReceive()

template<typename OutboundPolicy , typename InboundPolicy >
int join::BasicEndpoint< OutboundPolicy, InboundPolicy >::tryReceive ( void * element)
inline

try to receive a message from the peer (non blocking).

Parameters
elementpointer to buffer for received element.
Returns
0 on success, -1 on failure.

◆ trySend()

template<typename OutboundPolicy , typename InboundPolicy >
int join::BasicEndpoint< OutboundPolicy, InboundPolicy >::trySend ( const void * element)
inline

try to send a message to the peer (non blocking).

Parameters
elementpointer to the element to send
Returns
0 on success, -1 on failure.

Member Data Documentation

◆ _addr

template<typename OutboundPolicy , typename InboundPolicy >
struct sockaddr_storage join::BasicEndpoint< OutboundPolicy, InboundPolicy >::_addr = {}
protected

socket address storage.


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