[zeromq-dev] CZMQ: proposal for wrapping a 0MQ context: zmq_wrap ()
Philip Kovacs
kovacsp3 at comcast.net
Sat Dec 24 01:17:06 CET 2011
I would like to propose an addition to the api for CZMQ: zmq_wrap (void* context).
This function would take a context created by 0MQ's void* zmq_init (int) and create
a CZMQ-compatible "wrapper" context. This wrapper context created function as usual,
however zctx_destroy () would _not_ issue zmq_term () on the wrapped 0MQ context.
In effect, CZMQ would destroy only the CZMQ sockets created on the wrapped context
and leave the original 0MQ context alone. This could be accomplished quite easily
by added a field to the zctx_t structure:
// Structure of our class
struct _zctx_t {
void *context; // Our 0MQ context
zlist_t *sockets; // Sockets held by this thread
Bool main; // TRUE if we're the main thread
int iothreads; // Number of IO threads, default 1
int linger; // Linger timeout, default 0
Bool wrapped; // TRUE if created by zctx_wrap () <--------
}
The motivation for this proposal stems from my writing a library which uses the
high-level functionality of CZMQ. I cannot allow users to supply their own contexts
without exposing the CZMQ interface which I prefer not to do. I would prefer to expose
the 0MQ interface only. Consider these two contructors for a C++ object that uses CZMQ:
LibraryObject (); // creates a context privately, unseen to the user
LibraryObject (void* context) // uses the supplied context, created by zmq_init()
At present, I cannot offer the second contructor. I can only offer this one:
LibraryObject (zctx_t* context) // ugh, I just exposed CZMQ
and ^this is what I want to avoid. By adding the ability to create CZMQ wrapper contexts
around existing 0MQ contexts, I can utilize CZMQ internally while not exposing the CZMQ
interface:
LibraryObject (void* context)
{
assert (context != 0);
zctx_t* context_wrapper_ = zctx_wrap (context);
...
}
Phil
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20111223/1e1b5bd1/attachment.sig>
More information about the zeromq-dev
mailing list