int main (void)
{
    setup_test_environment();
    int rc;

    //  Set up our context and sockets
    void *ctx = zmq_ctx_new ();
    assert (ctx);

    assert (zmq_ctx_get (ctx, ZMQ_MAX_SOCKETS) == ZMQ_MAX_SOCKETS_DFLT);
    assert (zmq_ctx_get (ctx, ZMQ_IO_THREADS) == ZMQ_IO_THREADS_DFLT);
    assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 0);

    rc = zmq_ctx_set (ctx, ZMQ_IPV6, true);
    assert (zmq_ctx_get (ctx, ZMQ_IPV6) == true);

    void *router = zmq_socket (ctx, ZMQ_ROUTER);
    int ipv6;
    size_t optsize = sizeof (int);
    rc = zmq_getsockopt (router, ZMQ_IPV6, &ipv6, &optsize);
    assert (rc == 0);
    assert (ipv6);

    rc = zmq_close (router);
    assert (rc == 0);

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

    return 0;
}
Example #2
0
JNIEXPORT jint JNICALL Java_org_zeromq_ZMQ_00024Context_getMaxSockets (JNIEnv *env, jobject obj)
{
    void *c = get_context (env, obj);
    if (! c)
        return -1;

    return zmq_ctx_get (c, ZMQ_MAX_SOCKETS);
}
Example #3
0
int HHVM_METHOD(ZMQContext, getOpt, int64_t option) {
  auto ctx = Native::data<ZMQContext>(this_);
  
  if (option != ZMQ_MAX_SOCKETS) {
    throwExceptionClass(s_ZMQContextExceptionClass, "Unknown option key", PHP_ZMQ_INTERNAL_ERROR);
  }

  int value = zmq_ctx_get(ctx->context->z_ctx, option);
  return value;
}
Example #4
0
int main(int argc, char** argv)
{

  int io_threads = 4;
  void* context = zmq_ctx_new();
  zmq_ctx_set(context, ZMQ_IO_THREADS, io_threads);
  printf("io thread num: %d\n", zmq_ctx_get(context, ZMQ_IO_THREADS));

  zmq_ctx_destroy(context);

  return 0;
}
Example #5
0
int main (void)
{
    setup_test_environment();
    int rc;
    
    //  Set up our context and sockets
    void *ctx = zmq_ctx_new ();
    assert (ctx);
    
    assert (zmq_ctx_get (ctx, ZMQ_MAX_SOCKETS) == ZMQ_MAX_SOCKETS_DFLT);
#if defined(ZMQ_USE_SELECT)
    assert (zmq_ctx_get (ctx, ZMQ_SOCKET_LIMIT) == FD_SETSIZE - 1);
#elif    defined(ZMQ_USE_POLL) || defined(ZMQ_USE_EPOLL)     \
      || defined(ZMQ_USE_DEVPOLL) || defined(ZMQ_USE_KQUEUE)
    assert (zmq_ctx_get (ctx, ZMQ_SOCKET_LIMIT) == 65535);
#endif
    assert (zmq_ctx_get (ctx, ZMQ_IO_THREADS) == ZMQ_IO_THREADS_DFLT);
    assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 0);
    assert (zmq_ctx_get (ctx, ZMQ_MSG_T_SIZE) == sizeof (zmq_msg_t));
    
    rc = zmq_ctx_set (ctx, ZMQ_IPV6, true);
    assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 1);
    
    void *router = zmq_socket (ctx, ZMQ_ROUTER);
    int value;
    size_t optsize = sizeof (int);
    rc = zmq_getsockopt (router, ZMQ_IPV6, &value, &optsize);
    assert (rc == 0);
    assert (value == 1);
    rc = zmq_getsockopt (router, ZMQ_LINGER, &value, &optsize);
    assert (rc == 0);
    assert (value == -1);
    rc = zmq_close (router);
    assert (rc == 0);
    
    rc = zmq_ctx_set (ctx, ZMQ_BLOCKY, false);
    assert (zmq_ctx_get (ctx, ZMQ_BLOCKY) == 0);
    router = zmq_socket (ctx, ZMQ_ROUTER);
    rc = zmq_getsockopt (router, ZMQ_LINGER, &value, &optsize);
    assert (rc == 0);
    assert (value == 0);
    rc = zmq_close (router);
    assert (rc == 0);

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

    return 0;
}
Example #6
0
File: zsys.c Project: wysman/czmq
size_t
zsys_socket_limit (void)
{
    int socket_limit;
#if (ZMQ_VERSION >= ZMQ_MAKE_VERSION (4, 1, 0))
    if (s_process_ctx)
        socket_limit = zmq_ctx_get (s_process_ctx, ZMQ_SOCKET_LIMIT);
    else {
        void *ctx = zmq_init (1);
        socket_limit = zmq_ctx_get (ctx, ZMQ_SOCKET_LIMIT);
        zmq_term (ctx);
    }
    //  ZeroMQ used to report a nonsense value (2^31) which if used would
    //  on zmq_ctx_set (ZMQ_MAX_SOCKETS) cause an out-of-memory error. So
    //  if we're running on an older library, enforce a sane limit.
    if (socket_limit > 65535)
        socket_limit = 65535;
#else
    socket_limit = 1024;
#endif
    return (size_t) socket_limit;
}
Example #7
0
int context::get(context_option const& option)
{
	if (nullptr == _context) { throw invalid_instance("context is invalid"); }

	int result = zmq_ctx_get(_context, static_cast<int>(option));

	if (result < 0)
	{
		throw zmq_internal_exception();
	}

	return result;
}
Example #8
0
int main(void)
{
    void* ctx;
    void* sckts[n];
    int rc;
    int i;

    assert(m <= n);

    printf("#       : create context\n");
    ctx = zmq_ctx_new();
    assert(ctx);

    rc = zmq_ctx_get(ctx, ZMQ_MAX_SOCKETS);
    assert(rc >= n);

    printf("##      : starting to create sockets\n");
    for(i=0; i<n; ++i) {
        if(i == 0)
            sckts[i] = zmq_socket(ctx, ZMQ_REP);
        else
            sckts[i] = zmq_socket(ctx, ZMQ_REQ);
        assert(sckts[i]);
    }

    printf("####    : starting to connect sockets\n");
    for(i=0; i<m; ++i) {
        if(i == 0)
            rc = zmq_bind(sckts[i], "inproc://test");
        else
            rc = zmq_connect(sckts[i], "inproc://test");
        assert(rc == 0);
    }

    printf("######  : starting to close sockets\n");
    for(i=0; i<n; ++i) {
        rc = zmq_close(sckts[i]);
        assert(rc == 0);
    }

    printf("####### : destroy context\n");
    rc = zmq_ctx_destroy(ctx);
    assert(rc == 0);

    printf("Success : all resources released\n");
    return 0;
}
Example #9
0
int main (int argc, char *argv [])
{
    void *ctx;
    int rc;
    int i;

    if (argc != 10) {
        printf ("usage: remote_thr <connect-to> <message-size> <message-count> <SND buffer> <RCV buffer> <flow (PUSH/PULL)> <records (ZMSG/DATA)> <zmq-threads> <workers>\n");
        return 1;
    }

    connect_to = argv [1];
    message_size = atoi (argv [2]);
    message_count = atoi (argv [3]);
	sndbuflen = atoi (argv [4]);
	rcvbuflen = atoi (argv [5]);
    if( !strcmp( argv [6], "PUSH")){
        flow = ZMQ_PUSH;
    }
    if( !strcmp( argv [6], "PULL")){
        flow = ZMQ_PULL;
    }
    if( !strcmp( argv [7], "ZMSG")){
        rec = ZMSG;
    }
    if( !strcmp( argv [7], "DATA")){
        rec = DATA;
    }
    threads = atoi (argv [8]);
    workers = atoi (argv [9]);


    ctx = zmq_ctx_new ();
    if (!ctx) {
        printf ("error in zmq_ctx_new: %s\n", zmq_strerror (errno));
        return -1;
    }

    rc = zmq_ctx_set ( ctx, ZMQ_IO_THREADS, threads);
    if (rc) {
        printf ("error in zmq_ctx_set: %s\n", zmq_strerror (errno));
        return -1;
    }

    printf("Threads: %d, workers %d\n", zmq_ctx_get( ctx, ZMQ_IO_THREADS), workers);
#if defined ZMQ_HAVE_WINDOWS
    HANDLE worker[128];
#else
    pthread_t worker[128];
#endif

    US_TIMER timer;

    tm_init( &timer);

    for (i = 0; i < workers; i++) {
#if defined ZMQ_HAVE_WINDOWS
        worker[i] = (HANDLE) _beginthreadex (NULL, 0, worker_routine, ctx, 0 , NULL);
#else
        pthread_create (&worker[i], NULL, worker_routine, ctx);
#endif
        printf("Worker %d spawned\n", i);
    }

    for (i = 0; i < workers; i++) {
#if defined ZMQ_HAVE_WINDOWS
        WaitForSingleObject (worker[i], INFINITE);
        CloseHandle (worker[i]);
#else
        pthread_join( worker[i], NULL);
#endif
        printf("Worker %d joined\n", i);
    }

    float secs = tm_secs( &timer);
    float total = ( (float)workers)*(((float) message_count) * ((float) message_size)) / (1024.0*1024.0*1024.0);

    printf ("Message: size: %d KBytes, count: %d/workers(%d), time: %f secs\n", (int) message_size/1024, message_count, workers, secs);
    printf ("%sed %.3f GB @ %.3f GB/s\n", (flow == ZMQ_PULL) ? "Pull":"Push", total, total/secs);

    rc = zmq_term (ctx);
    if (rc != 0) {
        printf ("error in zmq_term: %s\n", zmq_strerror (errno));
        return -1;
    }

    return 0;
}