int XS_TEST_MAIN ()
{
    void *ctx;
    void *s1;
    void *s2;
    int i;
    int j;
    int rc;
    int io_threads;
    void *threads [THREAD_COUNT];

    fprintf (stderr, "shutdown_stress test running...\n");

    for (j = 0; j != 10; j++) {

        //  Check the shutdown with many parallel I/O threads.
        ctx = xs_init ();
        assert (ctx);
        io_threads = 7;
        rc = xs_setctxopt (ctx, XS_IO_THREADS, &io_threads,
            sizeof (io_threads));
        assert (rc == 0);

        s1 = xs_socket (ctx, XS_PUB);
        assert (s1);

        rc = xs_bind (s1, "tcp://127.0.0.1:5560");
        assert (rc == 0);

        for (i = 0; i != THREAD_COUNT; i++) {
            s2 = xs_socket (ctx, XS_SUB);
            assert (s2);
            threads [i] = thread_create (shutdown_stress_worker, s2);
            assert (threads [i]);
        }

        for (i = 0; i != THREAD_COUNT; i++)
            thread_join (threads [i]);

        rc = xs_close (s1);
        assert (rc == 0);

        rc = xs_term (ctx);
        assert (rc == 0);
    }

    return 0;
}
Exemple #2
0
void *zmq_init (int io_threads)
{
    void *ctx = xs_init ();
    if (!ctx)
        return NULL;

    //  Crossroads don't allow for zero I/O threads.
    if (io_threads < 1)
        io_threads = 1;

    int rc = xs_setctxopt (ctx, XS_IO_THREADS, &io_threads,
        sizeof (io_threads));
    if (rc != 0) {
        xs_term (ctx);
        return NULL;
    }

    return ctx;
}