1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/app/mcast/Transport.hpp" 4 #include "hmbdc/app/mcast/Messages.hpp" 5 #include "hmbdc/app/Base.hpp" 6 #include "hmbdc/pattern/MonoLockFreeBuffer.hpp" 7 #include "hmbdc/time/Time.hpp" 8 #include "hmbdc/time/Rater.hpp" 9 #include "hmbdc/numeric/BitMath.hpp" 11 #include <boost/regex.hpp> 16 #include <sys/epoll.h> 17 namespace hmbdc {
namespace app {
namespace mcast {
19 namespace sendtransportengine_detail {
27 using ptr = std::shared_ptr<SendTransport>;
31 bool match(
Topic const& t)
const {
32 return boost::regex_match(t.c_str(), topicRegex_);
35 template <
typename... Messages>
36 void queue(
Topic const& t, Messages&&... msgs) {
37 auto n =
sizeof...(msgs);
38 auto it = buffer_.claim(n);
39 queue(it, t, std::forward<Messages>(msgs)...);
40 buffer_.commit(it, n);
43 template <
typename... Messages>
44 bool tryQueue(
Topic const& t, Messages&&... msgs) {
45 auto n =
sizeof...(msgs);
46 auto it = buffer_.tryClaim(n);
48 queue(it, t, std::forward<Messages>(msgs)...);
49 buffer_.commit(it, n);
55 template <
typename Message,
typename ... Args>
56 void queueInPlace(
Topic const& t, Args&&... args) {
57 auto s = buffer_.claim();
58 char* addr =
static_cast<char*
>(*s);
62 if (hmbdc_likely(
sizeof(Message) <= maxMessageSize_)) {
66 HMBDC_THROW(std::out_of_range
67 ,
"maxMessageSize too small to hold a message when constructing SendTransportEngine");
72 void queueBytes(
Topic const& t, uint16_t tag,
void const* bytes,
size_t len);
74 void runOnce(
bool alwaysPoll =
false) HMBDC_RESTRICT {
76 if (hmbdc_unlikely(alwaysPoll || !isFdReady())) {
77 utils::EpollTask::instance().poll();
85 boost::regex topicRegex_;
86 size_t maxMessageSize_;
93 size_t toSendMsgsHead_;
94 size_t toSendMsgsTail_;
96 size_t toSendPktsHead_;
97 size_t toSendPktsTail_;
100 outBufferSizePower2();
102 template<
typename M,
typename ... Messages>
104 , M&& m, Messages&&... msgs) {
105 using Message =
typename std::remove_reference<M>::type;
107 char* addr =
static_cast<char*
>(s);
111 if (hmbdc_likely(
sizeof(Message) <= maxMessageSize_)) {
115 HMBDC_THROW(std::out_of_range
116 ,
"maxMessageSize too small to hold a message when constructing SendTransportEngine");
118 queue(++it, t, std::forward<Messages>(msgs)...);
128 ,
Client<SendTransportEngine> {
129 using SendTransport::SendTransport;
130 using SendTransport::hmbdcName;
131 using SendTransport::schedSpec;
Definition: MonoLockFreeBuffer.hpp:15
class to hold an hmbdc configuration
Definition: Config.hpp:44
Definition: SendTransportEngine.hpp:25
topic as in the publish / subscribe communication paradigm
Definition: Topic.hpp:14
Definition: TypedString.hpp:74
Definition: BlockingBuffer.hpp:11
void invokedCb(uint16_t) HMBDC_RESTRICT override
this callback is called all the time (frequently) - the exact timing is after a batch of messages are...
Definition: SendTransportEngine.hpp:134
Definition: Message.hpp:72
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:47
Definition: Transport.hpp:43
Definition: SendTransportEngine.hpp:126
bool droppedCb() override
callback called after the Client is safely taken out of the Context
Definition: SendTransportEngine.hpp:137
Definition: LockFreeBufferMisc.hpp:74