Thrill  0.1
Connection Class Referenceabstract

Detailed Description

A Connection represents a link to another peer in a network group.

The link need not be an actual stateful TCP connection, but may be reliable and stateless.

The Connection class is abstract, and subclasses must exist for every network implementation.

Definition at line 49 of file connection.hpp.

+ Inheritance diagram for Connection:

#include <connection.hpp>

Public Types

enum  Flags : size_t { NoFlags = 0, MsgMore = 1 }
 Additional flags for sending or receiving. More...
 

Public Member Functions

Base Status Functions
virtual bool IsValid () const =0
 check whether the connection is (still) valid. More...
 
virtual std::string ToString () const =0
 return a string representation of this connection, for user output. More...
 
virtual std::ostream & OutputOstream (std::ostream &os) const =0
 virtual method to output to a std::ostream More...
 
Send Functions
virtual void SyncSend (const void *data, size_t size, Flags flags=NoFlags)=0
 
virtual ssize_t SendOne (const void *data, size_t size, Flags flags=NoFlags)=0
 
template<typename T >
std::enable_if< std::is_pod< T >::value, void >::type Send (const T &value)
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type Send (const T &value)
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&!data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type Send (const T &value)
 
Receive Functions
virtual void SyncRecv (void *out_data, size_t size)=0
 
virtual ssize_t RecvOne (void *out_data, size_t size)=0
 
template<typename T >
std::enable_if< std::is_pod< T >::value, void >::type Receive (T *out_value)
 Receive any serializable POD item T. More...
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type Receive (T *out_value)
 Receive any serializable non-POD fixed-length item T. More...
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&!data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type Receive (T *out_value)
 Receive any serializable non-POD fixed-length item T. More...
 
Paired SendReceive Methods
virtual void SyncSendRecv (const void *send_data, size_t send_size, void *recv_data, size_t recv_size)=0
 
virtual void SyncRecvSend (const void *send_data, size_t send_size, void *recv_data, size_t recv_size)=0
 
template<typename T >
std::enable_if< std::is_pod< T >::value, void >::type SendReceive (const T *value, T *out_value, size_t n=1)
 SendReceive any serializable POD item T. More...
 
template<typename T >
std::enable_if< std::is_pod< T >::value, void >::type ReceiveSend (const T &value, T *out_value)
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type SendReceive (const T *value, T *out_value, size_t n=1)
 SendReceive any serializable non-POD fixed-length item T. More...
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type ReceiveSend (const T &value, T *out_value)
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&!data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type SendReceive (const T *value, T *out_value, size_t n=1)
 SendReceive any serializable non-POD fixed-length item T. More...
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&!data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type ReceiveSend (const T &value, T *out_value)
 
SendN Functions
template<typename T >
std::enable_if< std::is_pod< T >::value, void >::type SendN (const T *value, size_t n)
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type SendN (const T *value, size_t n)
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&!data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type SendN (const T *value, size_t n)
 
ReceiveN Functions
template<typename T >
std::enable_if< std::is_pod< T >::value, void >::type ReceiveN (T *out_value, size_t n)
 Receive an array of serializable POD items T. More...
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type ReceiveN (T *out_value, size_t n)
 Receive an array of serializable non-POD fixed-length items T. More...
 
template<typename T >
std::enable_if< !std::is_pod< T >::value &&!data::Serialization< BufferBuilder, T >::is_fixed_size, void >::type ReceiveN (T *out_value, size_t n)
 Receive an array of serializable non-POD fixed-length items T. More...
 

Public Attributes

bool is_loopback_ = false
 
Sequence Numbers
std::atomic< uint32_t > tx_seq_ { 0 }
 send sequence More...
 
std::atomic< uint32_t > rx_seq_ { 0 }
 receive sequence More...
 

Static Public Attributes

static constexpr bool self_verify_ = common::g_self_verify
 

Friends

Flags operator| (const Flags &a, const Flags &b)
 operator to combine flags More...
 

Statistics

