mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
feat: Drop public dependency to Boost.Asio and use standalone asio
This commit is contained in:
parent
ac3293fcc6
commit
943b16beff
|
@ -120,7 +120,7 @@ if(BUILD_DOCS)
|
||||||
DESTINATION ${PROJECT_INSTALL_DATADIR}/docs
|
DESTINATION ${PROJECT_INSTALL_DATADIR}/docs
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(BUILD_SDK)
|
if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||||
if(asio_BUNDLED)
|
if(asio_BUNDLED)
|
||||||
install_bundled(asio)
|
install_bundled(asio)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -42,9 +42,6 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||||
find_package2(PUBLIC Boost REQUIRED VERSION 1.66
|
find_package2(PUBLIC Boost REQUIRED VERSION 1.66
|
||||||
COMPONENTS container program_options filesystem date_time regex
|
COMPONENTS container program_options filesystem date_time regex
|
||||||
)
|
)
|
||||||
endif()
|
|
||||||
|
|
||||||
if(BUILD_SDK)
|
|
||||||
set(__asio_version 1.18.1)
|
set(__asio_version 1.18.1)
|
||||||
find_package2(BUNDLED asio VERSION ${__asio_version})
|
find_package2(BUNDLED asio VERSION ${__asio_version})
|
||||||
if(NOT asio_FOUND AND NOT asio_BUNDLED)
|
if(NOT asio_FOUND AND NOT asio_BUNDLED)
|
||||||
|
|
|
@ -49,12 +49,6 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||||
)
|
)
|
||||||
target_compile_features(${target} PUBLIC cxx_std_17)
|
target_compile_features(${target} PUBLIC cxx_std_17)
|
||||||
target_compile_definitions(${target} PUBLIC BOOST_ERROR_CODE_HEADER_ONLY)
|
target_compile_definitions(${target} PUBLIC BOOST_ERROR_CODE_HEADER_ONLY)
|
||||||
# workaround https://github.com/boostorg/asio/commit/43874d5497414c67655d901e48c939ef01337edb
|
|
||||||
if( Boost_VERSION VERSION_LESS 1.69
|
|
||||||
AND CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
|
|
||||||
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0.1)
|
|
||||||
target_compile_definitions(${target} PUBLIC BOOST_ASIO_HAS_STD_STRING_VIEW)
|
|
||||||
endif()
|
|
||||||
target_include_directories(${target}
|
target_include_directories(${target}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
|
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
|
||||||
|
@ -64,8 +58,9 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||||
PRIVATE
|
PRIVATE
|
||||||
FairLogger::FairLogger
|
FairLogger::FairLogger
|
||||||
Threads::Threads
|
Threads::Threads
|
||||||
PUBLIC
|
|
||||||
Boost::boost
|
Boost::boost
|
||||||
|
PUBLIC
|
||||||
|
asio::asio
|
||||||
)
|
)
|
||||||
set_target_properties(${target} PROPERTIES
|
set_target_properties(${target} PROPERTIES
|
||||||
VERSION ${PROJECT_VERSION}
|
VERSION ${PROJECT_VERSION}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <boost/algorithm/string/join.hpp>
|
#include <boost/algorithm/string/join.hpp>
|
||||||
#include <boost/algorithm/string/split.hpp>
|
#include <boost/algorithm/string/split.hpp>
|
||||||
#include <boost/algorithm/string/classification.hpp>
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
#include <boost/asio/post.hpp>
|
#include <asio/post.hpp>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -243,7 +243,7 @@ auto DDS::SubscribeForConnectingChannels() -> void
|
||||||
string channelName = key.substr(8);
|
string channelName = key.substr(8);
|
||||||
LOG(info) << "Update for channel name: " << channelName;
|
LOG(info) << "Update for channel name: " << channelName;
|
||||||
|
|
||||||
boost::asio::post(fWorkerQueue, [=]() {
|
asio::post(fWorkerQueue, [=]() {
|
||||||
try {
|
try {
|
||||||
{
|
{
|
||||||
unique_lock<mutex> lk(fUpdateMutex);
|
unique_lock<mutex> lk(fUpdateMutex);
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
#include <dds/dds.h>
|
#include <dds/dds.h>
|
||||||
|
|
||||||
#include <boost/asio/executor.hpp>
|
#include <asio/executor.hpp>
|
||||||
#include <boost/asio/executor_work_guard.hpp>
|
#include <asio/executor_work_guard.hpp>
|
||||||
#include <boost/asio/io_context.hpp>
|
#include <asio/io_context.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
@ -166,8 +166,8 @@ class DDS : public Plugin
|
||||||
std::condition_variable fUpdateCondition;
|
std::condition_variable fUpdateCondition;
|
||||||
|
|
||||||
std::thread fWorkerThread;
|
std::thread fWorkerThread;
|
||||||
boost::asio::io_context fWorkerQueue;
|
asio::io_context fWorkerQueue;
|
||||||
boost::asio::executor_work_guard<boost::asio::executor> fWorkGuard;
|
asio::executor_work_guard<asio::executor> fWorkGuard;
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin::ProgOptions DDSProgramOptions()
|
Plugin::ProgOptions DDSProgramOptions()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2017-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
@ -10,31 +10,28 @@
|
||||||
#include <fairmq/tools/Network.h>
|
#include <fairmq/tools/Network.h>
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
#define _GNU_SOURCE // To get defns of NI_MAXSERV and NI_MAXHOST
|
#define _GNU_SOURCE // To get defns of NI_MAXSERV and NI_MAXHOST
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp> // trim
|
|
||||||
#include <boost/asio.hpp>
|
|
||||||
|
|
||||||
#include <ifaddrs.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <boost/algorithm/string.hpp> // trim
|
||||||
|
#include <boost/asio.hpp>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <ifaddrs.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <netdb.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace fair::mq::tools
|
namespace fair::mq::tools {
|
||||||
{
|
|
||||||
|
|
||||||
// returns a map with network interface names as keys and their IP addresses as values
|
// returns a map with network interface names as keys and their IP addresses as values
|
||||||
map<string, string> getHostIPs()
|
map<string, string> getHostIPs()
|
||||||
|
@ -56,7 +53,13 @@ map<string, string> getHostIPs()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ifa->ifa_addr->sa_family == AF_INET) {
|
if (ifa->ifa_addr->sa_family == AF_INET) {
|
||||||
s = getnameinfo(ifa->ifa_addr, sizeof(sockaddr_in), host.data(), NI_MAXHOST, nullptr, 0, NI_NUMERICHOST);
|
s = getnameinfo(ifa->ifa_addr,
|
||||||
|
sizeof(sockaddr_in),
|
||||||
|
host.data(),
|
||||||
|
NI_MAXHOST,
|
||||||
|
nullptr,
|
||||||
|
0,
|
||||||
|
NI_NUMERICHOST);
|
||||||
if (s != 0) {
|
if (s != 0) {
|
||||||
cout << "getnameinfo() failed: " << gai_strerror(s) << endl;
|
cout << "getnameinfo() failed: " << gai_strerror(s) << endl;
|
||||||
throw runtime_error("getnameinfo() failed");
|
throw runtime_error("getnameinfo() failed");
|
||||||
|
@ -79,7 +82,8 @@ string getInterfaceIP(const string& interface)
|
||||||
if (IPs.count(interface) > 0) {
|
if (IPs.count(interface) > 0) {
|
||||||
return IPs[interface];
|
return IPs[interface];
|
||||||
}
|
}
|
||||||
LOG(error) << "Could not find provided network interface: \"" << interface << "\"!, exiting.";
|
LOG(error) << "Could not find provided network interface: \""
|
||||||
|
<< interface << "\"!, exiting.";
|
||||||
return "";
|
return "";
|
||||||
} catch (runtime_error& re) {
|
} catch (runtime_error& re) {
|
||||||
cout << "could not get interface IP: " << re.what();
|
cout << "could not get interface IP: " << re.what();
|
||||||
|
@ -94,9 +98,10 @@ string getDefaultRouteNetworkInterface()
|
||||||
array<char, BUFSIZE> buffer{};
|
array<char, BUFSIZE> buffer{};
|
||||||
string interfaceName;
|
string interfaceName;
|
||||||
|
|
||||||
#ifdef __APPLE__ // MacOS
|
#ifdef __APPLE__ // MacOS
|
||||||
unique_ptr<FILE, decltype(pclose) *> file(popen("route -n get default | grep interface | cut -d \":\" -f 2", "r"), pclose);
|
unique_ptr<FILE, decltype(pclose)*> file(
|
||||||
#else // Linux
|
popen("route -n get default | grep interface | cut -d \":\" -f 2", "r"), pclose);
|
||||||
|
#else // Linux
|
||||||
ifstream is("/proc/net/route");
|
ifstream is("/proc/net/route");
|
||||||
string line;
|
string line;
|
||||||
|
|
||||||
|
@ -114,14 +119,17 @@ string getDefaultRouteNetworkInterface()
|
||||||
|
|
||||||
if (line.substr(pos + 1, 8) == "00000000") {
|
if (line.substr(pos + 1, 8) == "00000000") {
|
||||||
interfaceName = line.substr(0, pos);
|
interfaceName = line.substr(0, pos);
|
||||||
LOG(debug) << "Detected network interface name for the default route: " << interfaceName;
|
LOG(debug) << "Detected network interface name for the default route: "
|
||||||
|
<< interfaceName;
|
||||||
return interfaceName;
|
return interfaceName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(debug) << "could not get network interface of the default route from /proc/net/route, going to try via 'ip route'";
|
LOG(debug) << "could not get network interface of the default route from /proc/net/route, "
|
||||||
|
"going to try via 'ip route'";
|
||||||
|
|
||||||
unique_ptr<FILE, decltype(pclose) *> file(popen("ip route | grep default | cut -d \" \" -f 5 | head -n 1", "r"), pclose);
|
unique_ptr<FILE, decltype(pclose)*> file(
|
||||||
|
popen("ip route | grep default | cut -d \" \" -f 5 | head -n 1", "r"), pclose);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
|
@ -138,8 +146,10 @@ string getDefaultRouteNetworkInterface()
|
||||||
boost::algorithm::trim(interfaceName);
|
boost::algorithm::trim(interfaceName);
|
||||||
|
|
||||||
if (interfaceName.empty()) {
|
if (interfaceName.empty()) {
|
||||||
LOG(debug) << "Could not detect default route network interface name from /proc/net/route nor 'ip route'";
|
LOG(debug) << "Could not detect default route network interface name from /proc/net/route "
|
||||||
throw DefaultRouteDetectionError("Could not detect default route network interface name from /proc/net/route nor 'ip route'");
|
"nor 'ip route'";
|
||||||
|
throw DefaultRouteDetectionError("Could not detect default route network interface name "
|
||||||
|
"from /proc/net/route nor 'ip route'");
|
||||||
} else {
|
} else {
|
||||||
LOG(debug) << "Detected network interface name for the default route: " << interfaceName;
|
LOG(debug) << "Detected network interface name for the default route: " << interfaceName;
|
||||||
}
|
}
|
||||||
|
@ -149,25 +159,22 @@ string getDefaultRouteNetworkInterface()
|
||||||
|
|
||||||
string getIpFromHostname(const string& hostname)
|
string getIpFromHostname(const string& hostname)
|
||||||
{
|
{
|
||||||
boost::asio::io_service ios;
|
boost::asio::io_context ioc;
|
||||||
return getIpFromHostname(hostname, ios);
|
|
||||||
}
|
using namespace boost::asio::ip;
|
||||||
|
|
||||||
string getIpFromHostname(const string& hostname, boost::asio::io_service& ios)
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
namespace bai = boost::asio::ip;
|
tcp::resolver resolver(ioc);
|
||||||
bai::tcp::resolver resolver(ios);
|
tcp::resolver::query query(hostname, "");
|
||||||
bai::tcp::resolver::query query(hostname, "");
|
tcp::resolver::iterator end;
|
||||||
bai::tcp::resolver::iterator end;
|
|
||||||
|
|
||||||
auto it = find_if(static_cast<bai::basic_resolver_iterator<bai::tcp>>(resolver.resolve(query)), end, [](const bai::tcp::endpoint& ep) {
|
auto it = find_if(static_cast<basic_resolver_iterator<tcp>>(resolver.resolve(query)),
|
||||||
return ep.address().is_v4();
|
end,
|
||||||
});
|
[](const tcp::endpoint& ep) { return ep.address().is_v4(); });
|
||||||
|
|
||||||
if (it != end) {
|
if (it != end) {
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss << static_cast<bai::tcp::endpoint>(*it).address();
|
ss << static_cast<tcp::endpoint>(*it).address();
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,4 +187,4 @@ string getIpFromHostname(const string& hostname, boost::asio::io_service& ios)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace fair::mq::tools
|
} // namespace fair::mq::tools
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2017-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
@ -13,18 +13,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
// forward declarations
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
namespace asio
|
|
||||||
{
|
|
||||||
|
|
||||||
class io_context;
|
|
||||||
using io_service = class io_context;
|
|
||||||
|
|
||||||
} // namespace asio
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
namespace fair::mq::tools
|
namespace fair::mq::tools
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -41,8 +29,6 @@ std::string getDefaultRouteNetworkInterface();
|
||||||
|
|
||||||
std::string getIpFromHostname(const std::string& hostname);
|
std::string getIpFromHostname(const std::string& hostname);
|
||||||
|
|
||||||
std::string getIpFromHostname(const std::string& hostname, boost::asio::io_service& ios);
|
|
||||||
|
|
||||||
} // namespace fair::mq::tools
|
} // namespace fair::mq::tools
|
||||||
|
|
||||||
#endif /* FAIR_MQ_TOOLS_NETWORK_H */
|
#endif /* FAIR_MQ_TOOLS_NETWORK_H */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user