1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/tips/tcpcast/Transport.hpp" 4 #include "hmbdc/tips/tcpcast/RecvSession.hpp" 5 #include "hmbdc/tips/tcpcast/Messages.hpp" 6 #include "hmbdc/tips/tcpcast/DefaultUserConfig.hpp" 7 #include "hmbdc/tips/udpcast/RecvTransportEngine.hpp" 8 #include "hmbdc/app/Logger.hpp" 10 #include <boost/bind.hpp> 11 #include <boost/lexical_cast.hpp> 12 #include <boost/unordered_map.hpp> 18 namespace hmbdc {
namespace tips {
namespace tcpcast {
25 using Transport::Transport;
29 namespace recvtransportengine_detail {
30 template <
typename OutputBuffer,
typename AttachmentAllocator>
48 , OutputBuffer& outputBuffer)
49 :
RecvTransport(((cfg.setAdditionalFallbackConfig(
hmbdc::app::Config(DefaultUserConfig))
50 , cfg.resetSection(
"rx", false))))
51 ,
hmbdc::time::ReoccuringTimer(
hmbdc::time::Duration::seconds(cfg.getExt<size_t>(
"heartbeatPeriodSeconds")))
55 , config_.getExt<uint16_t>(
"cmdBufferSizePower2"))
56 , outputBuffer_(outputBuffer)
57 , maxItemSize_(outputBuffer.maxItemSize())
58 , myIp_(inet_addr(hmbdc::comm::inet::getLocalIpMatchMask(
59 config_.getExt<std::string>(
"ifaceAddr")).c_str())) {
60 if (!config_.
getExt<
bool>(
"allowRecvWithinProcess")) {
65 HMBDC_THROW(std::out_of_range
66 ,
"buffer is too small for notification: SessionStarted and SessionDropped");
68 mcConfig_.
put(
"outBufferSizePower2", 3u);
69 mcReceiver_.emplace(mcConfig_, buffer_);
70 mcReceiver_->template subscribe<TypeTagSource>();
74 for (
auto& s : recvSessions_) {
75 s.second->heartbeat();
80 schedule(hmbdc::time::SysTime::now(), *
this);
84 this->checkTimers(hmbdc::time::SysTime::now());
88 using Transport::hmbdcName;
89 using Transport::schedSpec;
98 HMBDC_LOG_C(e.what());
107 for (
auto it = recvSessions_.begin(); it != recvSessions_.end();) {
108 if (hmbdc_unlikely(!(*it).second->runOnce())) {
109 (*it).second->stop();
110 recvSessions_.erase(it++);
116 auto n = buffer_.peek(begin, end);
123 mcReceiver_->runOnce(
true);
131 return recvSessions_.size();
134 template <MessageTupleC Messages,
typename CcNode>
135 void subscribeFor(CcNode
const& node, uint16_t mod, uint16_t res) {
136 subscriptions_.markSubsFor<Messages>(node, mod, res);
143 auto ip = inet_addr(t.ip);
149 if (t.srcPid == myPid_ && ip == myIp_)
return;
150 auto key = std::make_pair(ip, t.port);
151 if (recvSessions_.find(key) == recvSessions_.end()) {
152 for (
auto i = 0u; i < t.typeTagCountContained; ++i) {
153 if (subscriptions_.check(t.typeTags[i])) {
160 sess->start(ip, t.port);
161 recvSessions_[key] =
typename Session::ptr(sess);
162 }
catch (std::exception
const& e) {
163 HMBDC_LOG_C(e.what());
176 OutputBuffer& outputBuffer_;
178 std::optional<udpcast::RecvTransportImpl<decltype(buffer_)>> mcReceiver_;
181 boost::unordered_map<std::pair<uint64_t, uint16_t>
182 ,
typename Session::ptr> recvSessions_;
188 template <
typename OutputBuffer,
typename AttachmentAllocator>
189 using RecvTransportEngine = recvtransportengine_detail::RecvTransportEngine<OutputBuffer, AttachmentAllocator>;
T getExt(const path_type ¶m, bool throwIfMissing=true) const
get a value from the config
Definition: Config.hpp:238
Definition: MonoLockFreeBuffer.hpp:16
interface to power a tcpcast transport receiving functions
Definition: RecvTransportEngine.hpp:23
class to hold an hmbdc configuration
Definition: Config.hpp:44
void invokedCb(size_t) HMBDC_RESTRICT override
power the io_service and other things
Definition: RecvTransportEngine.hpp:106
Definition: TypedString.hpp:84
Definition: Timers.hpp:70
void handleMessageCb(TypeTagSource const &t)
only used by MD
Definition: RecvTransportEngine.hpp:142
Definition: Transport.hpp:65
this message tipsears in the receiver's buffer indicating a previously connected source is dropped ...
Definition: Messages.hpp:120
Definition: RecvSession.hpp:24
RecvTransportEngine(hmbdc::app::Config cfg, OutputBuffer &outputBuffer)
ctor
Definition: RecvTransportEngine.hpp:47
Definition: MessageDispacher.hpp:184
void stoppedCb(std::exception const &e) override
should not htipsen ever unless an exception thrown
Definition: RecvTransportEngine.hpp:97
Definition: Message.hpp:212
void schedule(SysTime fireAt, Timer &timer)
schedule the timer to start at a specific time
Definition: Timers.hpp:79
Definition: Message.hpp:263
Config & put(Args &&... args)
forward the call to ptree's put but return Configure
Definition: Config.hpp:194
A Client represents a thread of execution/a task. The execution is managed by a Context. a Client object could participate in message dispatching as the receiver of specifed message types.
Definition: Client.hpp:128
Definition: RecvTransportEngine.hpp:31
void wasteAfterPeek(iterator, size_t, bool=false)
if size not matching - please refer to the impl for details
Definition: MonoLockFreeBuffer.hpp:160
Definition: Timers.hpp:117
this message tipsears in the receiver's buffer indicating a new source is connected ...
Definition: Messages.hpp:106
size_t sessionsRemainingActive() const
check how many other parties are sending to this engine
Definition: RecvTransportEngine.hpp:130
Definition: LockFreeBufferMisc.hpp:89