示例#1
0
static void
pass_xrap_message_to_app (client_t *self)
{
    zstr_sendm (self->msgpipe, "XRAP DELIVER");
    zsock_bsend (self->msgpipe, "up",
                 xrap_traffic_sender (self->message),
                 xrap_traffic_get_content (self->message));
}
示例#2
0
文件: zeb_broker.c 项目: sappo/zebra
static void
write_message_to_xrap_client (client_t *self)
{
    zuuid_t *client_id = xrap_traffic_sender (self->message);
    assert (client_id);
    client_t *client = (client_t *) zhashx_lookup (self->server->clients, zuuid_str (client_id));
    if (client) {
        //  Save message for broker
        client->msg = zmsg_dup (xrap_traffic_content (self->message));
        client->callee = NULL;
        engine_send_event (client, xrap_message_event);
    }
}
JNIEXPORT jlong JNICALL
Java_org_zeromq_zebra_XrapTraffic__1_1sender (JNIEnv *env, jclass c, jlong self)
{
    jlong sender_ = (jlong) (intptr_t) xrap_traffic_sender ((xrap_traffic_t *) (intptr_t) self);
    return sender_;
}
示例#4
0
///
//  Get the sender field
zuuid_t *QmlXrapTraffic::sender () {
    return xrap_traffic_sender (self);
};
示例#5
0
void
xrap_traffic_test (bool verbose)
{
    printf (" * xrap_traffic:");

    if (verbose)
        printf ("\n");

    //  @selftest
    //  Simple create/destroy test
    xrap_traffic_t *self = xrap_traffic_new ();
    assert (self);
    xrap_traffic_destroy (&self);
    //  Create pair of sockets we can send through
    //  We must bind before connect if we wish to remain compatible with ZeroMQ < v4
    zsock_t *output = zsock_new (ZMQ_DEALER);
    assert (output);
    int rc = zsock_bind (output, "inproc://selftest-xrap_traffic");
    assert (rc == 0);

    zsock_t *input = zsock_new (ZMQ_ROUTER);
    assert (input);
    rc = zsock_connect (input, "inproc://selftest-xrap_traffic");
    assert (rc == 0);


    //  Encode/send/decode and verify each message type
    int instance;
    self = xrap_traffic_new ();
    xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_OPEN);

    xrap_traffic_set_address (self, "Life is short but Now lasts for ever");
    //  Send twice
    xrap_traffic_send (self, output);
    xrap_traffic_send (self, output);

    for (instance = 0; instance < 2; instance++) {
        xrap_traffic_recv (self, input);
        assert (xrap_traffic_routing_id (self));
        assert (streq (xrap_traffic_address (self), "Life is short but Now lasts for ever"));
    }
    xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_PING);

    //  Send twice
    xrap_traffic_send (self, output);
    xrap_traffic_send (self, output);

    for (instance = 0; instance < 2; instance++) {
        xrap_traffic_recv (self, input);
        assert (xrap_traffic_routing_id (self));
    }
    xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_PONG);

    //  Send twice
    xrap_traffic_send (self, output);
    xrap_traffic_send (self, output);

    for (instance = 0; instance < 2; instance++) {
        xrap_traffic_recv (self, input);
        assert (xrap_traffic_routing_id (self));
    }
    xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_CLOSE);

    //  Send twice
    xrap_traffic_send (self, output);
    xrap_traffic_send (self, output);

    for (instance = 0; instance < 2; instance++) {
        xrap_traffic_recv (self, input);
        assert (xrap_traffic_routing_id (self));
    }
    xrap_traffic_set_id (self, XRAP_TRAFFIC_XRAP_SEND);

    xrap_traffic_set_timeout (self, 123);
    zmsg_t *xrap_send_content = zmsg_new ();
    xrap_traffic_set_content (self, &xrap_send_content);
    zmsg_addstr (xrap_traffic_content (self), "Captcha Diem");
    //  Send twice
    xrap_traffic_send (self, output);
    xrap_traffic_send (self, output);

    for (instance = 0; instance < 2; instance++) {
        xrap_traffic_recv (self, input);
        assert (xrap_traffic_routing_id (self));
        assert (xrap_traffic_timeout (self) == 123);
        assert (zmsg_size (xrap_traffic_content (self)) == 1);
        char *content = zmsg_popstr (xrap_traffic_content (self));
        assert (streq (content, "Captcha Diem"));
        zstr_free (&content);
        if (instance == 1)
            zmsg_destroy (&xrap_send_content);
    }
    xrap_traffic_set_id (self, XRAP_TRAFFIC_XRAP_OFFER);

    xrap_traffic_set_route (self, "Life is short but Now lasts for ever");
    xrap_traffic_set_method (self, "Life is short but Now lasts for ever");
    //  Send twice
    xrap_traffic_send (self, output);
    xrap_traffic_send (self, output);

    for (instance = 0; instance < 2; instance++) {
        xrap_traffic_recv (self, input);
        assert (xrap_traffic_routing_id (self));
        assert (streq (xrap_traffic_route (self), "Life is short but Now lasts for ever"));
        assert (streq (xrap_traffic_method (self), "Life is short but Now lasts for ever"));
    }
    xrap_traffic_set_id (self, XRAP_TRAFFIC_XRAP_DELIVER);

    zuuid_t *xrap_deliver_sender = zuuid_new ();
    xrap_traffic_set_sender (self, xrap_deliver_sender);
    zmsg_t *xrap_deliver_content = zmsg_new ();
    xrap_traffic_set_content (self, &xrap_deliver_content);
    zmsg_addstr (xrap_traffic_content (self), "Captcha Diem");
    //  Send twice
    xrap_traffic_send (self, output);
    xrap_traffic_send (self, output);

    for (instance = 0; instance < 2; instance++) {
        xrap_traffic_recv (self, input);
        assert (xrap_traffic_routing_id (self));
        assert (zuuid_eq (xrap_deliver_sender, zuuid_data (xrap_traffic_sender (self))));
        if (instance == 1)
            zuuid_destroy (&xrap_deliver_sender);
        assert (zmsg_size (xrap_traffic_content (self)) == 1);
        char *content = zmsg_popstr (xrap_traffic_content (self));
        assert (streq (content, "Captcha Diem"));
        zstr_free (&content);
        if (instance == 1)
            zmsg_destroy (&xrap_deliver_content);
    }
    xrap_traffic_set_id (self, XRAP_TRAFFIC_OK);

    xrap_traffic_set_status_code (self, 123);
    xrap_traffic_set_status_reason (self, "Life is short but Now lasts for ever");
    //  Send twice
    xrap_traffic_send (self, output);
    xrap_traffic_send (self, output);

    for (instance = 0; instance < 2; instance++) {
        xrap_traffic_recv (self, input);
        assert (xrap_traffic_routing_id (self));
        assert (xrap_traffic_status_code (self) == 123);
        assert (streq (xrap_traffic_status_reason (self), "Life is short but Now lasts for ever"));
    }
    xrap_traffic_set_id (self, XRAP_TRAFFIC_FAIL);

    xrap_traffic_set_status_code (self, 123);
    xrap_traffic_set_status_reason (self, "Life is short but Now lasts for ever");
    //  Send twice
    xrap_traffic_send (self, output);
    xrap_traffic_send (self, output);

    for (instance = 0; instance < 2; instance++) {
        xrap_traffic_recv (self, input);
        assert (xrap_traffic_routing_id (self));
        assert (xrap_traffic_status_code (self) == 123);
        assert (streq (xrap_traffic_status_reason (self), "Life is short but Now lasts for ever"));
    }
    xrap_traffic_set_id (self, XRAP_TRAFFIC_ERROR);

    xrap_traffic_set_status_code (self, 123);
    xrap_traffic_set_status_reason (self, "Life is short but Now lasts for ever");
    //  Send twice
    xrap_traffic_send (self, output);
    xrap_traffic_send (self, output);

    for (instance = 0; instance < 2; instance++) {
        xrap_traffic_recv (self, input);
        assert (xrap_traffic_routing_id (self));
        assert (xrap_traffic_status_code (self) == 123);
        assert (streq (xrap_traffic_status_reason (self), "Life is short but Now lasts for ever"));
    }

    xrap_traffic_destroy (&self);
    zsock_destroy (&input);
    zsock_destroy (&output);
    //  @end

    printf ("OK\n");
}