preCICE
Loading...
Searching...
No Matches
precice::com::SocketCommunication Class Reference

Implements Communication by using sockets. More...

#include <SocketCommunication.hpp>

Inheritance diagram for precice::com::SocketCommunication:
[legend]
Collaboration diagram for precice::com::SocketCommunication:
[legend]

Public Member Functions

 SocketCommunication (unsigned short portNumber=0, bool reuseAddress=false, std::string networkName=utils::networking::loopbackInterfaceName(), std::string addressDirectory=".")
 SocketCommunication (std::string const &addressDirectory)
 ~SocketCommunication () override
size_t getRemoteCommunicatorSize () override
void acceptConnection (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int acceptorRank, int rankOffset=0) override
void acceptConnectionAsServer (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int acceptorRank, int requesterCommunicatorSize) override
void requestConnection (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int requesterRank, int requesterCommunicatorSize) override
void requestConnectionAsClient (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, std::set< int > const &acceptorRanks, int requesterRank) override
void closeConnection () override
void send (std::string const &itemToSend, Rank rankReceiver) override
 Sends a std::string to process with given rank.
void send (precice::span< const int > itemsToSend, Rank rankReceiver) override
 Sends an array of integer values.
PtrRequest aSend (precice::span< const int > itemsToSend, Rank rankReceiver) override
 Asynchronously sends an array of integer values.
void send (precice::span< const double > itemsToSend, Rank rankReceiver) override
 Sends an array of double values.
PtrRequest aSend (precice::span< const double > itemsToSend, Rank rankReceiver) override
 Asynchronously sends an array of double values.
void send (double itemToSend, Rank rankReceiver) override
 Sends a double to process with given rank.
PtrRequest aSend (const double &itemToSend, Rank rankReceiver) override
 Asynchronously sends a double to process with given rank.
void send (int itemToSend, Rank rankReceiver) override
 Sends an int to process with given rank.
PtrRequest aSend (const int &itemToSend, Rank rankReceiver) override
 Asynchronously sends an int to process with given rank.
void send (bool itemToSend, Rank rankReceiver) override
 Sends a bool to process with given rank.
PtrRequest aSend (const bool &itemToSend, Rank rankReceiver) override
 Asynchronously sends a bool to process with given rank.
void receive (std::string &itemToReceive, Rank rankSender) override
 Receives a std::string from process with given rank.
void receive (precice::span< int > itemsToReceive, Rank rankSender) override
 Receives an array of integer values.
void receive (precice::span< double > itemsToReceive, Rank rankSender) override
 Receives an array of double values.
PtrRequest aReceive (precice::span< double > itemsToReceive, int rankSender) override
 Asynchronously receives an array of double values.
void receive (double &itemToReceive, Rank rankSender) override
 Receives a double from process with given rank.
PtrRequest aReceive (double &itemToReceive, Rank rankSender) override
 Asynchronously receives a double from process with given rank.
void receive (int &itemToReceive, Rank rankSender) override
 Receives an int from process with given rank.
PtrRequest aReceive (int &itemToReceive, Rank rankSender) override
 Asynchronously receives an int from process with given rank.
void receive (bool &itemToReceive, Rank rankSender) override
 Receives a bool from process with given rank.
PtrRequest aReceive (bool &itemToReceive, Rank rankSender) override
 Asynchronously receives a bool from process with given rank.
void prepareEstablishment (std::string const &acceptorName, std::string const &requesterName) override
void cleanupEstablishment (std::string const &acceptorName, std::string const &requesterName) override

Private Types

using IOContext = boost::asio::io_context
using Socket = boost::asio::ip::tcp::socket
using WorkGuard = boost::asio::executor_work_guard<IOContext::executor_type>

Private Member Functions

bool isClient ()
bool isServer ()
std::string getIpAddress ()

Private Attributes

logging::Logger _log {"com::SocketCommunication"}
unsigned short _portNumber
 Port used for socket connection.
bool _reuseAddress
std::string _networkName
 Name of network to communicate over.
std::string _addressDirectory
 Directory where IP address is exchanged by file.
std::shared_ptr< IOContext_ioContext
std::unique_ptr< WorkGuard_workGuard
std::thread _thread
std::map< int, std::shared_ptr< Socket > > _sockets
 Remote rank -> socket map.
SocketSendQueue _queue

Detailed Description

Implements Communication by using sockets.

Definition at line 20 of file SocketCommunication.hpp.

Member Typedef Documentation

◆ IOContext

using precice::com::SocketCommunication::IOContext = boost::asio::io_context
private

