1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/tips/rmcast/Transport.hpp" 4 #include "hmbdc/tips/rmcast/McRecvTransport.hpp" 5 #include "hmbdc/tips/rmcast/BackupRecvSession.hpp" 6 #include "hmbdc/tips/rmcast/DefaultUserConfig.hpp" 7 #include "hmbdc/tips/reliable/AttBufferAdaptor.hpp" 8 #include "hmbdc/app/Logger.hpp" 9 #include "hmbdc/comm/inet/Hash.hpp" 11 #include <boost/bind.hpp> 12 #include <boost/lexical_cast.hpp> 13 #include <boost/unordered_map.hpp> 17 #include <type_traits> 20 namespace hmbdc {
namespace tips {
namespace rmcast {
34 namespace recvtransportengine_detail {
42 template <
typename OutputBuffer,
typename AttachmentAllocator>
60 , config_.getExt<uint16_t>(
"cmdBufferSizePower2"))
61 , outputBuffer_(outputBuffer)
62 , myBackupIp_(inet_addr(hmbdc::comm::inet::getLocalIpMatchMask(
63 config_.getExt<std::string>(
"tcpIfaceAddr") == std::string(
"ifaceAddr")
64 ?config_.getExt<std::string>(
"ifaceAddr"):config_.getExt<std::string>(
"tcpIfaceAddr")
66 , mcRecvTransport_(config_
70 , loopback_(config_.getExt<
bool>(
"loopback")) {
71 subscriptions_.addAll<std::tuple<app::StartMemorySegTrain, app::MemorySeg>>();
72 if (!config_.
getExt<
bool>(
"allowRecvWithinProcess")) {
82 mcRecvTransport_.start();
85 void runOnce() HMBDC_RESTRICT {
86 hmbdc::app::utils::EpollTask::instance().poll();
88 auto n = cmdBuffer_.peek(begin, end);
94 mcRecvTransport_.runOnce();
95 for (
auto it = recvSessions_.begin(); it != recvSessions_.end();) {
96 if (hmbdc_unlikely(!it->second->runOnce())) {
99 ep2SessionDict_.erase(it->second->sendFrom);
100 recvSessions_.erase(it++);
111 auto ip = inet_addr(t.ip);
113 if (ip == myBackupIp_
117 if (t.srcPid == myPid_ && ip == myBackupIp_)
return;
118 auto key = std::make_pair(ip, t.port);
119 if (recvSessions_.find(key) == recvSessions_.end()) {
120 for (
auto i = 0u; i < t.typeTagCountContained; ++i) {
121 if (subscriptions_.check(t.typeTags[i])) {
123 typename Session::ptr sess {
132 sess->start(ip, t.port);
133 recvSessions_[key] = sess;
134 ep2SessionDict_[t.sendFrom] = sess;
135 schedule(hmbdc::time::SysTime::now(), *sess);
136 }
catch (std::exception
const& e) {
137 HMBDC_LOG_C(e.what());
150 return recvSessions_.size();
153 template <MessageTupleC Messages,
typename CcNode>
154 void subscribeFor(CcNode
const& node, uint16_t mod, uint16_t res) {
155 subscriptions_.markSubsFor<Messages>(node, mod, res);
162 OutputBuffer outputBuffer_;
163 in_addr_t myBackupIp_;
167 = boost::unordered_map<sockaddr_in,
typename Session::ptr
168 , endpointhash, endpointequal>;
169 Ep2SessionDict ep2SessionDict_;
170 boost::unordered_map<std::pair<uint64_t, uint16_t>
171 ,
typename Session::ptr> recvSessions_;
177 template <
typename OutputBuffer,
typename AttachmentAllocator>
186 , OutputBuffer& outputBuffer)
187 :
Impl(cfg, outputBuffer) {
192 if (runLock_.try_lock()) {
193 this->checkTimers(hmbdc::time::SysTime::now());
216 HMBDC_LOG_C(e.what());
219 using EngineTransport::hmbdcName;
221 std::tuple<char const*, int> schedSpec()
const {
222 return std::make_tuple(this->schedPolicy_.c_str(), this->schedPriority_);
226 this->runLock_.unlock();
234 template <
typename OutputBuffer,
typename AttachmentAllocator>
235 using RecvTransportEngine = recvtransportengine_detail::RecvTransportEngine<OutputBuffer
236 , 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
class to hold an hmbdc configuration
Definition: Config.hpp:44
void setAdditionalFallbackConfig(Config const &c)
set additional defaults
Definition: Config.hpp:153
Definition: Messages.hpp:90
impl class
Definition: McRecvTransport.hpp:26
Definition: TypedString.hpp:84
impl class
Definition: RecvTransportEngine.hpp:43
Definition: Timers.hpp:70
Config & resetSection(char const *section, bool sectionExists=true)
change section name
Definition: Config.hpp:176
void stoppedCb(std::exception const &e) override
should not happen ever unless an exception thrown
Definition: RecvTransportEngine.hpp:215
Definition: Transport.hpp:39
Definition: RecvTransportEngine.hpp:178
Definition: MessageDispacher.hpp:184
Definition: Message.hpp:212
RecvTransportImpl(hmbdc::app::Config const &cfg, OutputBuffer &outputBuffer)
ctor
Definition: RecvTransportEngine.hpp:57
void cancel(Timer &timer)
cancel a timer previously scheduled with the TimerManager
Definition: Timers.hpp:90
interface to power a multicast transport receiving functions
Definition: RecvTransportEngine.hpp:25
void invokedCb(size_t) HMBDC_RESTRICT override
this callback is called all the time (frequently) - the exact timing is after a batch of messages are...
Definition: RecvTransportEngine.hpp:205
void schedule(SysTime fireAt, Timer &timer)
schedule the timer to start at a specific time
Definition: Timers.hpp:79
Definition: Message.hpp:263
size_t sessionsRemainingActive() const
check how many other parties are sending to this engine
Definition: RecvTransportEngine.hpp:149
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
void handleMessageCb(TypeTagBackupSource const &t)
only used by MH
Definition: RecvTransportEngine.hpp:110
void wasteAfterPeek(iterator, size_t, bool=false)
if size not matching - please refer to the impl for details
Definition: MonoLockFreeBuffer.hpp:160
void start()
start the show by schedule the mesage recv
Definition: RecvTransportEngine.hpp:81
Definition: BackupRecvSessionT.hpp:34
Definition: LockFreeBufferMisc.hpp:89
void messageDispatchingStartedCb(size_t const *) override
called before any messages got dispatched - only once
Definition: RecvTransportEngine.hpp:200