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


C++ zmq_msg_init_data函数代码示例

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


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

示例1: assert

void reply_message::emit(libfault::zmq_msg_vector& msg) {
  assert(zmqbodyused == false);
  // first block is the reply status
  zmq_msg_t* z_status = msg.insert_back();
  zmq_msg_init_size(z_status, sizeof(reply_status));
  (*reinterpret_cast<reply_status*>(zmq_msg_data(z_status))) = status;

  // second block is the property bag
  graphlab::oarchive oarc;
  oarc << properties;
  zmq_msg_t* z_propertybag = msg.insert_back();
  zmq_msg_init_data(z_propertybag, oarc.buf, oarc.off, 
                    libfault::zmq_msg_standard_free, NULL);

  // third block is the serialization body
  zmq_msg_t* z_body= msg.insert_back();

  if (body != NULL) {
    zmq_msg_init_data(z_body, body, bodylen, libfault::zmq_msg_standard_free, NULL);
  }
  
  // we are giving away the body pointer
  body = NULL;
  clear();
}
开发者ID:Bhushan1002,项目名称:SFrame,代码行数:25,代码来源:message_types.cpp

示例2: send_int_array

int send_int_array(const int arr[], size_t count, role *r, const char *label)
{
  int rc = 0;
  zmq_msg_t msg;
  size_t size = sizeof(int) * count;


#ifdef __DEBUG__
  fprintf(stderr, " --> %s ", __FUNCTION__);
#endif

  if (label != NULL) {
#ifdef __DEBUG__
    fprintf(stderr, "{label: %s}", label);
#endif
    zmq_msg_t msg_label;
    char *buf_label = (char *)calloc(sizeof(char), strlen(label));
    memcpy(buf_label, label, strlen(label));
    zmq_msg_init_data(&msg_label, buf_label, strlen(label), _dealloc, NULL);
    switch (r->type) {
      case SESSION_ROLE_P2P:
        rc = zmq_msg_send(r->p2p->ptr, &msg_label, ZMQ_SNDMORE);
        break;
      case SESSION_ROLE_GRP:
        rc = zmq_msg_send(r->grp->out->ptr, &msg_label, ZMQ_SNDMORE);
        break;
    default:
        fprintf(stderr, "%s: Unknown endpoint type: %d\n", __FUNCTION__, r->type);
    }
    zmq_msg_close(&msg_label);
  }

  int *buf = (int *)malloc(size);
  memcpy(buf, arr, size);

  zmq_msg_init_data(&msg, buf, size, _dealloc, NULL);
  switch (r->type) {
    case SESSION_ROLE_P2P:
      rc = zmq_msg_send(r->p2p->ptr, &msg, 0);
      break;
    case SESSION_ROLE_GRP:
#ifdef __DEBUG__
      fprintf(stderr, "bcast -> %s(%d endpoints) ", r->grp->name, r->grp->nendpoint);
#endif
      rc = zmq_msg_send(r->grp->out->ptr, &msg, 0);
      break;
    default:
      fprintf(stderr, "%s: Unknown endpoint type: %d\n", __FUNCTION__, r->type);
  }
  zmq_msg_close(&msg);

  if (rc != 0) perror(__FUNCTION__);
 
#ifdef __DEBUG__
  fprintf(stderr, ".\n");
#endif

  return rc;
}
开发者ID:D4vidH4mm3r,项目名称:sessc,代码行数:59,代码来源:primitives.c

示例3: uwsgi_proto_zeromq_write

