[zeromq-dev] Using zmq over network without zmq_server

Ville Aine ville.aine at blackshear.fi
Sat Jun 6 18:23:10 CEST 2009


Hi,

We have a server in a known location with a global exchange. We would like to
access the server without having to use zmq_server. Now, if we were using the
C++ API we could use dummy_locator_t[1] and be done with it, but we are using
the C API, and we'd rather not maintain a private fork of libczmq.

So, is there any plans to include dummy_locator_t or something like that to the
mainline, and to expose it via the C API?

As a concrete example of what I mean, I've attached a patch for libczmq
that we've been playing around with. The patch is against 0.6.1 and is
released under MIT license.

Thanks,
Ville

1. http://lists.zeromq.org/pipermail/zeromq-dev/2009-May/000790.html

---
 libczmq/zmq.cpp |   19 +++++++++++++++----
 libczmq/zmq.h   |    2 ++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/libczmq/zmq.cpp b/libczmq/zmq.cpp
index 76696ea..5e101c2 100644
--- a/libczmq/zmq.cpp
+++ b/libczmq/zmq.cpp
@@ -22,24 +22,25 @@
 #include <string.h>
 
 #include <zmq.hpp>
+#include <zmq/dummy_locator.hpp>
 #include <zmq.h>
 
 struct context_t
 {
     zmq::dispatcher_t *dispatcher;
-    zmq::locator_t *locator;    
+    zmq::i_locator *locator;
     zmq::i_thread *io_thread;
     zmq::api_thread_t *api_thread;
 };
 
-void *zmq_create (const char *host_)
-{   
+static void *create(zmq::i_locator *locator)
+{
     //  Create the context.
     context_t *context = new context_t;
     assert (context);
     context->dispatcher = new zmq::dispatcher_t (2);
     assert (context->dispatcher);
-    context->locator = new zmq::locator_t (host_);
+    context->locator = locator;
     assert (context->locator);    
     context->io_thread = zmq::io_thread_t::create (context->dispatcher);
     assert (context->io_thread);
@@ -50,6 +51,16 @@ void *zmq_create (const char *host_)
     return (void*) context;
 }
 
+void *zmq_create (const char *host_)
+{
+    return create (new zmq::locator_t (host_));
+}
+
+void *zmq_create_serverless (void)
+{
+    return create (new zmq::dummy_locator_t);
+}
+
 void zmq_destroy (void *object_)
 {
     //  Get the context.
diff --git a/libczmq/zmq.h b/libczmq/zmq.h
index 5e7280a..476840e 100644
--- a/libczmq/zmq.h
+++ b/libczmq/zmq.h
@@ -43,6 +43,8 @@ extern "C" {
 
 void ZMQ_EXPORT *zmq_create (const char *host_);
 
+void ZMQ_EXPORT *zmq_create_serverless (void);
+
 void ZMQ_EXPORT zmq_destroy (void *object_);
 
 void ZMQ_EXPORT zmq_mask (void *object_, uint32_t notifications_);



More information about the zeromq-dev mailing list