当前位置: 首页>>代码示例>>C++>>正文


C++ zmq_msg_init函数代码示例

本文整理汇总了C++中zmq_msg_init函数的典型用法代码示例。如果您正苦于以下问题:C++ zmq_msg_init函数的具体用法?C++ zmq_msg_init怎么用?C++ zmq_msg_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zmq_msg_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: send_response

static void send_response(void *sock, int internal_status, int exit_status)
{
	void *buf;
	int len;

	CqRep rep = CQ_REP__INIT;
	zmq_msg_t msg;
	zmq_msg_init(&msg);

	rep.exit_status = exit_status;
	rep.internal_status = internal_status;

	len = cq_rep__get_packed_size(&rep);
	buf = malloc(len);
	cq_rep__pack(&rep, buf);

	zmq_msg_init_data(&msg, buf, len, free_buf, NULL);

	zmq_msg_send(&msg, sock, 0);

	zmq_msg_close(&msg);
}
开发者ID:RPI-HPC,项目名称:cq,代码行数:22,代码来源:server.c

示例2: do_read

/**
 * Issue a read on the socket.
 */
static zmq_msg_t* do_read(JNIEnv *env, jobject obj, zmq_msg_t *message, int flags)
{
    void *s = get_socket (env, obj);

    int rc = zmq_msg_init (message);
    if (rc != 0) {
        raise_exception (env, zmq_errno());
        return NULL;
    }

#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3,0,0)
    rc = zmq_recvmsg (s, message, flags);
#else
    rc = zmq_recv (s, message, flags);
#endif
    int err = zmq_errno();
    if (rc < 0 && err == EAGAIN) {
        rc = zmq_msg_close (message);
        err = zmq_errno();
        if (rc != 0) {
            raise_exception (env, err);
            return NULL;
        }
        return NULL;
    }

    if (rc < 0) {
        raise_exception (env, err);
        rc = zmq_msg_close (message);
        err = zmq_errno();
        if (rc != 0) {
            raise_exception (env, err);
            return NULL;
        }
        return NULL;
    }
    
    return message;
}
开发者ID:hawkproject,项目名称:hawksource,代码行数:42,代码来源:Socket.cpp

示例3: handler_recv_parse

static inline int handler_recv_parse(Handler *handler, HandlerParser *parser)
{
    check(handler->running, "Called while handler wasn't running, that's not good.");

    zmq_msg_t *inmsg = calloc(sizeof(zmq_msg_t), 1);
    int rc = 0;

    check_mem(inmsg);

    rc = zmq_msg_init(inmsg);
    check(rc == 0, "Failed to initialize message.");

    taskstate("recv");

    rc = mqrecv(handler->recv_socket, inmsg, ZMQ_NOBLOCK);
    check(rc == 0, "Receive on handler socket failed.");
    check(handler->running, "Received shutdown notification, goodbye.");

    rc = HandlerParser_execute(parser, zmq_msg_data(inmsg), zmq_msg_size(inmsg));
    check(rc == 1, "Failed to parse message from handler.");

    check(parser->target_count > 0, "Message sent had 0 targets: %.*s",
            (int)zmq_msg_size(inmsg), (char *)zmq_msg_data(inmsg));

    debug("Parsed message with %d targets, first: %d, uuid: %s, and body: %d",
            (int)parser->target_count, parser->targets[0],
            bdata(parser->uuid), blength(parser->body));

    zmq_msg_close(inmsg);
    free(inmsg);
    return 0;

error:
    if(inmsg) {
        zmq_msg_close(inmsg);
        free(inmsg);
    }
    return -1;
}
开发者ID:derdewey,项目名称:mongrel2,代码行数:39,代码来源:handler.c

示例4: main

int main(int argc, char *argv[])
{
    if (argc < 3) return EXIT_FAILURE;
    int M = atoi(argv[1]);
    int N = atoi(argv[2]);
    printf("M: %d, N: %d\n", M, N);

    void *ctx = zmq_init(1);
    void *b = zmq_socket(ctx, ZMQ_PAIR);
    zmq_connect(b, "tcp://localhost:4444");

    zmq_msg_t msg;
    int val[M];
    long long start_time = sc_time();

    int i;
    for (i=0; i<N; i++) {
        int *buf = (int *)malloc(M * sizeof(int));
        memset(val, i, M * sizeof(int));
        memcpy(buf, val, M * sizeof(int));
        zmq_msg_init_data(&msg, buf, M * sizeof(int), _dealloc, NULL);
        zmq_send(b, &msg, 0);
        zmq_msg_close(&msg);

        zmq_msg_init(&msg);
        zmq_recv(b, &msg, 0);
        memcpy(val, (int *)zmq_msg_data(&msg), zmq_msg_size(&msg));
        zmq_msg_close(&msg);
    }

    long long end_time = sc_time();

    printf("zmq_a: Time elapsed: %f sec\n", sc_time_diff(start_time, end_time));

    zmq_close(b);
    zmq_term(ctx);

    return EXIT_SUCCESS;
}
开发者ID:braman,项目名称:sessc,代码行数:39,代码来源:zmq_a.c