ssize_t uwsgi_proto_zeromq_write(struct wsgi_request * wsgi_req, char *buf, size_t len) {
	zmq_msg_t reply;
	char *zmq_body;

	if (len == 0)
		return 0;

	zmq_body = uwsgi_concat2n(wsgi_req->proto_parser_buf, (int) wsgi_req->proto_parser_pos, buf, (int) len);

	//uwsgi_log("|%.*s|\n", (int)wsgi_req->proto_parser_pos+len, zmq_body);

	zmq_msg_init_data(&reply, zmq_body, wsgi_req->proto_parser_pos + len, uwsgi_proto_zeromq_free, NULL);
	if (uwsgi.threads > 1) pthread_mutex_lock(&uwsgi.zmq_lock);
	if (zmq_send(uwsgi.zmq_pub, &reply, 0)) {
		if (!uwsgi.ignore_write_errors) {
			uwsgi_error("zmq_send()");
		}
		wsgi_req->write_errors++;
		if (uwsgi.threads > 1) pthread_mutex_unlock(&uwsgi.zmq_lock);
		zmq_msg_close(&reply);
		return 0;
	}
	if (uwsgi.threads > 1) pthread_mutex_unlock(&uwsgi.zmq_lock);
	zmq_msg_close(&reply);

	return len;
}
开发者ID:theflockers,项目名称:file-uploader,代码行数:27,代码来源:zeromq.c

示例4: Log_request

int Log_request(Connection *conn, int status, int size)
{
    zmq_msg_t msg;

    if(LOG_SOCKET == NULL) 
        return 0;

    bstring log_data = make_log_message(conn->req, conn->remote, conn->rport, status, size);
    check_mem(log_data);

    int rc = zmq_msg_init_data(&msg, bdata(log_data), blength(log_data),
            free_log_msg, log_data);
    check(rc == 0, "Could not craft message for log message '%s'.", bdata(log_data));
    
    rc = zmq_msg_send(&msg, LOG_SOCKET, 0);
    check(rc >= 0, "Could not send log message to socket.");

    log_data = NULL; // that way errors from above can clean the log_data
    rc = zmq_msg_close(&msg);
    check(rc == 0, "Failed to close message object.");

    return 0;

error:
    bdestroy(log_data);
    zmq_msg_close(&msg);
    return -1;
}
开发者ID:304471720,项目名称:mongrel2,代码行数:28,代码来源:log.c

示例5: main

int main()
{
    void *ctx, *s;
    zmq_msg_t query, result;

    ctx = zmq_init(1);

    s = zmq_socket(ctx, ZMQ_REP);

    if (zmq_bind(s, "tcp://127.0.0.1:5554") < 0) {
        printf("could not bind\n");
        exit(-1);
    }

    while (1) {
        printf("listening...\n");
        zmq_msg_init(&query);
        zmq_recv(s, &query, 0);

        int msg_len = zmq_msg_size(&query) + 1;
        char *out = (char *) malloc(msg_len);
        snprintf(out, msg_len, "%s", (char *) zmq_msg_data(&query));
        out[msg_len-1]='\0';
        printf("%s\n", out);
        zmq_msg_close(&query);
        free(out);

        zmq_msg_init_data(&result, reply, strlen(reply), NULL, NULL);
        zmq_send(s, &result, 0);
        zmq_msg_close(&result);
    }
}
开发者ID:JustinTulloss,项目名称:0mq-playground,代码行数:32,代码来源:server.c

示例6: main

int
main(int argc, char *argv)
{
    int i = 0;
    char msg[10] = "aaaaaaaaaa";

    void *context = zmq_init(1);
    void *sender = zmq_socket(context, ZMQ_PUSH);
    zmq_msg_t m;

    printf("%d bind\n", zmq_bind(sender, "tcp://*:3333"));
    //printf("%d bind\n", zmq_bind(sender, "ipc:///tmp/zmqpy_bench"));

    for (i = 0; i < 10000000; i++) {
        if (i % 10000 == 0)
            printf("%d\n", i);

#if (ZMQ_VERSION_MAJOR == 3)
        zmq_send(sender, msg, 10, 0);
#else
        zmq_msg_init_data(&m, msg, 10, NULL, 0);
        zmq_send(sender, &m, 0);
        zmq_msg_close(&m);
#endif
    }

    zmq_close(sender);
    zmq_term(context);
}
开发者ID:pfw,项目名称:zmqpy,代码行数:29,代码来源:sender.c

示例7: tmp

