28template <
typename REQ,
typename RESP>
class client {
33 void configure(std::string host,
unsigned port_nr) {
40 bool is_remote_connected() {
return is_connected; }
45 while(!is_connected && retry_count > 0) {
46 CPPLOG(INFO,
"tcp4tlm::client") <<
"retrying connection for " << retry_count-- <<
" times";
50 throw std::runtime_error(
"Retry count exceeded!");
57 unsigned short retry_count;
58 boost::asio::io_context io_service;
59 typename connection<REQ, RESP>::ptr trace_conn;
60 std::atomic<bool> is_connected;
61 bool local_connection;
63#ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS
64 void setup_endpoint(boost::asio::local::stream_protocol::endpoint& ep) {
66 std::string s(
"/tmp/server");
67 s += boost::lexical_cast<std::string>(port ? port : getpid());
68 ep = boost::asio::local::stream_protocol::endpoint(s);
70 ep = boost::asio::local::stream_protocol::endpoint(host);
75 void setup_endpoint(boost::asio::ip::tcp::endpoint& ep) {
76 using boost::asio::ip::tcp;
77 tcp::resolver resolver(io_service);
78 auto results = resolver.resolve(tcp::v4(), host, boost::lexical_cast<std::string>(port));
79 ep = results.begin()->endpoint();
82 void setup_endpoint(boost::asio::ip::udp::endpoint& ep) {
83 using boost::asio::ip::udp;
84 udp::resolver resolver(io_service);
85 auto results = resolver.resolve(udp::v4(), host, boost::lexical_cast<std::string>(port));
86 ep = results.begin()->endpoint();
89 bool is_local_socket(boost::asio::ip::tcp::socket& socket) {
90 return socket.local_endpoint().address() == socket.remote_endpoint().address();
93 bool is_local_socket(boost::asio::ip::udp::socket& socket) {
94 return socket.local_endpoint().address() == socket.remote_endpoint().address();
97#ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS
98 bool is_local_socket(boost::asio::local::stream_protocol::socket& socket) {
return true; }