Pieter Hintjens wrote:
On Mon, Apr 1, 2013 at 6:23 PM, Anoop Karollil <[email protected]> wrote:

Pieter, any clue as to why the send with the connected (not bound)
ROUTER socket might be failing initially?

No clue, but if you can make a minimal test case in C, we can
investigate. Afaik it should work and this would be considered a bug.

Attached are two C programs that reproduce the problem. The broker binds and receives. The client connects and then sends. The send fails initially and then succeeds.

Anoop
#include <zmq.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

#define URI "tcp://127.0.0.1:20000"

void main()
{
    void *ctx = zmq_ctx_new();
    assert(ctx);

    void *client = zmq_socket(ctx, ZMQ_ROUTER);
    assert(client);

    char *client_id = "CLIENT";
    int rc = zmq_setsockopt(client, ZMQ_IDENTITY, client_id, strlen(client_id));
    assert(!rc);

    int option = 1;
    rc = zmq_setsockopt(client, ZMQ_ROUTER_MANDATORY, &option, sizeof(option));
    assert(!rc);

    rc = zmq_connect(client, URI);

    char *broker_id = "BROKER";
    char *msg = "Hello";
    int sent_addr = 0;
    while(1) {

        if (!sent_addr) {
            printf("Sending address...\n");
            rc = zmq_send(client, broker_id, strlen(broker_id), ZMQ_SNDMORE);
        } else {
            printf("Sending %s...\n", msg);
            rc = zmq_send(client, msg, strlen(msg), 0);
        }

        if (rc > 0) {
            printf("Success!\n");
            if (sent_addr)
                break;
            else
                sent_addr = 1;
        } else {
            printf("Error: %s\n", zmq_strerror(errno));
        }

    }

    zmq_close(client);
    zmq_ctx_destroy(ctx);
}

#include <zmq.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

#define URI "tcp://127.0.0.1:20000"

void main()
{
    void *ctx = zmq_ctx_new();
    assert(ctx);

    void *broker = zmq_socket(ctx, ZMQ_ROUTER);
    assert(broker);

    char *broker_id = "BROKER";
    int rc = zmq_setsockopt(broker, ZMQ_IDENTITY, broker_id, strlen(broker_id));
    assert(!rc);

    int option = 1;
    rc = zmq_setsockopt(broker, ZMQ_ROUTER_MANDATORY, &option, sizeof(option));
    assert(!rc);

    rc = zmq_bind(broker, URI);
    assert(!rc);

    zmq_msg_t message;
    while (1) {
        zmq_msg_init(&message);
        zmq_msg_recv(&message, broker, 0);
        int more = zmq_msg_more(&message);
        zmq_msg_close(&message);
        if (!more)
            break;
    }

    zmq_close(broker);
    zmq_ctx_destroy(ctx);
}

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

Reply via email to