Definition at line 143 of file SocketCommunication.hpp.

◆ Socket

using precice::com::SocketCommunication::Socket = boost::asio::ip::tcp::socket
private

Definition at line 144 of file SocketCommunication.hpp.

◆ WorkGuard

using precice::com::SocketCommunication::WorkGuard = boost::asio::executor_work_guard<IOContext::executor_type>
private

Definition at line 145 of file SocketCommunication.hpp.

Constructor & Destructor Documentation

◆ SocketCommunication() [1/2]

precice::com::SocketCommunication::SocketCommunication ( unsigned short portNumber = 0,
bool reuseAddress = false,
std::string networkName = utils::networking::loopbackInterfaceName(),
std::string addressDirectory = "." )

Definition at line 24 of file SocketCommunication.cpp.

◆ SocketCommunication() [2/2]

precice::com::SocketCommunication::SocketCommunication ( std::string const & addressDirectory)
explicit

Definition at line 39 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ ~SocketCommunication()

precice::com::SocketCommunication::~SocketCommunication ( )
override

Definition at line 44 of file SocketCommunication.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ acceptConnection()

void precice::com::SocketCommunication::acceptConnection ( std::string const & acceptorName,
std::string const & requesterName,
std::string const & tag,
int acceptorRank,
int rankOffset = 0 )
override

Definition at line 57 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ acceptConnectionAsServer()

void precice::com::SocketCommunication::acceptConnectionAsServer ( std::string const & acceptorName,
std::string const & requesterName,
std::string const & tag,
int acceptorRank,
int requesterCommunicatorSize )
override

Definition at line 141 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ aReceive() [1/4]

PtrRequest precice::com::SocketCommunication::aReceive ( bool & itemToReceive,
Rank rankSender )
override

Asynchronously receives a bool from process with given rank.

Definition at line 699 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ aReceive() [2/4]

PtrRequest precice::com::SocketCommunication::aReceive ( double & itemToReceive,
Rank rankSender )
override

Asynchronously receives a double from process with given rank.

Definition at line 637 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ aReceive() [3/4]

PtrRequest precice::com::SocketCommunication::aReceive ( int & itemToReceive,
Rank rankSender )
override

Asynchronously receives an int from process with given rank.

Definition at line 658 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ aReceive() [4/4]

PtrRequest precice::com::SocketCommunication::aReceive ( precice::span< double > itemsToReceive,
int rankSender )
override

Asynchronously receives an array of double values.

Definition at line 596 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ aSend() [1/5]

PtrRequest precice::com::SocketCommunication::aSend ( const bool & itemToSend,
Rank rankReceiver )
override

Asynchronously sends a bool to process with given rank.

Definition at line 524 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ aSend() [2/5]

PtrRequest precice::com::SocketCommunication::aSend ( const double & itemToSend,
Rank rankReceiver )
override

Asynchronously sends a double to process with given rank.

Definition at line 482 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ aSend() [3/5]

PtrRequest precice::com::SocketCommunication::aSend ( const int & itemToSend,
Rank rankReceiver )
override

Asynchronously sends an int to process with given rank.

Definition at line 503 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ aSend() [4/5]

PtrRequest precice::com::SocketCommunication::aSend ( precice::span< const double > itemsToSend,
Rank rankReceiver )
override

Asynchronously sends an array of double values.

Definition at line 447 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ aSend() [5/5]

PtrRequest precice::com::SocketCommunication::aSend ( precice::span< const int > itemsToSend,
Rank rankReceiver )
override

Asynchronously sends an array of integer values.

Definition at line 412 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ cleanupEstablishment()

void precice::com::SocketCommunication::cleanupEstablishment ( std::string const & acceptorName,
std::string const & requesterName )
override

Definition at line 399 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ closeConnection()

void precice::com::SocketCommunication::closeConnection ( )
override

Definition at line 325 of file SocketCommunication.cpp.

◆ getIpAddress()

std::string precice::com::SocketCommunication::getIpAddress ( )
private

Definition at line 774 of file SocketCommunication.cpp.

◆ getRemoteCommunicatorSize()

size_t precice::com::SocketCommunication::getRemoteCommunicatorSize ( )
override

Definition at line 50 of file SocketCommunication.cpp.

◆ isClient()

bool precice::com::SocketCommunication::isClient ( )
private

◆ isServer()

bool precice::com::SocketCommunication::isServer ( )
private

◆ prepareEstablishment()

void precice::com::SocketCommunication::prepareEstablishment ( std::string const & acceptorName,
std::string const & requesterName )
override