{

std::atomic< size_t > tx_bytes_ { 0 }
 sent bytes More...
 
std::atomic< size_t > rx_bytes_ = { 0 }
 received bytes More...
 
size_t prev_tx_bytes_ = 0
 previous read of sent bytes More...
 
size_t prev_rx_bytes_ = 0
 previous read of received bytes More...
 
std::atomic< size_t > tx_active_ { 0 }
 active send requests More...
 
std::atomic< size_t > rx_active_ = { 0 }
 active recv requests More...
 
std::ostream & operator<< (std::ostream &os, const Connection &c)
 } More...
 

Member Enumeration Documentation

◆ Flags

enum Flags : size_t

Additional flags for sending or receiving.

Enumerator
NoFlags 
MsgMore 

indicate that more data is coming, hence, sending a packet may be delayed. currently only applies to TCP.

Definition at line 61 of file connection.hpp.

Member Function Documentation

◆ IsValid()

virtual bool IsValid ( ) const
pure virtual

check whether the connection is (still) valid.

Implemented in Connection, Connection, and Connection.

Referenced by Dispatcher::AsyncRead(), and Dispatcher::AsyncWrite().

◆ OutputOstream()

virtual std::ostream& OutputOstream ( std::ostream &  os) const
pure virtual

virtual method to output to a std::ostream

Implemented in Connection, Connection, and Connection.

◆ Receive() [1/3]

std::enable_if<std::is_pod<T>::value, void>::type Receive ( T out_value)
inline

Receive any serializable POD item T.

Definition at line 184 of file connection.hpp.

References Connection::SyncRecv(), and gen_data::value.

Referenced by Group::ReceiveFrom().

◆ Receive() [2/3]

std::enable_if< !std::is_pod<T>::value && data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type Receive ( T out_value)
inline

Receive any serializable non-POD fixed-length item T.

Definition at line 204 of file connection.hpp.

References Buffer::data(), Buffer::size(), Connection::SyncRecv(), and gen_data::value.

◆ Receive() [3/3]

std::enable_if< !std::is_pod<T>::value && !data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type Receive ( T out_value)
inline

Receive any serializable non-POD fixed-length item T.

Definition at line 239 of file connection.hpp.

References Buffer::data(), Connection::SyncRecv(), Connection::SyncRecvSend(), Connection::SyncSendRecv(), and gen_data::value.

◆ ReceiveN() [1/3]

std::enable_if<std::is_pod<T>::value, void>::type ReceiveN ( T out_value,
size_t  n 
)
inline

Receive an array of serializable POD items T.

Definition at line 524 of file connection.hpp.

References Connection::SyncRecv(), and gen_data::value.

Referenced by Group::AllGatherBruck().

◆ ReceiveN() [2/3]

std::enable_if< !std::is_pod<T>::value && data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type ReceiveN ( T out_value,
size_t  n 
)
inline

Receive an array of serializable non-POD fixed-length items T.

Definition at line 544 of file connection.hpp.

References Buffer::data(), Buffer::size(), Connection::SyncRecv(), and gen_data::value.

◆ ReceiveN() [3/3]

std::enable_if< !std::is_pod<T>::value && !data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type ReceiveN ( T out_value,
size_t  n 
)
inline

Receive an array of serializable non-POD fixed-length items T.

Definition at line 569 of file connection.hpp.

References Buffer::data(), and Connection::SyncRecv().

◆ ReceiveSend() [1/3]

std::enable_if<std::is_pod<T>::value, void>::type ReceiveSend ( const T value,
T out_value 
)
inline

◆ ReceiveSend() [2/3]

std::enable_if< !std::is_pod<T>::value && data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type ReceiveSend ( const T value,
T out_value 
)
inline

◆ ReceiveSend() [3/3]

std::enable_if< !std::is_pod<T>::value && !data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type ReceiveSend ( const T value,
T out_value 
)
inline

◆ RecvOne()

virtual ssize_t RecvOne ( void *  out_data,
size_t  size 
)
pure virtual

