JNIEXPORT void JNICALL
Java_org_zeromq_zebra_XrapTraffic__1_1setTimeout (JNIEnv *env, jclass c, jlong self, jint timeout)
{
    xrap_traffic_set_timeout ((xrap_traffic_t *) (intptr_t) self, (uint32_t) timeout);
}
Exemple #2
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");
}
Exemple #3
0
///
//  Set the timeout field
void QmlXrapTraffic::setTimeout (uint32_t timeout) {
    xrap_traffic_set_timeout (self, timeout);
};
Exemple #4
0
static void
prepare_xrap_send_command (client_t *self)
{
    xrap_traffic_set_timeout (self->message, self->args->timeout);
    xrap_traffic_set_content (self->message, &self->args->content);
}