a singleton that holding netmap resources
More...
#include <NetContext.hpp>
|
template<typename CcContext > |
| NetContext (CcContext &ctx, Config::Base const *cfgIn=nullptr, char const *sendSec=nullptr, char const *recvSec=nullptr, size_t maxMessageSize=0, uint8_t runningUsingThreadIndex=0, char const *listenToTopic="_") |
| this ctor is to create some commonly used basic engine setup to start with. This is private and only meant to be used through SingletonGuardian, see in example chat.cpp Config config; config.put("ifaceAddr", ifaceAddr); config.put("loopback", true); Context<sizeof(ChatMessage)> ctx; SingletonGuardian<tcpcast::NetContext> g(ctx, &config); More...
|
|
| NetContext () |
| this is for users that want finer control of engine creation - from a blank NetContext. More...
|
|
|
struct | hmbdc::pattern::SingletonGuardian< NetContext > |
|
a singleton that holding netmap resources
it manage transport engines see perf-netmap.cpp for usage
◆ NetContext() [1/2]
template<typename CcContext >
hmbdc::app::netmap::NetContext::NetContext |
( |
CcContext & |
ctx, |
|
|
Config::Base const * |
cfgIn = nullptr , |
|
|
char const * |
sendSec = nullptr , |
|
|
char const * |
recvSec = nullptr , |
|
|
size_t |
maxMessageSize = 0 , |
|
|
uint8_t |
runningUsingThreadIndex = 0 , |
|
|
char const * |
listenToTopic = "_" |
|
) |
| |
|
inlineprivate |
this ctor is to create some commonly used basic engine setup to start with. This is private and only meant to be used through SingletonGuardian, see in example chat.cpp
Config config;
config.put("ifaceAddr", ifaceAddr);
config.put("loopback", true);
Context<sizeof(ChatMessage)> ctx;
SingletonGuardian<tcpcast::NetContext> g(ctx, &config);
It creates one send transport engine and/or one recv transport engine based on cfgIn. and run them using a single OS thread indicated by runningUsingThreadIndex If recv engine is created, this method also automaticallly makes the NetContext listen to a default topic (listenToTopic).
- Parameters
-
ctx | a Context that manages the send / recv transport engines, and hold the received messages |
cfgIn | optional Config for the send AND recv transport engines |
sendSec | the section name for send transport engine in above cfgIn, special values: nullptr - create send engine using no section config values "" - do not create send engine |
recvSec | the section name for recv transport engine in above cfgIn nullptr - create recv engine using no section config values "" - do not create recv engine |
maxMessageSize | max message size in bytes to be sent, if 0, uses ctx's maxMessageSize() |
runningUsingThreadIndex | see details above |
- Template Parameters
-
◆ NetContext() [2/2]
hmbdc::app::netmap::NetContext::NetContext |
( |
| ) |
|
|
inlineprivate |
this is for users that want finer control of engine creation - from a blank NetContext.
it does not do anything that the previous ctor does
◆ createRecvTransportEngine()
template<typename Buffer , typename MsgArbitrator = RecvTransport::NoOpArb>
auto hmbdc::app::netmap::NetContext::createRecvTransportEngine |
( |
Config const & |
cfgIn, |
|
|
Buffer & |
buffer, |
|
|
MsgArbitrator && |
arb = RecvTransport::NoOpArb() |
|
) |
| |
|
inline |
construct a send transport and remember it
After this, user is respoonsible to get it started within a hmbdc Context, otherwise the transport is not functioing/running. Don't create the same thing twice
- Parameters
-
cfgIn | jason specifing the transport - see perf-netmap.cpp and hmbdc/app/netmap/DefaultUserConfig.hpp |
buffer | buffer that recv messages go in, normally the one returned by app::Context::buffer() |
arb | optonally an arbitrator to decide which messages to keep and drop if arb is an rvalue, it is passed in value, if an lvalue, passed in as reference; it also supports either netmap packet level (BEFORE topic filtering) or hmbdc message level (AFTER topic filtering) arbitration depending on which one of int operator()(void* bytes, size_t len) and int operator()(TransportMessageHeader const* header) presents in the arb passed in |
- Returns
- a pointer to the Engine
◆ createRecvTransportEngineTuply()
template<typename Buffer , typename ArgsTuple >
auto hmbdc::app::netmap::NetContext::createRecvTransportEngineTuply |
( |
Config const & |
cfg, |
|
|
Buffer & |
buffer, |
|
|
ArgsTuple && |
args |
|
) |
| |
|
inline |
same as above but to provide a unified interface - not preferred
- Returns
- a pointer to the Engine
◆ createSendTransportEngine()
SendTransportEngine* hmbdc::app::netmap::NetContext::createSendTransportEngine |
( |
Config const & |
cfgIn, |
|
|
size_t |
maxMessageSize |
|
) |
| |
|
inline |
construct a send transport and remember it
After this, user is responsible to get it started within a hmbdc Context, otherwise the transport is not functioing/running. Don't create the same thing twice. it might take several seconds (configured by nmResetWaitSec=2) to construct the engine to avoid message losses at the beginning - netmap seems to require that
- Parameters
-
- Returns
- a pointer to the Engine
◆ createSendTransportEngineTuply()
SendTransportEngine* hmbdc::app::netmap::NetContext::createSendTransportEngineTuply |
( |
Config const & |
cfg, |
|
|
size_t |
maxMessageSize, |
|
|
std::tuple<> |
args |
|
) |
| |
|
inline |
same as above but provide an unified interface - not preferred
- Returns
- a pointer to the Engine - don't delete it
◆ getSender()
get (or create for the first time) a Sender - whose function is to send messages on its associated Topic
this operation typically might be slow, so caching the return value is recommended.
- Parameters
-
t | - the Topic that the Sender is for |
◆ listenTo()
void hmbdc::app::netmap::NetContext::listenTo |
( |
comm::Topic const & |
t | ) |
|
|
inline |
This process is interested in a Topic.
Normally the receiving transport covering this topic needs to be created - not necessarily running - before calling this
- Parameters
-
◆ stopListenTo()
void hmbdc::app::netmap::NetContext::stopListenTo |
( |
comm::Topic const & |
t | ) |
|
|
inline |
undo the subscription
- Parameters
-
The documentation for this class was generated from the following file: