Q : "Or should I switch to ZeroMQ for my requirement?"
This last question seems, in the contrast to the prior two, decidable for me. Let's try it:
One may opt to use either a younger, lighweight nanomsg or the fully-fledged, many more inter-operational protocols ready zeromq, though given just the inproc://
-transport-class was mentioned, the latter may seem over-equipped for the task.
If just this transport-class is needed, one may instantiate data-pumps as purely I/O-thread-less Context()
-instances, using an explicit request to do so :
#define Zero_IO_threads 0
void *myCtx = zmq_ctx_new ( Zero_IO_threads );
assert ( myCtx && "FAILED: zmq_ctx_new ( ... )" );
zmq_ctx_set ( myCtx, ZMQ_BLOCKY, false );
void *aPubSocket = zmq_socket ( myCtx, ZMQ_PUB );
assert ( aPubSocket && "FAILED: zmq_socket ( ... )" );
...
void *aSubSocket = zmq_socket ( myCtx, ZMQ_SUB );
assert ( aSubSocket && "FAILED: zmq_socket ( ... )" );
rc = zmq_setsockopt ( aSubSocket, ZMQ_SUBSCRIBE, "", 0 );
assert ( rc == 0 && "FAILED: zmq_setsockopt ( aSubSocket, ... )" );
...
rc = zmq_bind ( aPubSocket, "inproc://#A" ); // Def inproc name "#A"
assert ( rc == 0 && "FAILED: zmq_bind ( aPubSocket, ... )" );
...
rc = zmq_connect ( aSubSocket, "inproc://#A"); // Try connect to #A
assert ( rc == 0 && "FAILED: zmq_connect ( aSubSocket, ... )" );
// ___________________________________________aSubSocket can start receive messages
...
// ___________________________________________FINALLY: gracefully close & terminate
assert ( 0 == zmq_close ( aPubSocket ) && "FAILED: zmq_close( aPubSocket )" );
...
assert ( 0 == zmq_close ( aSubSocket ) && "FAILED: zmq_close( aSubSocket )" );
...
assert ( 0 == zmq_ctx_term ( myCtx ) && "FAILED: zmq_ctx_term( myCtx )" );