Definition at line 386 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ receive() [1/6]

void precice::com::SocketCommunication::receive ( bool & itemToReceive,
Rank rankSender )
override

Receives a bool from process with given rank.

Definition at line 683 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ receive() [2/6]

void precice::com::SocketCommunication::receive ( double & itemToReceive,
Rank rankSender )
override

Receives a double from process with given rank.

Definition at line 621 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ receive() [3/6]

void precice::com::SocketCommunication::receive ( int & itemToReceive,
Rank rankSender )
override

Receives an int from process with given rank.

Definition at line 642 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ receive() [4/6]

void precice::com::SocketCommunication::receive ( precice::span< double > itemsToReceive,
Rank rankSender )
override

Receives an array of double values.

Definition at line 580 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ receive() [5/6]

void precice::com::SocketCommunication::receive ( precice::span< int > itemsToReceive,
Rank rankSender )
override

Receives an array of integer values.

Definition at line 564 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ receive() [6/6]

void precice::com::SocketCommunication::receive ( std::string & itemToReceive,
Rank rankSender )
override

Receives a std::string from process with given rank.

Definition at line 543 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ requestConnection()

void precice::com::SocketCommunication::requestConnection ( std::string const & acceptorName,
std::string const & requesterName,
std::string const & tag,
int requesterRank,
int requesterCommunicatorSize )
override

Definition at line 206 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ requestConnectionAsClient()

void precice::com::SocketCommunication::requestConnectionAsClient ( std::string const & acceptorName,
std::string const & requesterName,
std::string const & tag,
std::set< int > const & acceptorRanks,
int requesterRank )
override

Definition at line 267 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ send() [1/6]

void precice::com::SocketCommunication::send ( bool itemToSend,
Rank rankReceiver )
override

Sends a bool to process with given rank.

Definition at line 508 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ send() [2/6]

void precice::com::SocketCommunication::send ( double itemToSend,
Rank rankReceiver )
override

Sends a double to process with given rank.

Definition at line 466 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ send() [3/6]

void precice::com::SocketCommunication::send ( int itemToSend,
Rank rankReceiver )
override

Sends an int to process with given rank.

Definition at line 487 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ send() [4/6]

void precice::com::SocketCommunication::send ( precice::span< const double > itemsToSend,
Rank rankReceiver )
override

Sends an array of double values.

Definition at line 431 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ send() [5/6]

void precice::com::SocketCommunication::send ( precice::span< const int > itemsToSend,
Rank rankReceiver )
override

Sends an array of integer values.

Definition at line 370 of file SocketCommunication.cpp.

Here is the call graph for this function:

◆ send() [6/6]

void precice::com::SocketCommunication::send ( std::string const & itemToSend,
Rank rankReceiver )
override

Sends a std::string to process with given rank.

Definition at line 352 of file SocketCommunication.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ _addressDirectory

std::string precice::com::SocketCommunication::_addressDirectory
private

Directory where IP address is exchanged by file.

Definition at line 141 of file SocketCommunication.hpp.

◆ _ioContext

std::shared_ptr<IOContext> precice::com::SocketCommunication::_ioContext
private

Definition at line 147 of file SocketCommunication.hpp.

◆ _log

logging::Logger precice::com::SocketCommunication::_log {"com::SocketCommunication"}
private

Definition at line 130 of file SocketCommunication.hpp.

◆ _networkName

std::string precice::com::SocketCommunication::_networkName
private

Name of network to communicate over.

Definition at line 138 of file SocketCommunication.hpp.

◆ _portNumber

unsigned short precice::com::SocketCommunication::_portNumber
private

Port used for socket connection.

Definition at line 133 of file SocketCommunication.hpp.

◆ _queue

SocketSendQueue precice::com::SocketCommunication::_queue
private

Definition at line 154 of file SocketCommunication.hpp.

◆ _reuseAddress

bool precice::com::SocketCommunication::_reuseAddress
private

Definition at line 135 of file SocketCommunication.hpp.

◆ _sockets

std::map<int, std::shared_ptr<Socket> > precice::com::SocketCommunication::_sockets
private

Remote rank -> socket map.

Definition at line 152 of file SocketCommunication.hpp.

◆ _thread

std::thread precice::com::SocketCommunication::_thread
private

Definition at line 149 of file SocketCommunication.hpp.

◆ _workGuard

std::unique_ptr<WorkGuard> precice::com::SocketCommunication::_workGuard
private

Definition at line 148 of file SocketCommunication.hpp.


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