On Thu, Mar 24, 2011 at 10:29 AM, Michael Compton
<[email protected]> wrote:
> While zapi is definitely cool and I can see your desire to have the
> guide migrated to zapi, I'd still have sympathize with Martins point.
Me too, it's just not realistic IME to not use some higher level API
for the examples, and I'd rather it was a properly packaged and
documented one. Easier for everyone.
> Expecting the other binding examples authors to come and migrate their
> examples may be a bit much, and part of the value of guide, in my eyes,
> is aa source of tutorials for all language bindings, as well as an
> introduction of libzmq proper.
Using zapi in the C examples wouldn't require changes for other
translations, except perhaps C++, which often follows the C code
closely. Actually I'd expect the new C++ binding to also go a level
higher and perhaps adopt some of zapi's semantics. zapi++ maybe?
Part of the goal with zapi is also to explore better semantics for all
bindings. For example, I took the automatic socket closure from
erlzmq, but it's a technique that would add value to all bindings.
There is also a small but essential portability layer in zapi, which
all bindings (where the language doesn't already offer this) could
benefit from. Two main areas: starting new threads, and clocks/delays.
So my goals here are:
* To get all language binding authors thinking of potential shared
higher-level semantics (this gives us the same result as if zapi was
part of core).
* To not refer to zapi in the text except briefly (same as already
done for the ad-hoc zhelpers API). The Guide is not a tutorial for any
API but for 0MQ's semantics, which are core and higher-level patterns.
When code gets out of the way, the patterns are easier to understand and reuse.
Look, here is the zctx self test. You can pretty much read exactly
what's happening:
// Create a context with many busy sockets, destroy it
ctx = zctx_new ();
zctx_set_iothreads (ctx, 1);
zctx_set_linger (ctx, 5); // 5 msecs
void *s1 = zctx_socket_new (ctx, ZMQ_PAIR);
void *s2 = zctx_socket_new (ctx, ZMQ_XREQ);
void *s3 = zctx_socket_new (ctx, ZMQ_REQ);
void *s4 = zctx_socket_new (ctx, ZMQ_REP);
void *s5 = zctx_socket_new (ctx, ZMQ_PUB);
void *s6 = zctx_socket_new (ctx, ZMQ_SUB);
zmq_connect (s1, "tcp://127.0.0.1:5555");
zmq_connect (s2, "tcp://127.0.0.1:5555");
zmq_connect (s3, "tcp://127.0.0.1:5555");
zmq_connect (s4, "tcp://127.0.0.1:5555");
zmq_connect (s5, "tcp://127.0.0.1:5555");
zmq_connect (s6, "tcp://127.0.0.1:5555");
// Create a child thread, check it's safely alive
void *pipe = zctx_thread_new (ctx, s_test_thread, NULL);
zstr_send (pipe, "ping");
char *pong = zstr_recv (pipe);
assert (streq (pong, "pong"));
free (pong);
// Everything should be cleanly closed now
zctx_destroy (&ctx);
...
static void *
s_test_thread (void *args_ptr)
{
zthread_t *args = (zthread_t *) args_ptr;
// Create a socket to check it'll be properly deleted at exit
zctx_socket_new (args->ctx, ZMQ_PUSH);
// Wait for our parent to ping us, and pong back
char *ping = zstr_recv (args->pipe);
free (ping);
zstr_send (args->pipe, "pong");
return NULL;
}
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev