Thanks Pieter. My problem came from I forgot to configure the debugger for multithreading.

I have one question please : is it "legal" to use a PUB socket without a poller ? In my test, I receive nothing.

Here is a code excerpt :

static void
server_worker (void *ctx)
{
    void *worker = zmq_socket (ctx, ZMQ_DEALER);
    assert (worker);
    int rc = zmq_connect (worker, "inproc://backend");
    assert (rc == 0);

    // Control socket receives terminate command from main over inproc
*void *control = zmq_socket (ctx, ZMQ_SUB);*
    assert (control);
*rc = zmq_setsockopt (control, ZMQ_SUBSCRIBE, "", 0);*
    assert (rc == 0);
*rc = zmq_connect (control, "inproc://control");*
    assert (rc == 0);

char content [CONTENT_SIZE_MAX]; // bigger than what we need to check that
    char identity [ID_SIZE_MAX];      // the size received is the size sent

    bool run = true;
    while (run) {
*rc = zmq_recv (control, content, CONTENT_SIZE_MAX, ZMQ_DONTWAIT);*
        if (!rc) {
if (is_verbose) printf("server_worker receives command = %s\n", content);
            if (memcmp (content, "TERMINATE", 10) == 0)
                run = false;
        }

        // The DEALER socket gives us the reply envelope and message
        rc = zmq_recv (worker, identity, ID_SIZE_MAX, 0);
        assert (rc == ID_SIZE);
        rc = zmq_recv (worker, content, CONTENT_SIZE_MAX, 0);
        assert (rc == CONTENT_SIZE);
if (is_verbose) printf("server receive - identity = %s content = %s\n", identity, content);

In main :

int main (void)
{
    setup_test_environment ();
    void* threads [QT_CLIENTS + 1];
    for (int i = 0; i < QT_CLIENTS; i++)
    {
        threads[i] = zmq_threadstart  (&client_task, NULL);
    }
    threads[QT_CLIENTS] = zmq_threadstart  (&server_task, NULL);
    sleep (5); // Run for 5 seconds then quit

    void *ctx = zmq_ctx_new ();
    assert (ctx);
    // Control socket receives terminate command from main over inproc
*void *control = zmq_socket (ctx, ZMQ_PUB);*
    assert (control);
*int rc = zmq_bind (control, "inproc://control");*
    assert (rc == 0);
    for (int i = 0; i < 100; i++) {
*rc = zmq_send (control, "TERMINATE", 10, 0);*
        assert (rc == 10);
    }

    for (int i = 0; i < QT_CLIENTS + 1; i++)
        zmq_threadclose (threads[i]);
    rc = zmq_close (control);
    assert (rc == 0);
    rc = zmq_ctx_term (ctx);
    assert (rc == 0);
    return 0;
}

Le 14/10/2013 17:23, Pieter Hintjens a écrit :
You should include just <zmq.h>.

Line 59 is the bind, anyhow...

On Mon, Oct 14, 2013 at 5:14 PM, Laurent Alebarde <[email protected]> wrote:
Thanks Pieter. In fact, the problem is strange and comes as soon as the
creation of the socket. But I think I have a build issue. You know, IDE
comfort ;-) .


Le 14/10/2013 16:55, Pieter Hintjens a écrit :

You can't bind to a hostname. Use 127.0.0.1 instead.

On Mon, Oct 14, 2013 at 4:52 PM, Laurent Alebarde <[email protected]>
wrote:

I am trying to adapt the Guide's "Asynchronous client-to-server (DEALER to
ROUTER)" in a non czmq version, but it fails when it binds or connects. Here
is my code.

libzmq_test: ../tests/async_client_to_server_no_czmq.cpp:59: void
server_task(void*): Assertion `rc == 0' failed.

On its side, the client fails too.

I tried several ports with the same result


Any idea please ?

_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev





_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev




_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to