Non-blocking receive of at most size data. returns number of bytes actually received. check errno for errors.

Implemented in Connection, Connection, and Connection.

Referenced by AsyncReadBuffer::operator()(), AsyncReadByteBlock::operator()(), and Connection::Send().

◆ Send() [1/3]

std::enable_if<std::is_pod<T>::value, void>::type Send ( const T value)
inline

Send any serializable POD item T. if sending fails, a net::Exception is thrown.

Definition at line 105 of file connection.hpp.

References Connection::SyncSend(), and gen_data::value.

Referenced by Group::SendTo().

◆ Send() [2/3]

std::enable_if< !std::is_pod<T>::value && data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type Send ( const T value)
inline

Send any serializable non-POD fixed-length item T. if sending fails, a net::Exception is thrown.

Definition at line 121 of file connection.hpp.

References BufferBuilder::data(), BufferBuilder::size(), Connection::SyncSend(), and gen_data::value.

◆ Send() [3/3]

std::enable_if< !std::is_pod<T>::value && !data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type Send ( const T value)
inline

Send any serializable non-POD variable-length item T. if sending fails, a net::Exception is thrown.

Definition at line 152 of file connection.hpp.

References BufferBuilder::data(), Connection::MsgMore, Connection::RecvOne(), BufferBuilder::size(), Connection::SyncRecv(), Connection::SyncSend(), and gen_data::value.

◆ SendN() [1/3]

std::enable_if<std::is_pod<T>::value, void>::type SendN ( const T value,
size_t  n 
)
inline

Send an array of serializable POD items T. if sending fails, a net::Exception is thrown.

Definition at line 462 of file connection.hpp.

References Connection::SyncSend(), and gen_data::value.

Referenced by Group::AllGatherBruck().

◆ SendN() [2/3]

std::enable_if< !std::is_pod<T>::value && data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type SendN ( const T value,
size_t  n 
)
inline

Send an array of serializable non-POD fixed-length items T. if sending fails, a net::Exception is thrown.

Definition at line 478 of file connection.hpp.

References BufferBuilder::data(), BufferBuilder::size(), Connection::SyncSend(), and gen_data::value.

◆ SendN() [3/3]

std::enable_if< !std::is_pod<T>::value && !data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type SendN ( const T value,
size_t  n 
)
inline

Send an array of serializable non-POD variable-length items T. if sending fails, a net::Exception is thrown.

Definition at line 500 of file connection.hpp.

References BufferBuilder::data(), Connection::MsgMore, BufferBuilder::size(), Connection::SyncSend(), and gen_data::value.

◆ SendOne()

virtual ssize_t SendOne ( const void *  data,
size_t  size,
Flags  flags = NoFlags 
)
pure virtual

Non-blocking send of a (data,size) message. returns number of bytes possible to send. check errno for errors.

Implemented in Connection, Connection, and Connection.

Referenced by AsyncWriteBuffer::operator()(), and AsyncWriteBlock::operator()().

◆ SendReceive() [1/3]

std::enable_if<std::is_pod<T>::value, void>::type SendReceive ( const T value,
T out_value,
size_t  n = 1 
)
inline

SendReceive any serializable POD item T.

Definition at line 277 of file connection.hpp.

References Connection::SyncSendRecv(), and gen_data::value.

Referenced by Group::AllGatherRecursiveDoublingPowerOfTwo(), Group::AllReduceHypercube(), and Group::SendReceiveReduce().

◆ SendReceive() [2/3]

std::enable_if< !std::is_pod<T>::value && data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type SendReceive ( const T value,
T out_value,
size_t  n = 1 
)
inline

SendReceive any serializable non-POD fixed-length item T.

Definition at line 317 of file connection.hpp.

References Buffer::data(), BufferBuilder::data(), Buffer::size(), BufferBuilder::size(), Connection::SyncSendRecv(), and gen_data::value.

◆ SendReceive() [3/3]

