示例#1
0
文件: zctx.c 项目: Cargo-Labs/czmq
void
zctx_test (bool verbose)
{
    printf (" * zctx (deprecated): ");

    //  @selftest
    //  Create and destroy a context without using it
    zctx_t *ctx = zctx_new ();
    assert (ctx);
    zctx_destroy (&ctx);
    assert (ctx == NULL);

    //  Create a context with many busy sockets, destroy it
    ctx = zctx_new ();
    assert (ctx);
    zctx_set_iothreads (ctx, 1);
    zctx_set_linger (ctx, 5);       //  5 msecs
    void *s1 = zctx__socket_new (ctx, ZMQ_PAIR);
    assert (s1);
    void *s2 = zctx__socket_new (ctx, ZMQ_XREQ);
    assert (s2);
    void *s3 = zctx__socket_new (ctx, ZMQ_REQ);
    assert (s3);
    void *s4 = zctx__socket_new (ctx, ZMQ_REP);
    assert (s4);
    void *s5 = zctx__socket_new (ctx, ZMQ_PUB);
    assert (s5);
    void *s6 = zctx__socket_new (ctx, ZMQ_SUB);
    assert (s6);
    int rc = zsocket_connect (s1, "tcp://127.0.0.1:5555");
    assert (rc == 0);
    rc = zsocket_connect (s2, "tcp://127.0.0.1:5555");
    assert (rc == 0);
    rc = zsocket_connect (s3, "tcp://127.0.0.1:5555");
    assert (rc == 0);
    rc = zsocket_connect (s4, "tcp://127.0.0.1:5555");
    assert (rc == 0);
    rc = zsocket_connect (s5, "tcp://127.0.0.1:5555");
    assert (rc == 0);
    rc = zsocket_connect (s6, "tcp://127.0.0.1:5555");
    assert (rc == 0);
    assert (zctx_underlying (ctx));
    zctx_destroy (&ctx);
    //  @end

    printf ("OK\n");
}
示例#2
0
static rsRetVal createContext() {
    if (s_context == NULL) {
        errmsg.LogError(0, NO_ERRCODE, "creating zctx.");
        s_context = zctx_new();
        
        if (s_context == NULL) {
            errmsg.LogError(0, RS_RET_INVALID_PARAMS,
                            "zctx_new failed: %s",
                            strerror(errno));
            /* DK: really should do better than invalid params...*/
            return RS_RET_INVALID_PARAMS;
        }
        
        if (s_io_threads > 1) {
            errmsg.LogError(0, NO_ERRCODE, "setting io worker threads to %d", s_io_threads);
            zctx_set_iothreads(s_context, s_io_threads);
        }
    }
    return RS_RET_OK;
}
示例#3
0
int main (void)
{
	zctx_t *ctx = zctx_new ();
	int size;

	int io_threads = 4;
	zctx_set_iothreads (ctx,  io_threads);	
	
	void *subscriber, *publisher; 
	int accept_port = scan_and_bind_socket(ctx, &subscriber, ZMQ_XSUB, DYNAMIC_ADDR);
	int publish_port = scan_and_bind_socket(ctx, &publisher, ZMQ_XPUB, DYNAMIC_ADDR);
	

	char ** registration_response = register_publisher_service(ctx, accept_port, publish_port,  &size);

	free(registration_response);

	//void *listener = zthread_fork (ctx, listener_thread, NULL);
	zmq_proxy (subscriber, publisher, NULL);
	zctx_destroy (&ctx);
	return 0;
}
示例#4
0
文件: zctx.c 项目: bumptech/czmq
int
zctx_test (Bool verbose)
{
    printf (" * zctx: ");

    //  @selftest
    //  Create and destroy a context without using it
    zctx_t *ctx = zctx_new ();
    assert (ctx);
    zctx_destroy (&ctx);
    assert (ctx == NULL);

    //  Create a context with many busy sockets, destroy it
    ctx = zctx_new ();
    assert (ctx);
    zctx_set_iothreads (ctx, 1);
    zctx_set_linger (ctx, 5);       //  5 msecs
    void *s1 = zctx__socket_new (ctx, ZMQ_PAIR);
    void *s2 = zctx__socket_new (ctx, ZMQ_XREQ);
    void *s3 = zctx__socket_new (ctx, ZMQ_REQ);
    void *s4 = zctx__socket_new (ctx, ZMQ_REP);
    void *s5 = zctx__socket_new (ctx, ZMQ_PUB);
    void *s6 = zctx__socket_new (ctx, ZMQ_SUB);
    zsocket_connect (s1, "tcp://127.0.0.1:5555");
    zsocket_connect (s2, "tcp://127.0.0.1:5555");
    zsocket_connect (s3, "tcp://127.0.0.1:5555");
    zsocket_connect (s4, "tcp://127.0.0.1:5555");
    zsocket_connect (s5, "tcp://127.0.0.1:5555");
    zsocket_connect (s6, "tcp://127.0.0.1:5555");
    assert (zctx_underlying (ctx));

    //  Everything should be cleanly closed now
    zctx_destroy (&ctx);
    //  @end

    printf ("OK\n");
    return 0;
}