1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/app/utils/EpollTask.hpp" 5 #include "hmbdc/app/Base.hpp" 6 #include "hmbdc/text/StringTrieSet.hpp" 7 #include "hmbdc/comm/Topic.hpp" 8 #include "hmbdc/comm/inet/Misc.hpp" 9 #include "hmbdc/time/Timers.hpp" 10 #include "hmbdc/pattern/MonoLockFreeBuffer.hpp" 12 #include <boost/regex.hpp> 17 #include <sys/types.h> 18 #include <sys/socket.h> 19 #include <netinet/in.h> 20 #include <arpa/inet.h> 22 namespace hmbdc {
namespace app {
namespace tcpcast {
27 fd = socket(AF_INET, SOCK_STREAM, 0);
29 HMBDC_THROW(std::runtime_error,
"failed to create socket, errno=" << errno);
32 int flags = fcntl(fd, F_GETFL, 0);
34 if (fcntl(fd, F_SETFL, flags) < 0) {
35 HMBDC_THROW(std::runtime_error,
"fcntl failed errno=" << errno);
38 localAddr.sin_family = AF_INET;
39 localAddr.sin_addr.s_addr = inet_addr(hmbdc::comm::inet::getLocalIpMatchMask(
40 cfg.
getExt<std::string>(
"ifaceAddr")).c_str());
41 localAddr.sin_port = htons(cfg.
getExt<uint16_t>(
"tcpPort"));
42 if (bind(fd, (sockaddr*)&localAddr,
sizeof(localAddr)) < 0) {
43 HMBDC_THROW(std::runtime_error,
"failed to bind, errno=" << errno);
46 auto addrLen = socklen_t(
sizeof(localAddr));
47 if (getsockname(fd, (sockaddr*)&localAddr, &addrLen) < 0) {
48 HMBDC_THROW(std::runtime_error,
"getsockname failure, errno=" << errno);
51 char ipaddr[INET_ADDRSTRLEN];
52 if (!inet_ntop(AF_INET, &(localAddr.sin_addr), ipaddr, INET_ADDRSTRLEN)) {
53 HMBDC_THROW(std::runtime_error,
"failed to inet_ntop, errno=" << errno);
56 localPort = htons(localAddr.sin_port);
59 sockaddr_in localAddr;
65 using ptr = std::shared_ptr<Transport>;
69 , tcpcastAdTopic_(
"tcpcastad") {
70 cfg (hmbdcName_,
"hmbdcName")
71 (schedPolicy_,
"schedPolicy")
72 (schedPriority_,
"schedPriority")
76 char const* hmbdcName()
const {
77 return this->hmbdcName_.c_str();
80 std::tuple<char const*, int> schedSpec()
const {
81 return std::make_tuple(this->schedPolicy_.c_str(), this->schedPriority_);
84 bool operator == (
Transport const& other )
const {
85 return &config_ == &other.config_;
88 bool operator < (
Transport const& other )
const {
89 return &config_ < &other.config_;
97 Topic const tcpcastAdTopic_;
100 std::string hmbdcName_;
101 std::string schedPolicy_;
class to hold an hmbdc configuration
Definition: Config.hpp:44
topic as in the publish / subscribe communication paradigm
Definition: Topic.hpp:14
T getExt(const path_type ¶m) const
get a value from the config
Definition: Config.hpp:154
Definition: EpollTask.hpp:31
Definition: Transport.hpp:64
Definition: Transport.hpp:24