示例5: zmq_msg_init

int zmq::pair_t::xsend (zmq_msg_t *msg_, int flags_)
{
    if (outpipe == NULL || !outpipe_alive) {
        errno = EAGAIN;
        return -1;
    }

    if (!outpipe->write (msg_)) {
        outpipe_alive = false;
        errno = EAGAIN;
        return -1;
    }

    if (!(flags_ & ZMQ_SNDMORE))
        outpipe->flush ();

    //  Detach the original message from the data buffer.
    int rc = zmq_msg_init (msg_);
    zmq_assert (rc == 0);

    return 0;
}
开发者ID:Strongc,项目名称:playasa,代码行数:22,代码来源:pair.cpp

示例6: main

int main (void) {
    setup_test_environment ();
    void *ctx = zmq_ctx_new ();
    assert (ctx);
    
    void *stream = zmq_socket (ctx, ZMQ_STREAM);
    assert (stream);
    void *dealer = zmq_socket (ctx, ZMQ_DEALER);
    assert (dealer);
    
    int rc = zmq_bind (stream, "tcp://127.0.0.1:5555");
    assert (rc >= 0);
    rc = zmq_connect (dealer, "tcp://127.0.0.1:5555");
    assert (rc >= 0);
    zmq_send (dealer, "", 0, 0);
    
    zmq_msg_t ident, empty;
    zmq_msg_init (&ident);
    rc = zmq_msg_recv (&ident, stream, 0);
    assert (rc >= 0);
    rc = zmq_msg_init_data (&empty, (void *) "", 0, NULL, NULL);
    assert (rc >= 0);
    
    rc = zmq_msg_send (&ident, stream, ZMQ_SNDMORE);
    assert (rc >= 0);
    rc = zmq_msg_close (&ident);
    assert (rc >= 0);
    
    rc = zmq_msg_send (&empty, stream, 0);
    assert (rc >= 0);
    
    //  This close used to fail with Bad Address
    rc = zmq_msg_close (&empty);
    assert (rc >= 0);
    
    close_zero_linger (dealer);
    close_zero_linger (stream);
    zmq_ctx_term (ctx);
}
开发者ID:AimuTran,项目名称:avbot,代码行数:39,代码来源:test_stream_empty.cpp

示例7: main

int main (int argc, char const *argv[]) {

  void* context = zmq_ctx_new();
  //create a SUB socket
  void* subscriber = zmq_socket(context, ZMQ_SUB);

  const char* filter;
  
  if(argc > 1) {
    filter = argv[1];
  } else {
    filter = "Company1|";
  }
  printf("Collecting stock information from the server.\n");

  int conn = zmq_connect(subscriber, "tcp://localhost:4040");
  // must set a subscription for SUB socket
  conn = zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, filter, strlen(filter));

  int i = 0;
  for(i = 0; i < 10; i++) {
    zmq_msg_t reply;
    zmq_msg_init(&reply);
    // receive the message, previous message is deallocated
    zmq_msg_recv(&reply, subscriber, 0);
    
    int length = zmq_msg_size(&reply);
    char* value = malloc(length + 1);
    memcpy(value, zmq_msg_data(&reply), length);
    zmq_msg_close(&reply);
    printf("%s\n", value);    
    free(value);

  }
  zmq_close(subscriber);
  zmq_ctx_destroy(context);

  return 0;
}
开发者ID:vishalsanfran,项目名称:network-programming,代码行数:39,代码来源:zeroMQ-subscribe.c

示例8: zmq_socket