// Move operators will take ownership of message parts without copying
void message::move(void* part, size_t& size, release_function const& release)
{
	parts_type tmp(_parts.size() + 1);

	for(size_t i = 0; i < _parts.size(); ++i)
	{
		zmq_msg_t& dest = tmp[i].msg;
		if( 0 != zmq_msg_init(&dest) )
		{
			throw zmq_internal_exception();
		}

		zmq_msg_t& src = _parts[i].msg;
		if( 0 != zmq_msg_move(&dest, &src) )
		{
			throw zmq_internal_exception();
		}
	}

	std::swap(tmp, _parts);

	callback_releaser* hint = new callback_releaser();
	hint->func = release;

	zmq_msg_t& msg = _parts.back().msg;
	if (0 != zmq_msg_init_data(&msg, part, size, &message::release_callback, hint))
	{
		throw zmq_internal_exception();
	}
}
开发者ID:Fantasticer,项目名称:zmqpp,代码行数:31,代码来源:message.cpp

示例8: main

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

    //  Socket to talk to clients
    void *responder = zmq_socket (context, ZMQ_REP);
    zmq_bind (responder, "tcp://*:5555");

    while (1) {
        //  Wait for next request from client
        zmq_msg_t request;
        zmq_msg_init (&request);
        zmq_recv (responder, &request, 0);
        printf ("Received Hello\n");
        zmq_msg_close (&request);

        //  Do some 'work'
        sleep (1);

        //  Send reply back to client
        zmq_msg_t reply;
        zmq_msg_init_data (&reply, "World", 5, NULL, NULL);
        zmq_send (responder, &reply, 0);
        zmq_msg_close (&reply);
    }
    //  We never get here but if we did, this would be how we end
    zmq_close (responder);
    zmq_term (context);
    return 0;
}
开发者ID:dcramer,项目名称:zguide,代码行数:30,代码来源:hwserver.c

示例9: main

int main()
{
    void *context = zmq_ctx_new();

    void *responder = zmq_socket(context, ZMQ_REP);
    zmq_bind(responder, "tcp://*:5555");

    while(1) {
        zmq_msg_t request;
        zmq_msg_init(&request);
        zmq_msg_recv(&request, responder, 0);
        char *recvmsg ;
        int recvsize = zmq_msg_size(&request);
        //memset(recvmsg, 0, recvsize);
        memcpy(recvmsg, (char *)zmq_msg_data(&request), recvsize);
        recvmsg[recvsize] = '\0';
        printf("Received request :[%s]\n", recvmsg);
        zmq_msg_close(&request);

        sleep(1);

        zmq_msg_t reply;
        //zmq_msg_init_size(&reply, 5);
        //memcpy((void*)zmq_msg_data(&reply), "World", 5);
        zmq_msg_init_data(&reply, "World", 5, NULL, NULL);
        zmq_msg_send(&reply, responder, 0);
        zmq_msg_close(&reply);
    }
    zmq_close(responder);
    zmq_ctx_destroy(context);
    return 0;
}
开发者ID:wuyilun,项目名称:ZeromqExample,代码行数:32,代码来源:rep.c

示例10: zmq_send_const

int zmq_send_const (void *s_, const void *buf_, size_t len_, int flags_)
{
    if (!s_ || !((zmq::socket_base_t*) s_)->check_tag ()) {
        errno = ENOTSOCK;
        return -1;
    }
    zmq_msg_t msg;
    int rc = zmq_msg_init_data (&msg, (void*)buf_, len_, NULL, NULL);
    if (rc != 0)
        return -1;

    zmq::socket_base_t *s = (zmq::socket_base_t *) s_;
    rc = s_sendmsg (s, &msg, flags_);
    if (unlikely (rc < 0)) {
        int err = errno;
        int rc2 = zmq_msg_close (&msg);
        errno_assert (rc2 == 0);
        errno = err;
        return -1;
    }
    
    //  Note the optimisation here. We don't close the msg object as it is
    //  empty anyway. This may change when implementation of zmq_msg_t changes.
    return rc;
}
开发者ID:Talksum,项目名称:libzmq,代码行数:25,代码来源:zmq.cpp

示例11: Handler_deliver

