Thrill
0.1
|
Connection is a rich point-to-point socket connection to another client (worker, master, or whatever).
Messages are fixed-length integral items or opaque byte strings with a length.
If any function fails to send or receive, then a NetException is thrown instead of explicit error handling. If ever an error occurs, we probably have to rebuild the whole network explicitly.
Definition at line 54 of file connection.hpp.
#include <connection.hpp>
Public Member Functions | |
Connection ()=default | |
default construction, contains invalid socket More... | |
Connection (Socket &&s) | |
Construct Connection from a Socket. More... | |
Connection (Socket &&s, size_t group_id, size_t peer_id) | |
Connection (Connection &&other) | |
move-constructor More... | |
~Connection () | |
void | Close () |
Close this Connection. More... | |
int | GetError () const |
Return the associated socket error. More... | |
std::string | GetPeerAddress () const |
Return the socket peer address. More... | |
Socket & | GetSocket () |
Return the raw socket object for more low-level network programming. More... | |
const Socket & | GetSocket () const |
Return the raw socket object for more low-level network programming. More... | |
size_t | group_id () const |
Gets the id of the net group this connection is associated with. More... | |
bool | IsValid () const final |
Check whether the contained file descriptor is valid. More... | |
Connection & | operator= (Connection &&other) |
move assignment-operator More... | |
bool | operator== (const Connection &c) const noexcept |
Checks wether two connections have the same underlying socket or not. More... | |
std::ostream & | OutputOstream (std::ostream &os) const final |
make ostreamable More... | |
size_t | peer_id () const |
Gets the id of the worker this connection is connected to. More... | |
ssize_t | RecvOne (void *out_data, size_t size) final |
ssize_t | SendOne (const void *data, size_t size, Flags flags) final |
void | set_group_id (size_t groupId) |
Sets the group id of this connection. More... | |
void | set_peer_id (size_t peerId) |
Sets the id of the worker this connection is connected to. More... | |
void | set_state (ConnectionState state) |
Sets the state of this connection. More... | |
void | SetNonBlocking (bool non_blocking) |
Set socket to non-blocking. More... | |
ConnectionState | state () const |
Gets the state of this connection. More... | |
void | SyncRecv (void *out_data, size_t size) final |
void | SyncRecvSend (const void *send_data, size_t send_size, void *recv_data, size_t recv_size) final |
void | SyncSend (const void *data, size_t size, Flags flags) final |
void | SyncSendRecv (const void *send_data, size_t send_size, void *recv_data, size_t recv_size) final |
std::string | ToString () const final |
return a string representation of this connection, for user output. More... | |
Public Member Functions inherited from Connection | |
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) |
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... | |
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) |
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) |
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... | |
Private Attributes | |
size_t | group_id_ = size_t(-1) |
The id of the group this connection is associated with. More... | |
size_t | peer_id_ = size_t(-1) |
The id of the worker this connection is connected to. More... | |
Socket | socket_ |
Underlying socket or connection handle. More... | |
ConnectionState | state_ = ConnectionState::Invalid |
Static Private Attributes | |
static constexpr bool | debug = false |
Additional Inherited Members | |
Public Types inherited from Connection | |
enum | Flags : size_t { NoFlags = 0, MsgMore = 1 } |
Additional flags for sending or receiving. More... | |
Public Attributes inherited from Connection | |
bool | is_loopback_ = false |
std::atomic< uint32_t > | tx_seq_ { 0 } |
send sequence More... | |
std::atomic< uint32_t > | rx_seq_ { 0 } |
receive sequence More... | |
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... | |
Static Public Attributes inherited from Connection | |
static constexpr bool | self_verify_ = common::g_self_verify |
|
default |
default construction, contains invalid socket
|
inlineexplicit |
Construct Connection from a Socket.
Definition at line 63 of file connection.hpp.
|
inline |
Construct Connection from a Socket, with immediate initialization. (Currently used by tests).
Definition at line 69 of file connection.hpp.
|
inline |
move-constructor
Definition at line 75 of file connection.hpp.
References thrill::net::tcp::Invalid.
|
inline |
Destruction of Connection should be explicitly done by a NetGroup or other network class.
Definition at line 157 of file connection.hpp.
References Connection::Close(), and Connection::IsValid().
|
inline |
Close this Connection.
Definition at line 213 of file connection.hpp.
References Socket::close(), and Connection::socket_.
Referenced by Connection::operator=(), and Connection::~Connection().
|
inline |
Return the associated socket error.
Definition at line 138 of file connection.hpp.
References Socket::GetError(), and Connection::socket_.
|
inline |
Return the socket peer address.
Definition at line 148 of file connection.hpp.
References Socket::GetPeerAddress(), Connection::socket_, and SocketAddress::ToStringHostPort().
Referenced by Connection::OutputOstream().
|
inline |
Return the raw socket object for more low-level network programming.
Definition at line 130 of file connection.hpp.
References Connection::socket_.
Referenced by SelectDispatcher::AddRead(), SelectDispatcher::AddWrite(), SelectDispatcher::Cancel(), Connection::operator==(), Connection::OutputOstream(), SelectDispatcher::SetExcept(), and Connection::ToString().
|
inline |
Return the raw socket object for more low-level network programming.
Definition at line 134 of file connection.hpp.
References Connection::socket_.
|
inline |
Gets the id of the net group this connection is associated with.
Definition at line 103 of file connection.hpp.
References Connection::group_id_.
|
inlinefinalvirtual |
Check whether the contained file descriptor is valid.
Implements Connection.
Definition at line 123 of file connection.hpp.
References Socket::IsValid(), and Connection::socket_.
Referenced by Connection::operator=(), Connection::OutputOstream(), and Connection::~Connection().
|
inline |
move assignment-operator
Definition at line 84 of file connection.hpp.
References Connection::Close(), Connection::group_id_, thrill::net::tcp::Invalid, Connection::IsValid(), Connection::peer_id_, sLOG1, Connection::socket_, and Connection::state_.
|
inlinenoexcept |
Checks wether two connections have the same underlying socket or not.
Definition at line 152 of file connection.hpp.
References Socket::fd(), and Connection::GetSocket().
|
inlinefinalvirtual |
make ostreamable
Implements Connection.
Definition at line 218 of file connection.hpp.
References Socket::fd(), Connection::GetPeerAddress(), Connection::GetSocket(), and Connection::IsValid().
|
inline |
Gets the id of the worker this connection is connected to.
Definition at line 107 of file connection.hpp.
References Connection::peer_id_.
|
inlinefinalvirtual |
Non-blocking receive of at most size data. returns number of bytes actually received. check errno for errors.
Implements Connection.
Definition at line 190 of file connection.hpp.
References Socket::recv_one(), Connection::rx_bytes_, Connection::SetNonBlocking(), and Connection::socket_.
|
inlinefinalvirtual |
Non-blocking send of a (data,size) message. returns number of bytes possible to send. check errno for errors.
Implements Connection.
Definition at line 171 of file connection.hpp.
References MSG_MORE, Connection::MsgMore, Socket::send_one(), Connection::SetNonBlocking(), Connection::socket_, and Connection::tx_bytes_.
|
inline |
Sets the group id of this connection.
Definition at line 115 of file connection.hpp.
References Connection::group_id_.
|
inline |
Sets the id of the worker this connection is connected to.
Definition at line 119 of file connection.hpp.
References Connection::peer_id_.
|
inline |
Sets the state of this connection.
Definition at line 111 of file connection.hpp.
References Connection::state(), and Connection::state_.
|
inline |
Set socket to non-blocking.
Definition at line 142 of file connection.hpp.
References Socket::SetNonBlocking(), and Connection::socket_.
Referenced by Connection::RecvOne(), Connection::SendOne(), Connection::SyncRecv(), and Connection::SyncSend().
|
inline |
Gets the state of this connection.
Definition at line 99 of file connection.hpp.
References Connection::state_.
Referenced by Connection::set_state().
|
inlinefinalvirtual |
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.
Implements Connection.
Definition at line 183 of file connection.hpp.
References Socket::recv(), Connection::rx_bytes_, Connection::SetNonBlocking(), and Connection::socket_.
Referenced by Connection::SyncRecvSend(), and Connection::SyncSendRecv().
|
inlinefinalvirtual |
Implements Connection.
Definition at line 206 of file connection.hpp.
References Connection::NoFlags, Connection::SyncRecv(), and Connection::SyncSend().
|
inlinefinalvirtual |
Synchronous blocking send of the (data,size) packet. if sending fails, a net::Exception is thrown.
Implements Connection.
Definition at line 162 of file connection.hpp.
References MSG_MORE, Connection::MsgMore, Socket::send(), Connection::SetNonBlocking(), Connection::socket_, and Connection::tx_bytes_.
Referenced by Connection::SyncRecvSend(), and Connection::SyncSendRecv().
|
inlinefinalvirtual |
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.
Implements Connection.
Definition at line 200 of file connection.hpp.
References Connection::NoFlags, Connection::SyncRecv(), and Connection::SyncSend().
|
inlinefinalvirtual |
return a string representation of this connection, for user output.
Implements Connection.
Definition at line 126 of file connection.hpp.
References Connection::GetSocket(), and thrill::mem::to_string().
|
staticprivate |
Definition at line 56 of file connection.hpp.
|
private |
The id of the group this connection is associated with.
Definition at line 237 of file connection.hpp.
Referenced by Connection::group_id(), Connection::operator=(), and Connection::set_group_id().
|
private |
The id of the worker this connection is connected to.
Definition at line 240 of file connection.hpp.
Referenced by Connection::operator=(), Connection::peer_id(), and Connection::set_peer_id().
|
private |
Underlying socket or connection handle.
Definition at line 230 of file connection.hpp.
Referenced by Connection::Close(), Connection::GetError(), Connection::GetPeerAddress(), Connection::GetSocket(), Connection::IsValid(), Connection::operator=(), Connection::RecvOne(), Connection::SendOne(), Connection::SetNonBlocking(), Connection::SyncRecv(), and Connection::SyncSend().
|
private |
The connection state of this connection in the Thrill network state machine.
Definition at line 234 of file connection.hpp.
Referenced by Connection::operator=(), Connection::set_state(), and Connection::state().