void Executor::work()
{
    void *socket = zmq_socket(vcontext, ZMQ_REP);
    zmq_msg_t zMsg;
    char *cstring = NULL;
    size_t msgSize = 0;
    
    zmq_connect(socket, "inproc://storageWorkers");
    
    while(vstop==false)
    {
        zmq_msg_init(&zMsg);
        zmq_msg_recv(&zMsg, socket, 0);
        msgSize = zmq_msg_size(&zMsg);
        cstring = new char[msgSize+1];
        memcpy(cstring, zmq_msg_data(&zMsg), msgSize);
        zmq_msg_close(&zMsg);
        cstring[msgSize] = '\0';
        std::string str(cstring);
        delete cstring;

        Message* msg = vmsgFactory->parse(str);

        Action *action = vactionFactory->parse(*msg);
        delete msg;

        msg = action->execute();
        delete action;

        msgSize = msg->toString().size()+1;
        zmq_msg_init_size(&zMsg, msgSize);
        memcpy(zmq_msg_data(&zMsg), msg->toString().c_str(), msgSize);
        delete msg;
        zmq_msg_send(&zMsg, socket, 0);
        zmq_msg_close(&zMsg);
    }
    zmq_close(socket);
}    
开发者ID:ATNoG,项目名称:remoteLevelDB,代码行数:38,代码来源:Executor.cpp

示例9: main

int main (void)
{
    void *context = zmq_init (1);

    //  This is where the weather server sits
    void *frontend = zmq_socket (context, ZMQ_XSUB);
    zmq_connect (frontend, "tcp://192.168.55.210:5556");

    //  This is our public endpoint for subscribers
    void *backend = zmq_socket (context, ZMQ_XPUB);
    zmq_bind (backend, "tcp://10.1.1.0:8100");

    //  Subscribe on everything
    zmq_setsockopt (frontend, ZMQ_SUBSCRIBE, "", 0);

    //  Shunt messages out to our own subscribers
    while (1) {
        while (1) {
            zmq_msg_t message;
            int64_t more;

            //  Process all parts of the message
            zmq_msg_init (&message);
            zmq_recv (frontend, &message, 0);
            size_t more_size = sizeof (more);
            zmq_getsockopt (frontend, ZMQ_RCVMORE, &more, &more_size);
            zmq_send (backend, &message, more? ZMQ_SNDMORE: 0);
            zmq_msg_close (&message);
            if (!more)
                break;      //  Last message part
        }
    }
    //  We don't actually get here but if we did, we'd shut down neatly
    zmq_close (frontend);
    zmq_close (backend);
    zmq_term (context);
    return 0;
}
开发者ID:Double-Lv,项目名称:zguide2,代码行数:38,代码来源:wuproxy.c

示例10: main

// This main thread simply starts several clients, and a server, and then
// waits for the server to finish.
//
int main (void)
{
    void *context = zmq_init (1);

    // Backend socket talks to workers over inproc
    void *pipein = zmq_socket (context, ZMQ_DEALER);
    zsocket_bind (pipein, "inproc://pipe");

    // Frontend socket talks to clients over TCP
    void *pipeout = zmq_socket (context, ZMQ_ROUTER);
    zsocket_connect (pipeout, "inproc://pipe");

    zstr_send (pipein, "ABC");
    
    int rc;
    zmq_msg_t msg;
    zmq_msg_init (&msg);
    rc = zmq_recvmsg (pipeout, &msg, 0);
    if (rc < 0) {
        printf ("E: error, failed\n");
        exit (1);
    }
    int rcvmore;
    size_t type_size = sizeof (int);
    rc = zmq_getsockopt (pipeout, ZMQ_RCVMORE, &rcvmore, &type_size);
    if (rc)
        puts (strerror (errno));
    assert (rc == 0);

    int rcvlabel;
    zmq_getsockopt (pipeout, ZMQ_RCVLABEL, &rcvlabel, &type_size);
    assert (rc == 0);

    printf ("Got first message part: size=%zd more=%d label=%d\n",
        zmq_msg_size (&msg), rcvmore, rcvlabel);

    return 0;
}
开发者ID:amrali,项目名称:issues,代码行数:41,代码来源:issue.c

示例11: kill_server

int kill_server(){
    char addr[32];
    void *ctx = main_ctx;

    snprintf(addr, 32, "tcp://%s:%d", GlobalArgs.server_address, GlobalArgs.port + 1);
    void *skt = socket_connect(ctx, ZMQ_REQ, addr);
    if (!skt){
	syslog(LOG_CRIT,"KILLSERVER: unable to get req skt");
	return -1;
    }

    uint8_t tn = table_number;
    table_number = 0;

    char *tmpstr = strdup(kill_str);
    sendmore_msg_data(skt, tmpstr, strlen(tmpstr)+1, free_fn, NULL);
    send_msg_vsm(skt, &tn, sizeof(uint8_t));

    time_t curr_time;
    time(&curr_time);

    zmq_msg_t msg;
    zmq_msg_init(&msg);
    int err = 0;
    do {
	err = zmq_recv(skt, &msg, ZMQ_NOBLOCK);
	sleep(1);
    } while (err && time(NULL) < curr_time + 10 );
    if (err){
	syslog(LOG_ERR, "KILLSERVER: no ack recieved - ignore");
	err = -1;
    }

    zmq_close(skt);
    syslog(LOG_DEBUG,"KILLSERVER: server killed");

    return err;
}
开发者ID:abhay123lp,项目名称:audioscout,代码行数:38,代码来源:table_server.c

