Example #1
0
void test_poller_exists_with_socket_on_zmq_ctx_term (const int socket_type_)
{
#ifdef ZMQ_HAVE_POLLER
    struct poller_test_data_t poller_test_data;

    poller_test_data.socket_type = socket_type_;

    //  Set up our context and sockets
    poller_test_data.ctx = zmq_ctx_new ();
    TEST_ASSERT_NOT_NULL (poller_test_data.ctx);

    poller_test_data.counter = zmq_atomic_counter_new ();
    TEST_ASSERT_NOT_NULL (poller_test_data.counter);

    void *thread = zmq_threadstart (run_poller, &poller_test_data);
    TEST_ASSERT_NOT_NULL (thread);

    while (zmq_atomic_counter_value (poller_test_data.counter) == 0) {
        msleep (10);
    }

    // Destroy the context
    TEST_ASSERT_SUCCESS_ERRNO (zmq_ctx_destroy (poller_test_data.ctx));

    zmq_threadclose (thread);

    zmq_atomic_counter_destroy (&poller_test_data.counter);
#else
    TEST_IGNORE_MESSAGE ("libzmq without zmq_poller_* support, ignoring test");
#endif
}
Example #2
0
mlm_msg_t *
mlm_msg_new (
    const char *sender, const char *address, const char *subject,
    const char *tracker, uint timeout, zmsg_t *content)
{
    assert (sender);
    mlm_msg_t *self = (mlm_msg_t *) zmalloc (sizeof (mlm_msg_t));
    if (self) {
        self->sender = sender? strdup (sender): NULL;
        self->address = address? strdup (address): NULL;
        self->subject = subject? strdup (subject): NULL;
        self->tracker = tracker? strdup (tracker): NULL;
        self->expiry = zclock_time () + timeout;
        self->content = content;
        self->refcount = zmq_atomic_counter_new ();
        zmq_atomic_counter_set (self->refcount, 1);
    }
    return self;
}
Example #3
0
int main (void)
{
    setup_test_environment ();

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

    g_clients_pkts_out = zmq_atomic_counter_new ();
    g_workers_pkts_out = zmq_atomic_counter_new ();


    // Control socket receives terminate command from main over inproc
    void *control = zmq_socket (ctx, ZMQ_PUB);
    assert (control);
    int linger = 0;
    int rc = zmq_setsockopt (control, ZMQ_LINGER, &linger, sizeof (linger));
    assert (rc == 0);
    rc = zmq_bind (control, "inproc://control");
    assert (rc == 0);

    // Control socket receives terminate command from main over inproc
    void *control_proxy = zmq_socket (ctx, ZMQ_REQ);
    assert (control_proxy);
    rc = zmq_setsockopt (control_proxy, ZMQ_LINGER, &linger, sizeof (linger));
    assert (rc == 0);
    rc = zmq_bind (control_proxy, "inproc://control_proxy");
    assert (rc == 0);

    void *threads [QT_CLIENTS + 1];
    struct thread_data databags [QT_CLIENTS + 1];
    for (int i = 0; i < QT_CLIENTS; i++) {
        databags [i].ctx = ctx;
        databags [i].id = i;
        threads[i] = zmq_threadstart  (&client_task, &databags [i]);
    }
    threads[QT_CLIENTS] = zmq_threadstart  (&server_task, ctx);
    msleep (500); // Run for 500 ms then quit


    if (is_verbose)
        printf ("stopping all clients and server workers\n");
    rc = zmq_send (control, "STOP", 4, 0);
    assert (rc == 4);

    msleep(500); // Wait for all clients and workers to STOP


#ifdef ZMQ_BUILD_DRAFT_API
    if (is_verbose)
        printf ("retrieving stats from the proxy\n");
    check_proxy_stats(control_proxy);
#endif

    if (is_verbose)
        printf ("shutting down all clients and server workers\n");
    rc = zmq_send (control, "TERMINATE", 9, 0);
    assert (rc == 9);

    if (is_verbose)
        printf ("shutting down the proxy\n");
    rc = zmq_send (control_proxy, "TERMINATE", 9, 0);
    assert (rc == 9);


    rc = zmq_close (control);
    assert (rc == 0);
    rc = zmq_close (control_proxy);
    assert (rc == 0);

    for (int i = 0; i < QT_CLIENTS + 1; i++)
        zmq_threadclose (threads[i]);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);
    return 0;
}