Exemplo n.º 1
0
int
main (int argc, char *argv[])
{

    if (argc != 3) {
        exit (-1);
    }

    int numb_msgs = atoi (argv[2]);

    zctx_t *ctx = zctx_new ();

    void *dealer = zsocket_new (ctx, ZMQ_DEALER);
    zsocket_set_linger (dealer, -1);
    zsocket_connect (dealer, "%s:9000", argv[1]);

    void *sub = zsocket_new (ctx, ZMQ_SUB);
    zsocket_connect (sub, "%s:9002", argv[1]);
    zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "all", 4);

    int64_t time[2];

    zmq_pollitem_t pollitem[1] = { {sub, 0, ZMQ_POLLIN}
    };

    zmq_poll (pollitem, 1, -1);
    zmsg_t *signal = zmsg_recv (sub);
    zmsg_destroy (&signal);

    char blob[SIZE] = { 0 };
    zmsg_t *msg = zmsg_new ();
    zframe_t *frame = zframe_new (blob, SIZE);
    zmsg_add (msg, frame);

    time[0] = zclock_time ();

    int i;
    for (i = 0; i < numb_msgs; i++) {
        zmsg_t *nmsg = zmsg_dup (msg);
        zmsg_send (&nmsg, dealer);


    }
    time[1] = zclock_time ();

    zmsg_destroy (&msg);

    zmq_poll (pollitem, 1, -1);
    msg = zmsg_recv (sub);
    zmsg_destroy (&msg);


    msg = zmsg_new ();
    frame = zframe_new (time, sizeof (int64_t) * 2);
    zmsg_add (msg, frame);
    zmsg_send (&msg, dealer);


    zctx_destroy (&ctx);
}
Exemplo n.º 2
0
Arquivo: zctx.c Projeto: dnaeon/czmq
void
zctx__socket_destroy (zctx_t *self, void *zocket)
{
    assert (self);
    assert (zocket);
    zsocket_set_linger (zocket, self->linger);
    zmq_close (zocket);
    zlist_remove (self->sockets, zocket);
}
Exemplo n.º 3
0
static rsRetVal initZMQ(instanceData* pData) {
    DEFiRet;
    
    /* create the context if necessary. */
    if (NULL == s_context) {
        zsys_handler_set(NULL);
        s_context = zctx_new();
        if (s_workerThreads > 0) zctx_set_iothreads(s_context, s_workerThreads);
    }
    
    pData->socket = zsocket_new(s_context, pData->type);
    if (NULL == pData->socket) {
        errmsg.LogError(0, RS_RET_NO_ERRCODE,
                        "omzmq3: zsocket_new failed for %s: %s",
                        pData->description, zmq_strerror(errno));
        ABORT_FINALIZE(RS_RET_NO_ERRCODE);
    }
    /* use czmq defaults for these, unless set to non-default values */
    if(pData->identity)             zsocket_set_identity(pData->socket, (char*)pData->identity);
    if(pData->sndBuf > -1)          zsocket_set_sndbuf(pData->socket, pData->sndBuf);
    if(pData->rcvBuf > -1)          zsocket_set_sndbuf(pData->socket, pData->rcvBuf);
    if(pData->linger > -1)          zsocket_set_linger(pData->socket, pData->linger);
    if(pData->backlog > -1)         zsocket_set_backlog(pData->socket, pData->backlog);
    if(pData->sndTimeout > -1)      zsocket_set_sndtimeo(pData->socket, pData->sndTimeout);
    if(pData->rcvTimeout > -1)      zsocket_set_rcvtimeo(pData->socket, pData->rcvTimeout);
    if(pData->maxMsgSize > -1)      zsocket_set_maxmsgsize(pData->socket, pData->maxMsgSize);
    if(pData->rate > -1)            zsocket_set_rate(pData->socket, pData->rate);
    if(pData->recoveryIVL > -1)     zsocket_set_recovery_ivl(pData->socket, pData->recoveryIVL);
    if(pData->multicastHops > -1)   zsocket_set_multicast_hops(pData->socket, pData->multicastHops);
    if(pData->reconnectIVL > -1)    zsocket_set_reconnect_ivl(pData->socket, pData->reconnectIVL);
    if(pData->reconnectIVLMax > -1) zsocket_set_reconnect_ivl_max(pData->socket, pData->reconnectIVLMax);
    if(pData->ipv4Only > -1)        zsocket_set_ipv4only(pData->socket, pData->ipv4Only);
    if(pData->affinity != 1)        zsocket_set_affinity(pData->socket, pData->affinity);
    if(pData->rcvHWM > -1)          zsocket_set_rcvhwm(pData->socket, pData->rcvHWM);
    if(pData->sndHWM > -1)          zsocket_set_sndhwm(pData->socket, pData->sndHWM);
    
    /* bind or connect to it */
    if (pData->action == ACTION_BIND) {
        /* bind asserts, so no need to test return val here
           which isn't the greatest api -- oh well */
        if(-1 == zsocket_bind(pData->socket, (char*)pData->description)) {
            errmsg.LogError(0, RS_RET_NO_ERRCODE, "omzmq3: bind failed for %s: %s",
                            pData->description, zmq_strerror(errno));
            ABORT_FINALIZE(RS_RET_NO_ERRCODE);
        }
        DBGPRINTF("omzmq3: bind to %s successful\n",pData->description);
    } else {
        if(-1 == zsocket_connect(pData->socket, (char*)pData->description)) {
            errmsg.LogError(0, RS_RET_NO_ERRCODE, "omzmq3: connect failed for %s: %s", 
                            pData->description, zmq_strerror(errno));
            ABORT_FINALIZE(RS_RET_NO_ERRCODE);
        }
        DBGPRINTF("omzmq3: connect to %s successful", pData->description);
    }
 finalize_it:
    RETiRet;
}
Exemplo n.º 4
0
int main(int argc, char const * const *argv)
{
  int rc;

  zctx_t *context = zctx_new();
  assert(context);
  zctx_set_rcvhwm(context, 1000);
  zctx_set_linger(context, 100);

  void *socket = zsocket_new(context, ZMQ_PULL);
  assert(socket);

  zsocket_set_rcvhwm(socket, 100000);
  zsocket_set_linger(socket, 500);
  zsocket_set_reconnect_ivl(socket, 100); // 100 ms
  zsocket_set_reconnect_ivl_max(socket, 10 * 1000); // 10 s

  const char* host = "localhost";
  if (argc>1) host = argv[1];

  rc = zsocket_connect(socket, "tcp://%s:9651", host);
  assert(rc==0);

  zmsg_t *msg = NULL;

  size_t received = 0;
  size_t lost = 0;
  size_t last_num = 0;
  while (1) {
    msg = zmsg_recv(socket);
    if (zsys_interrupted)
      break;
    assert(msg);
    received++;
    // assert(zmsg_size(msg) == 3);
    // zmsg_dump(msg);
    zframe_t *last_frame = zmsg_last(msg);
    char *str = zframe_strdup(last_frame);
    size_t n = atol(str);
    free(str);
    if (n > last_num + 1 && last_num != 0) {
        lost += n - (last_num + 1);
    }
    last_num = n;
    zmsg_destroy(&msg);
  }

  zsocket_destroy(context, socket);
  zctx_destroy(&context);

  printf("\nlost:     %7zu\nreceived: %7zu\n", lost, received);

  return 0;
}
Exemplo n.º 5
0
void *new_socket(zctx_t *ctx, int stype)
{
    void *s;

    s = zsocket_new(ctx, stype);
    assert(s);
    zsocket_set_linger(s, 0);
    zsocket_set_sndhwm(s, 100000);
    zsocket_set_rcvhwm(s, 100000);

    return(s);
}
Exemplo n.º 6
0
void *zeromq_create_socket (zctx_t *context, const char *endpoint, int type,
    const char *topic, bool connect, int linger, int hwm)
{

  void *socket = NULL;

  assert(context);
  assert(endpoint);

  if (endpoint[0] == 0) {
    errorLog("Trying to open NULL output socket !");
    return NULL;
  }

  socket = zsocket_new (context, type);
  if (hwm != -1) {
    zsocket_set_sndhwm (socket, hwm);
    zsocket_set_rcvhwm (socket, hwm);
  }

  if (linger != -1) {
    zsocket_set_linger (socket, linger);
  } else { // Set linger to 0 as default, safety measure
    zsocket_set_linger (socket, 0);
  }

  // Allow for exponential backoff: up to 5 minutes and 1s minimum
  zsocket_set_reconnect_ivl(socket, 1 * 1000);
  zsocket_set_reconnect_ivl_max(socket, 5 * 60 * 1000);

  if (type == ZMQ_SUB)
    zsocket_set_subscribe (socket, (char*)(topic == NULL ? "" : topic));

  if (connect) {
    zsocket_connect (socket, "%s", endpoint);
  } else {
    zsocket_bind (socket, "%s", endpoint);
  }
  return socket;
}
Exemplo n.º 7
0
static rsRetVal initZMQ(instanceData* pData) {
    DEFiRet;
    
    /* create the context if necessary. */
    if (NULL == s_context) {
        s_context = zctx_new();
        if (s_workerThreads > 0) zctx_set_iothreads(s_context, s_workerThreads);
    }
    
    pData->socket = zsocket_new(s_context, pData->type);

    /* ALWAYS set the HWM as the zmq3 default is 1000 and we default
       to 0 (infinity) */
    zsocket_set_rcvhwm(pData->socket, pData->rcvHWM);
    zsocket_set_sndhwm(pData->socket, pData->sndHWM);
    
    /* use czmq defaults for these, unless set to non-default values */
    if(pData->identity)             zsocket_set_identity(pData->socket, (char*)pData->identity);
    if(pData->sndBuf > -1)          zsocket_set_sndbuf(pData->socket, pData->sndBuf);
    if(pData->rcvBuf > -1)          zsocket_set_sndbuf(pData->socket, pData->rcvBuf);
    if(pData->linger > -1)          zsocket_set_linger(pData->socket, pData->linger);
    if(pData->backlog > -1)         zsocket_set_backlog(pData->socket, pData->backlog);
    if(pData->sndTimeout > -1)      zsocket_set_sndtimeo(pData->socket, pData->sndTimeout);
    if(pData->rcvTimeout > -1)      zsocket_set_rcvtimeo(pData->socket, pData->rcvTimeout);
    if(pData->maxMsgSize > -1)      zsocket_set_maxmsgsize(pData->socket, pData->maxMsgSize);
    if(pData->rate > -1)            zsocket_set_rate(pData->socket, pData->rate);
    if(pData->recoveryIVL > -1)     zsocket_set_recovery_ivl(pData->socket, pData->recoveryIVL);
    if(pData->multicastHops > -1)   zsocket_set_multicast_hops(pData->socket, pData->multicastHops);
    if(pData->reconnectIVL > -1)    zsocket_set_reconnect_ivl(pData->socket, pData->reconnectIVL);
    if(pData->reconnectIVLMax > -1) zsocket_set_reconnect_ivl_max(pData->socket, pData->reconnectIVLMax);
    if(pData->ipv4Only > -1)        zsocket_set_ipv4only(pData->socket, pData->ipv4Only);
    if(pData->affinity != 1)        zsocket_set_affinity(pData->socket, pData->affinity);
                                  
    /* bind or connect to it */
    if (pData->action == ACTION_BIND) {
        /* bind asserts, so no need to test return val here
           which isn't the greatest api -- oh well */
        zsocket_bind(pData->socket, (char*)pData->description);
    } else {
        if(zsocket_connect(pData->socket, (char*)pData->description) == -1) {
            errmsg.LogError(0, RS_RET_SUSPENDED, "omzmq3: connect failed!");
            ABORT_FINALIZE(RS_RET_SUSPENDED);
        }
    }
 finalize_it:
    RETiRet;
}
Exemplo n.º 8
0
int maltcp_ctx_destroy(void **self_p) {
  clog_debug(maltcp_logger, "maltcp_ctx_destroy...\n");
  if (self_p && *self_p) {
    maltcp_ctx_t *self = (maltcp_ctx_t *) *self_p;


    // TODO(AF): zmq_close versus zsocket_destroy
    zsocket_set_linger(self->endpoints_socket, 0);
    clog_debug(maltcp_logger, "maltcp_ctx_destroy: linger=%d\n", zsocket_linger(self->endpoints_socket));
    zsocket_destroy(self->zmq_ctx, self->endpoints_socket);
  //  zmq_close(mal_ctx->endpoints_socket);

    // Free all structures in hash-table, close socket and destroy mutex.
    if (self->cnx_table) {
      maltcp_ctx_connection_t *cnx_ptr =  (maltcp_ctx_connection_t*) zhash_first(self->cnx_table);
      while (cnx_ptr) {
        // Close registered TCP connections
        clog_debug(maltcp_logger, "maltcp_ctx_destroy: close socket %d.\n", cnx_ptr->socket);
        maltcp_ctx_socket_destroy(cnx_ptr);
        // destroy all registered sockets
        cnx_ptr = (maltcp_ctx_connection_t*) zhash_next(self->cnx_table);
      }
    }

    // TODO (AF): Close all pollers?
    clog_debug(maltcp_logger, "maltcp_ctx_destroy: stopped.\n");

    free(self->maltcp_header);
    // Free all structures in hash-table, close socket and destroy mutex.
    if (self->cnx_table)
      zhash_destroy(&self->cnx_table);
    zloop_destroy(&self->zloop);
//    zsocket_destroy(self->zmq_ctx, self->endpoints_socket);
//    zmq_close(self->endpoints_socket);
    zctx_destroy(&self->zmq_ctx);

    free(self);
    *self_p = NULL;
  }
  clog_debug(maltcp_logger, "maltcp_ctx_destroy: destroyed.\n");
  return 0;
}
Exemplo n.º 9
0
Arquivo: zsys.c Projeto: wysman/czmq
void *
zsys_socket (int type, const char *filename, size_t line_nbr)
{
    //  First time initialization; if the application is mixing
    //  its own threading calls with zsock, this may fail if two
    //  threads try to create sockets at the same time. In such
    //  apps, they MUST create a socket in the main program before
    //  starting any threads. If the app uses zactor for its threads
    //  then we can guarantee this to always be safe.
    zsys_init ();
    ZMUTEX_LOCK (s_mutex);
    void *handle = zmq_socket (s_process_ctx, type);
    //  Configure socket with process defaults
    zsocket_set_linger (handle, (int) s_linger);
#if (ZMQ_VERSION_MAJOR == 2)
    //  For ZeroMQ/2.x we use sndhwm for both send and receive
    zsocket_set_hwm (handle, s_sndhwm);
#else
    //  For later versions we use separate SNDHWM and RCVHWM
    zsocket_set_sndhwm (handle, (int) s_sndhwm);
    zsocket_set_rcvhwm (handle, (int) s_rcvhwm);
#   if defined (ZMQ_IPV6)
    zsocket_set_ipv6 (handle, s_ipv6);
#   else
    zsocket_set_ipv4only (handle, s_ipv6 ? 0 : 1);
#   endif
#endif
    //  Add socket to reference tracker so we can report leaks; this is
    //  done only when the caller passes a filename/line_nbr
    if (filename) {
        s_sockref_t *sockref = (s_sockref_t *) malloc (sizeof (s_sockref_t));
        sockref->handle = handle;
        sockref->type = type;
        sockref->filename = filename;
        sockref->line_nbr = line_nbr;
        zlist_append (s_sockref_list, sockref);
    }
    s_open_sockets++;
    ZMUTEX_UNLOCK (s_mutex);
    return handle;
}
Exemplo n.º 10
0
mq_socket_t *zero_create_simple_router_socket(mq_socket_context_t *ctx)
{
    mq_socket_t *s;

    tbx_type_malloc_clear(s, mq_socket_t, 1);

    s->type = MQ_SIMPLE_ROUTER;
    s->arg = zsocket_new((zctx_t *)ctx->arg, ZMQ_ROUTER);
    zsocket_set_linger(s->arg, 0);
    zsocket_set_sndhwm(s->arg, 100000);
    zsocket_set_rcvhwm(s->arg, 100000);
    s->destroy = zero_native_destroy;
    s->bind = zero_native_bind;
    s->connect = zero_native_connect;
    s->disconnect = zero_native_disconnect;
    s->poll_handle = zero_native_poll_handle;
    s->monitor = zero_native_monitor;
    s->send = zero_native_send;
    s->recv = zero_simple_router_recv;

    return(s);
}
Exemplo n.º 11
0
int main(int argc, char const * const *argv)
{
  int socket_count  = argc>1 ? atoi(argv[1]) : 1;
  int message_count = argc>2 ? atoi(argv[2]) : 100000;
  int rc;

  zctx_t *context = zctx_new();
  assert(context);
  zctx_set_sndhwm(context, 1);
  zctx_set_linger(context, 100);

  // zmq 2.2 only supports up to 512 sockets
  assert_x(ZMQ_VERSION <= 20200 && socket_count > 512,
           "zeromq < 3.2 only supports up to 512 sockets");

  void **sockets = zmalloc(socket_count * sizeof(void*));

  int j;
  for (j=0; j<socket_count; j++) {
    void *socket = zsocket_new(context, ZMQ_PUSH);
    if (NULL==socket) {
      printf("Error occurred during %dth call to zsocket_new: %s\n", j, zmq_strerror (errno));
      exit(1);
    }
    // zsocket_set_sndtimeo(socket, 10);
    zsocket_set_sndhwm(socket, 10);
    zsocket_set_linger(socket, 50);
    zsocket_set_reconnect_ivl(socket, 100); // 100 ms
    zsocket_set_reconnect_ivl_max(socket, 10 * 1000); // 10 s
    // printf("hwm %d\n", zsocket_hwm(socket));
    // printf("sndbuf %d\n", zsocket_sndbuf(socket));
    // printf("swap %d\n", zsocket_swap(socket));
    // printf("linger %d\n", zsocket_linger(socket));
    // printf("sndtimeo %d\n", zsocket_sndtimeo(socket));
    // printf("reconnect_ivl %d\n", zsocket_reconnect_ivl(socket));
    // printf("reconnect_ivl_max %d\n", zsocket_reconnect_ivl_max(socket));

    rc = zsocket_connect(socket, "tcp://localhost:12345");
    assert(rc==0);
    sockets[j] = socket;
    zclock_sleep(10); // sleep 10 ms
  }

  char data[MESSAGE_BODY_SIZE];
  memset(data, 'a', MESSAGE_BODY_SIZE);

  char *exchanges[2] = {"zmq-device-1", "zmq-device-2"};
  // char *keys[2] = {"1","2"};

  int i = 0, queued = 0, rejected = 0;
  for (i=0; i<message_count; i++) {
    if (zsys_interrupted)
      break;
    zmsg_t *message = zmsg_new();
    zmsg_addstr(message, exchanges[i%2]);
    zmsg_addstrf(message, "logjam.zmq.test.%d.%d", i%2, i);
    zmsg_addmem(message, data, MESSAGE_BODY_SIZE);
    // zmsg_dump(message);
    rc = zmsg_send_dont_wait(&message, sockets[i%socket_count]);
    assert(message == NULL);
    if (rc == 0) {
      queued++;
    } else {
      rejected++;
    }
    // usleep(20);
    usleep(1000);
  }

  printf("queued:   %8d\n", queued);
  printf("rejected: %8d\n", rejected);

  for (i=0;i<socket_count;i++) {
    zsocket_destroy(context, sockets[i]);
  }
  free(sockets);
  zctx_destroy(&context);

  return 0;
}
Exemplo n.º 12
0
static rsRetVal createSocket(socket_info* info, void** sock) {
    size_t ii;
    int rv;

    *sock = zsocket_new(s_context, info->type);
    if (!sock) {
		errmsg.LogError(0,
                        RS_RET_INVALID_PARAMS,
                        "zsocket_new failed: %s, for type %d",
                        strerror(errno),info->type);
		/* DK: invalid params seems right here */
        return RS_RET_INVALID_PARAMS;
    }

    /* Set options *before* the connect/bind. */
    if (info->identity)             zsocket_set_identity(*sock, info->identity);
    if (info->sndBuf > -1)          zsocket_set_sndbuf(*sock, info->sndBuf);
    if (info->rcvBuf > -1)          zsocket_set_rcvbuf(*sock, info->rcvBuf);
    if (info->linger > -1)          zsocket_set_linger(*sock, info->linger);
    if (info->backlog > -1)         zsocket_set_backlog(*sock, info->backlog);
    if (info->sndTimeout > -1)      zsocket_set_sndtimeo(*sock, info->sndTimeout);
    if (info->rcvTimeout > -1)      zsocket_set_rcvtimeo(*sock, info->rcvTimeout);
    if (info->maxMsgSize > -1)      zsocket_set_maxmsgsize(*sock, info->maxMsgSize);
    if (info->rate > -1)            zsocket_set_rate(*sock, info->rate);
    if (info->recoveryIVL > -1)     zsocket_set_recovery_ivl(*sock, info->recoveryIVL);
    if (info->multicastHops > -1)   zsocket_set_multicast_hops(*sock, info->multicastHops);
    if (info->reconnectIVL > -1)    zsocket_set_reconnect_ivl(*sock, info->reconnectIVL);
    if (info->reconnectIVLMax > -1) zsocket_set_reconnect_ivl_max(*sock, info->reconnectIVLMax);
    if (info->ipv4Only > -1)        zsocket_set_ipv4only(*sock, info->ipv4Only);
    if (info->affinity > -1)        zsocket_set_affinity(*sock, info->affinity);
   
    /* since HWM have defaults, we always set them.  No return codes to check, either.*/
    zsocket_set_sndhwm(*sock, info->sndHWM);
    zsocket_set_rcvhwm(*sock, info->rcvHWM);

    /* Set subscriptions.*/
    if (info->type == ZMQ_SUB) {
	    for (ii = 0; ii < sizeof(info->subscriptions)/sizeof(char*); ++ii)
		zsocket_set_subscribe(*sock, info->subscriptions[ii]);
    }

    

    /* Do the bind/connect... */
    if (info->action==ACTION_CONNECT) {
        rv = zsocket_connect(*sock, info->description);
        if (rv < 0) {
            errmsg.LogError(0,
                            RS_RET_INVALID_PARAMS,
                            "zmq_connect using %s failed: %s",
                            info->description, strerror(errno));
            return RS_RET_INVALID_PARAMS;
        }
    } else {
        rv = zsocket_bind(*sock, info->description);
        if (rv <= 0) {
            errmsg.LogError(0,
                            RS_RET_INVALID_PARAMS,
                            "zmq_bind using %s failed: %s",
                            info->description, strerror(errno));
            return RS_RET_INVALID_PARAMS;
        }
    }
    return RS_RET_OK;
}
Exemplo n.º 13
0
int
zsockopt_test (bool verbose)
{
    printf (" * zsockopt: ");

    //  @selftest
    zctx_t *ctx = zctx_new ();
    assert (ctx);
    void *zocket;
#if (ZMQ_VERSION_MAJOR == 2)
#       if defined (ZMQ_HWM)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_hwm (zocket, 1);
    assert (zsocket_hwm (zocket) == 1);
    zsocket_hwm (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_SWAP)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_swap (zocket, 1);
    assert (zsocket_swap (zocket) == 1);
    zsocket_swap (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_AFFINITY)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_affinity (zocket, 1);
    assert (zsocket_affinity (zocket) == 1);
    zsocket_affinity (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_IDENTITY)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_identity (zocket, "test");
    char *identity = zsocket_identity (zocket);
    assert (identity);
    free (identity);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RATE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_rate (zocket, 1);
    assert (zsocket_rate (zocket) == 1);
    zsocket_rate (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RECOVERY_IVL)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_recovery_ivl (zocket, 1);
    assert (zsocket_recovery_ivl (zocket) == 1);
    zsocket_recovery_ivl (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RECOVERY_IVL_MSEC)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_recovery_ivl_msec (zocket, 1);
    assert (zsocket_recovery_ivl_msec (zocket) == 1);
    zsocket_recovery_ivl_msec (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_MCAST_LOOP)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_mcast_loop (zocket, 1);
    assert (zsocket_mcast_loop (zocket) == 1);
    zsocket_mcast_loop (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#   if (ZMQ_VERSION_MINOR == 2)
#       if defined (ZMQ_RCVTIMEO)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_rcvtimeo (zocket, 1);
    assert (zsocket_rcvtimeo (zocket) == 1);
    zsocket_rcvtimeo (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#   endif
#   if (ZMQ_VERSION_MINOR == 2)
#       if defined (ZMQ_SNDTIMEO)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_sndtimeo (zocket, 1);
    assert (zsocket_sndtimeo (zocket) == 1);
    zsocket_sndtimeo (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#   endif
#       if defined (ZMQ_SNDBUF)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_sndbuf (zocket, 1);
    assert (zsocket_sndbuf (zocket) == 1);
    zsocket_sndbuf (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RCVBUF)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_rcvbuf (zocket, 1);
    assert (zsocket_rcvbuf (zocket) == 1);
    zsocket_rcvbuf (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_LINGER)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_linger (zocket, 1);
    assert (zsocket_linger (zocket) == 1);
    zsocket_linger (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RECONNECT_IVL)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_reconnect_ivl (zocket, 1);
    assert (zsocket_reconnect_ivl (zocket) == 1);
    zsocket_reconnect_ivl (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RECONNECT_IVL_MAX)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_reconnect_ivl_max (zocket, 1);
    assert (zsocket_reconnect_ivl_max (zocket) == 1);
    zsocket_reconnect_ivl_max (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_BACKLOG)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_backlog (zocket, 1);
    assert (zsocket_backlog (zocket) == 1);
    zsocket_backlog (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_SUBSCRIBE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_subscribe (zocket, "test");
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_UNSUBSCRIBE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_unsubscribe (zocket, "test");
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_TYPE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_type (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RCVMORE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_rcvmore (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_FD)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_fd (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_EVENTS)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_events (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#endif

#if (ZMQ_VERSION_MAJOR == 3)
#       if defined (ZMQ_TYPE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_type (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_SNDHWM)
    zocket = zsocket_new (ctx, ZMQ_PUB);
    assert (zocket);
    zsocket_set_sndhwm (zocket, 1);
    assert (zsocket_sndhwm (zocket) == 1);
    zsocket_sndhwm (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RCVHWM)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_rcvhwm (zocket, 1);
    assert (zsocket_rcvhwm (zocket) == 1);
    zsocket_rcvhwm (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_AFFINITY)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_affinity (zocket, 1);
    assert (zsocket_affinity (zocket) == 1);
    zsocket_affinity (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_SUBSCRIBE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_subscribe (zocket, "test");
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_UNSUBSCRIBE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_unsubscribe (zocket, "test");
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_IDENTITY)
    zocket = zsocket_new (ctx, ZMQ_DEALER);
    assert (zocket);
    zsocket_set_identity (zocket, "test");
    char *identity = zsocket_identity (zocket);
    assert (identity);
    free (identity);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RATE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_rate (zocket, 1);
    assert (zsocket_rate (zocket) == 1);
    zsocket_rate (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RECOVERY_IVL)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_recovery_ivl (zocket, 1);
    assert (zsocket_recovery_ivl (zocket) == 1);
    zsocket_recovery_ivl (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_SNDBUF)
    zocket = zsocket_new (ctx, ZMQ_PUB);
    assert (zocket);
    zsocket_set_sndbuf (zocket, 1);
    assert (zsocket_sndbuf (zocket) == 1);
    zsocket_sndbuf (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RCVBUF)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_rcvbuf (zocket, 1);
    assert (zsocket_rcvbuf (zocket) == 1);
    zsocket_rcvbuf (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_LINGER)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_linger (zocket, 1);
    assert (zsocket_linger (zocket) == 1);
    zsocket_linger (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RECONNECT_IVL)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_reconnect_ivl (zocket, 1);
    assert (zsocket_reconnect_ivl (zocket) == 1);
    zsocket_reconnect_ivl (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RECONNECT_IVL_MAX)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_reconnect_ivl_max (zocket, 1);
    assert (zsocket_reconnect_ivl_max (zocket) == 1);
    zsocket_reconnect_ivl_max (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_BACKLOG)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_backlog (zocket, 1);
    assert (zsocket_backlog (zocket) == 1);
    zsocket_backlog (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_MAXMSGSIZE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_maxmsgsize (zocket, 1);
    assert (zsocket_maxmsgsize (zocket) == 1);
    zsocket_maxmsgsize (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_MULTICAST_HOPS)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_multicast_hops (zocket, 1);
    assert (zsocket_multicast_hops (zocket) == 1);
    zsocket_multicast_hops (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RCVTIMEO)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_rcvtimeo (zocket, 1);
    assert (zsocket_rcvtimeo (zocket) == 1);
    zsocket_rcvtimeo (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_SNDTIMEO)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_sndtimeo (zocket, 1);
    assert (zsocket_sndtimeo (zocket) == 1);
    zsocket_sndtimeo (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_IPV4ONLY)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_set_ipv4only (zocket, 1);
    assert (zsocket_ipv4only (zocket) == 1);
    zsocket_ipv4only (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_DELAY_ATTACH_ON_CONNECT)
    zocket = zsocket_new (ctx, ZMQ_PUB);
    assert (zocket);
    zsocket_set_delay_attach_on_connect (zocket, 1);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_ROUTER_MANDATORY)
    zocket = zsocket_new (ctx, ZMQ_ROUTER);
    assert (zocket);
    zsocket_set_router_mandatory (zocket, 1);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_ROUTER_RAW)
    zocket = zsocket_new (ctx, ZMQ_ROUTER);
    assert (zocket);
    zsocket_set_router_raw (zocket, 1);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_XPUB_VERBOSE)
    zocket = zsocket_new (ctx, ZMQ_XPUB);
    assert (zocket);
    zsocket_set_xpub_verbose (zocket, 1);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_RCVMORE)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_rcvmore (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_FD)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_fd (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_EVENTS)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    zsocket_events (zocket);
    zsocket_destroy (ctx, zocket);
#       endif
#       if defined (ZMQ_LAST_ENDPOINT)
    zocket = zsocket_new (ctx, ZMQ_SUB);
    assert (zocket);
    char *last_endpoint = zsocket_last_endpoint (zocket);
    assert (last_endpoint);
    free (last_endpoint);
    zsocket_destroy (ctx, zocket);
#       endif

    zocket = zsocket_new (ctx, ZMQ_SUB);
    zsocket_set_hwm (zocket, 1);
#endif

    zctx_destroy (&ctx);
    //  @end

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