示例12: worker_routine

// worker thread function
static void* worker_routine (void *context)
{
	// socket to talk to dispatcher
	void* receiver = zmq_socket(context, ZMQ_REP); 
	if (!receiver) 
	{
		dzlog_error("create socket to talk to dispatcher failed, err: %s", zmq_strerror(errno));
		return NULL;
	}

	if (zmq_connect(receiver, "inproc://workers") != 0)
	{
		dzlog_error("worker thread connect worker_socket failed, err: %s", zmq_strerror(errno));
		return NULL;
	}

	dzlog_info("worker thread run ...");

	while (1) 
	{
		zmq_msg_t request;
		zmq_msg_init(&request);
		zmq_recvmsg(receiver, &request, 0); 
		printf("Recv Hello\n"); 
		zmq_msg_close(&request);

		sleep(1);
		
		zmq_msg_t reply;
		zmq_msg_init_size(&reply, 5);
		memcpy(zmq_msg_data (&reply), "World", 5); 
		zmq_sendmsg(receiver, &reply, 0); 
		zmq_msg_close(&reply);
	}

	zmq_close (receiver);
	return NULL;
}
开发者ID:junglefire,项目名称:Raptor,代码行数:39,代码来源:raptor_proxy.c

示例13: subscriber_thread_main

static void subscriber_thread_main (void *pvoid)
{
    const proxy_hwm_cfg_t *cfg = (proxy_hwm_cfg_t *) pvoid;
    const int idx = cfg->thread_idx;

    void *subsocket = zmq_socket (cfg->context, ZMQ_SUB);
    assert (subsocket);

    set_hwm (subsocket);

    TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (subsocket, ZMQ_SUBSCRIBE, 0, 0));

    TEST_ASSERT_SUCCESS_ERRNO (
      zmq_connect (subsocket, cfg->backend_endpoint[idx]));

    //  Receive message_count messages
    uint64_t rxsuccess = 0;
    bool success = true;
    while (success) {
        zmq_msg_t msg;
        int rc = zmq_msg_init (&msg);
        assert (rc == 0);

        rc = zmq_msg_recv (&msg, subsocket, 0);
        if (rc != -1) {
            TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg));
            rxsuccess++;
        }

        if (rxsuccess == message_count)
            break;
    }

    //  Cleanup

    zmq_close (subsocket);
    printf ("subscriber thread ended\n");
}
开发者ID:somdoron,项目名称:libzmq,代码行数:38,代码来源:proxy_thr.cpp

示例14: zmq_msg_size

int zmq::xsub_t::xsend (zmq_msg_t *msg_, int options_)
{
    size_t size = zmq_msg_size (msg_);
    unsigned char *data = (unsigned char*) zmq_msg_data (msg_);

    //  Malformed subscriptions are dropped silently.
    if (size >= 1) {

        //  Process a subscription.
        if (*data == 1)
            subscriptions.add (data + 1, size - 1);

        //  Process an unsubscription. Invalid unsubscription is ignored.
        if (*data == 0)
            subscriptions.rm (data + 1, size - 1);
    }

    int rc = zmq_msg_close (msg_);
    zmq_assert (rc == 0);
    rc = zmq_msg_init (msg_);
    zmq_assert (rc == 0);
    return 0;
}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:23,代码来源:xsub.cpp

示例15: input_reaper

void input_reaper(void * insock) {
	while(1) {
		zmq_msg_t input;
		zmq_msg_init(&input);

		if(zmq_msg_recv(&input, insock, ZMQ_DONTWAIT) == -1) {
			if(errno == EAGAIN)
				break;
			else if(errno == EINTR)
				continue;
			syslog(LOG_ERR, "Error receiving message from interface: %s",
				zmq_strerror(errno));
			continue;
		}

		if(insock == pullsock)
			process_pull_msg(&input);
		else if(insock == reqsock)
			process_req_msg(&input);

		zmq_msg_close(&input);
	}
}
开发者ID:NixM0nk3y,项目名称:nagmq,代码行数:23,代码来源:common.c


注:本文中的zmq_msg_init函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。