int Handler_deliver(void *handler_socket, char *buffer, size_t len)
{
    int rc = 0;
    zmq_msg_t *msg = calloc(sizeof(zmq_msg_t), 1);
    bstring msg_buf = NULL;

    rc = zmq_msg_init(msg);
    check(rc == 0, "Failed to initialize 0mq message to send.");

    msg_buf = blk2bstr(buffer, len);
    check_mem(msg_buf);

    rc = zmq_msg_init_data(msg, bdata(msg_buf), blength(msg_buf), bstring_free, msg_buf);
    check(rc == 0, "Failed to init 0mq message data.");

    rc = mqsend(handler_socket, msg, 0);
    check(rc == 0, "Failed to deliver 0mq message to handler.");

    if(msg) free(msg);
    return 0;

error:
    // TODO: confirm what if this is the right shutdown
    if(msg) free(msg);
    return -1;
}
开发者ID:derdewey,项目名称:mongrel2,代码行数:26,代码来源:handler.c

示例12: main

int main(int argc, char *argv[])
{
  if (argc < 2) return EXIT_FAILURE;
  int N = atoi(argv[1]);

  printf("N: %d\n", N);

  void *ctx = zmq_init(1);
  void *pub = zmq_socket(ctx, ZMQ_PUB); // Output channel of 0
  assert(pub);
  void *sub = zmq_socket(ctx, ZMQ_SUB); // Input channel of 0
  assert(sub);

  int rc;
  rc = zmq_bind(sub, "tcp://*:8887"); // Waits for publishers
  assert(rc == 0);

  rc = zmq_connect(pub, "tcp://localhost:8888"); // Actively connect to subscribers
  assert(rc == 0);

  zmq_setsockopt(sub, ZMQ_SUBSCRIBE, "", 0);

  int *val = (int *)calloc(N, sizeof(int));
  zmq_msg_t msg;

  long long start_time = sc_time();

  // Send
  int *buf = (int *)calloc(N, sizeof(int));
  memcpy(buf, val, N * sizeof(int));
  zmq_msg_init_data(&msg, buf, N * sizeof(int), _dealloc, NULL);
  zmq_send(pub, &msg, 0);
  zmq_msg_close(&msg);

  // Receive
  zmq_msg_init(&msg);
  zmq_recv(sub, &msg, 0);
  memcpy(val, (int *)zmq_msg_data(&msg), zmq_msg_size(&msg));
  zmq_msg_close(&msg);

  long long end_time = sc_time();

  printf("%s: Time elapsed: %f sec\n", argv[0], sc_time_diff(start_time, end_time));

#ifdef __DEBUG__
  int i;
  printf("%s [ ", argv[0]);
  for (i=0; i<N; ++i) {
    printf("%d ", val[i]);
  }
  printf("]\n");
#endif

  free(val);
  zmq_close(sub);
  zmq_close(pub);
  zmq_term(ctx);

  return EXIT_SUCCESS;
}
开发者ID:D4vidH4mm3r,项目名称:sessc,代码行数:60,代码来源:zmq0.c

示例13: message_t

 inline message_t (void *data_, size_t size_, free_fn *ffn_,
     void *hint_ = NULL)
 {
     int rc = zmq_msg_init_data (&msg, data_, size_, ffn_, hint_);
     if (rc != 0)
         throw error_t ();
 }
开发者ID:pombredanne,项目名称:metamorphosys-desktop,代码行数:7,代码来源:zmq.hpp

示例14: rebuild

 inline void rebuild(void *data_, size_t size_, free_fn *ffn_, void *hint_ = NULL)
 {
     int rc = zmq_msg_close(&msg);
     if (rc != 0)
         throw error_t();
     rc = zmq_msg_init_data(&msg, data_, size_, ffn_, hint_);
     if (rc != 0)
         throw error_t();
 }
开发者ID:dand-oss,项目名称:cppzmq,代码行数:9,代码来源:zmq.hpp

示例15: message

 message(nocopy_t, boost::asio::mutable_buffer const& buffer, void* hint, zmq_free_fn* deleter)
 {
     auto rc = zmq_msg_init_data(&msg_,
                                 boost::asio::buffer_cast<void*>(buffer),
                                 boost::asio::buffer_size(buffer),
                                 deleter, hint);
     if (rc)
         throw boost::system::system_error(make_error_code());
 }
开发者ID:zhangf911,项目名称:azmq,代码行数:9,代码来源:message.hpp


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