1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/tips/rnetmap/Transport.hpp" 4 #include "hmbdc/tips/rnetmap/NmRecvTransport.hpp" 5 #include "hmbdc/tips/rnetmap/BackupRecvSession.hpp" 6 #include "hmbdc/tips/rnetmap/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 rnetmap {
30 namespace recvtransportengine_detail {
32 template <
typename OutputBuffer,
typename AttachmentAllocator>
37 friend struct NetContext;
39 , OutputBuffer& outputBuffer)
42 , config_.getExt<uint16_t>(
"cmdBufferSizePower2"))
43 , outputBuffer_(outputBuffer)
44 , myBackupIp_(inet_addr(hmbdc::comm::inet::getLocalIpMatchMask(
45 config_.getExt<std::string>(
"tcpIfaceAddr") == std::string(
"ifaceAddr")
46 ?config_.getExt<std::string>(
"ifaceAddr"):config_.getExt<std::string>(
"tcpIfaceAddr")
48 , nmRecvTransport_(config_
52 , loopback_(config_.getExt<
bool>(
"loopback")) {
53 subscriptions_.addAll<std::tuple<app::StartMemorySegTrain, app::MemorySeg>>();
54 if (!config_.
getExt<
bool>(
"allowRecvWithinProcess")) {
59 void runOnce() HMBDC_RESTRICT {
60 hmbdc::app::utils::EpollTask::instance().poll();
62 auto n = cmdBuffer_.peek(begin, end);
68 nmRecvTransport_.runOnce();
69 for (
auto it = recvSessions_.begin(); it != recvSessions_.end();) {
70 if (hmbdc_unlikely(!it->second->runOnce())) {
73 ep2SessionDict_.erase(it->second->sendFrom);
74 recvSessions_.erase(it++);
85 auto ip = inet_addr(t.ip);
91 if (t.srcPid == myPid_ && ip == myBackupIp_)
return;
92 auto key = std::make_pair(ip, t.port);
93 if (recvSessions_.find(key) == recvSessions_.end()) {
94 for (
auto i = 0u; i < t.typeTagCountContained; ++i) {
95 if (subscriptions_.check(t.typeTags[i])) {
97 typename Session::ptr sess {
106 sess->start(ip, t.port);
107 recvSessions_[key] = sess;
108 ep2SessionDict_[t.sendFrom] = sess;
109 schedule(hmbdc::time::SysTime::now(), *sess);
110 }
catch (std::exception
const& e) {
111 HMBDC_LOG_C(e.what());
124 return recvSessions_.size();
127 template <MessageTupleC Messages,
typename CcNode>
128 void subscribeFor(CcNode
const& node, uint16_t mod, uint16_t res) {
129 subscriptions_.markSubsFor<Messages>(node, mod, res);
136 OutputBuffer& outputBuffer_;
138 uint64_t myBackupIp_;
140 = boost::unordered_map<uint32_t, typename Session::ptr>;
141 Ep2SessionDict ep2SessionDict_;
142 boost::unordered_map<std::pair<uint64_t, uint16_t>
143 ,
typename Session::ptr> recvSessions_;
149 template <
typename OutputBuffer,
typename AttachmentAllocator>
157 this->checkTimers(hmbdc::time::SysTime::now());
168 HMBDC_LOG_C(e.what());
171 using EngineTransport::hmbdcName;
173 std::tuple<char const*, int> schedSpec()
const {
174 return std::make_tuple(this->schedPolicy_.c_str(), this->schedPriority_);
179 template <
typename OutputBuffer,
typename AttachmentAllocator>
180 using RecvTransportEngine = recvtransportengine_detail::RecvTransportEngine<
181 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
Definition: RecvTransportEngine.hpp:150
class to hold an hmbdc configuration
Definition: Config.hpp:44
void setAdditionalFallbackConfig(Config const &c)
set additional defaults
Definition: Config.hpp:153
Definition: RecvTransportEngine.hpp:33
Definition: Timers.hpp:70
Config & resetSection(char const *section, bool sectionExists=true)
change section name
Definition: Config.hpp:176
impl class
Definition: NmRecvTransport.hpp:25
void stoppedCb(std::exception const &e) override
callback called when this Client is taken out of message dispatching
Definition: RecvTransportEngine.hpp:167
Definition: Transport.hpp:37
void handleMessageCb(TypeTagBackupSource const &t)
only used by MD
Definition: RecvTransportEngine.hpp:84
Definition: MessageDispacher.hpp:184
Definition: Message.hpp:212
Definition: Messages.hpp:116
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:162
void cancel(Timer &timer)
cancel a timer previously scheduled with the TimerManager
Definition: Timers.hpp:90
void schedule(SysTime fireAt, Timer &timer)
schedule the timer to start at a specific time
Definition: Timers.hpp:79
Definition: Message.hpp:263
Definition: RecvTransportEngine.hpp:21
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
size_t sessionsRemainingActive() const
check how many other parties are sending to this engine
Definition: RecvTransportEngine.hpp:123
void wasteAfterPeek(iterator, size_t, bool=false)
if size not matching - please refer to the impl for details
Definition: MonoLockFreeBuffer.hpp:160
Definition: BackupRecvSessionT.hpp:34
Definition: LockFreeBufferMisc.hpp:89