std::enable_if< !std::is_pod<T>::value && !data::Serialization<BufferBuilder, T>::is_fixed_size, void>::type SendReceive ( const T value,
T out_value,
size_t  n = 1 
)
inline

SendReceive any serializable non-POD fixed-length item T.

Definition at line 393 of file connection.hpp.

References Buffer::data(), BufferBuilder::data(), BufferBuilder::size(), Connection::SyncSendRecv(), and gen_data::value.

◆ SyncRecv()

virtual void SyncRecv ( void *  out_data,
size_t  size 
)
pure virtual

Synchronous blocking receive a message of given size. The size must match the SyncSend size for some network layers may only support matching messages (read: RDMA!, but also true for the mock net). Throws a net::Exception on errors.

Implemented in Connection, Connection, and Connection.

Referenced by Connection::Receive(), Connection::ReceiveN(), and Connection::Send().

◆ SyncRecvSend()

virtual void SyncRecvSend ( const void *  send_data,
size_t  send_size,
void *  recv_data,
size_t  recv_size 
)
pure virtual

◆ SyncSend()

virtual void SyncSend ( const void *  data,
size_t  size,
Flags  flags = NoFlags 
)
pure virtual

Synchronous blocking send of the (data,size) packet. if sending fails, a net::Exception is thrown.

Implemented in Connection, Connection, and Connection.

Referenced by Connection::Send(), and Connection::SendN().

◆ SyncSendRecv()

virtual void SyncSendRecv ( const void *  send_data,
size_t  send_size,
void *  recv_data,
size_t  recv_size 
)
pure virtual

Synchronous blocking sending and receive a message of given size. The size must match the SyncSendRecv size for some network layers may only support matching messages (read: RDMA!, but also true for the mock net). Throws a net::Exception on errors.

Implemented in Connection, Connection, and Connection.

Referenced by Connection::Receive(), and Connection::SendReceive().

◆ ToString()

virtual std::string ToString ( ) const
pure virtual

return a string representation of this connection, for user output.

Implemented in Connection, Connection, and Connection.

Referenced by Dispatcher::ExceptionCallback(), and AsyncReadBuffer::operator()().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Connection c 
)
friend

}

make ostreamable

Definition at line 629 of file connection.hpp.

◆ operator|

Flags operator| ( const Flags a,
const Flags b 
)
friend

operator to combine flags

Definition at line 69 of file connection.hpp.

Member Data Documentation

◆ is_loopback_

bool is_loopback_ = false

typeid().hash_code() is only guaranteed to be equal for the same program run, hence, we can only use it on loopback networks.

Definition at line 58 of file connection.hpp.

Referenced by Connection::Initialize().

◆ prev_rx_bytes_

size_t prev_rx_bytes_ = 0

previous read of received bytes

Definition at line 618 of file connection.hpp.

Referenced by Manager::RunTask().

◆ prev_tx_bytes_

size_t prev_tx_bytes_ = 0

previous read of sent bytes

Definition at line 615 of file connection.hpp.

Referenced by Manager::RunTask().

◆ rx_active_

std::atomic<size_t> rx_active_ = { 0 }

◆ rx_bytes_

std::atomic<size_t> rx_bytes_ = { 0 }

◆ rx_seq_

std::atomic<uint32_t> rx_seq_ { 0 }

receive sequence

Definition at line 601 of file connection.hpp.

Referenced by Multiplexer::AsyncReadMultiplexerHeader().

◆ self_verify_

constexpr bool self_verify_ = common::g_self_verify
static

flag which enables transmission of verification bytes for debugging, this increases network volume.

Definition at line 54 of file connection.hpp.

◆ tx_active_

std::atomic<size_t> tx_active_ { 0 }

◆ tx_bytes_

std::atomic<size_t> tx_bytes_ { 0 }

◆ tx_seq_

std::atomic<uint32_t> tx_seq_ { 0 }

send sequence

Definition at line 598 of file connection.hpp.

Referenced by StreamSink::AppendPinnedBlock().


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