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


C++ zmq_sendmsg函数代码示例

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


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

示例1: zmq_msg_init_size

//  Send a monitor event
void zmq::socket_base_t::monitor_event (int event_, int value_, const std::string &addr_)
{
    if (monitor_socket) {
        //  Send event in first frame
        zmq_msg_t msg;
        zmq_msg_init_size (&msg, 6);
#ifdef ZMQ_HAVE_HPUX
        // avoid SIGBUS
        union {
          uint8_t data[6];
          struct {
            uint16_t event;
            uint32_t value;
          } v;
        } u;
        u.v.event = event_;
        u.v.value = value_;
        memcpy(zmq_msg_data (&msg), u.data, 6);
#else
        uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
        *(uint16_t *) (data + 0) = (uint16_t) event_;
        *(uint32_t *) (data + 2) = (uint32_t) value_;
#endif
        zmq_sendmsg (monitor_socket, &msg, ZMQ_SNDMORE);

        //  Send address in second frame
        zmq_msg_init_size (&msg, addr_.size());
        memcpy (zmq_msg_data (&msg), addr_.c_str (), addr_.size ());
        zmq_sendmsg (monitor_socket, &msg, 0);
    }
}
开发者ID:nyue,项目名称:libzmq,代码行数:32,代码来源:socket_base.cpp

示例2: copy_msg

static void copy_msg(void* from, void* to)
{
    zmq_msg_t msg;

    int more = 1;
    int rc;

    while (more)
    {
        more = 0;
        
        rc = zmq_msg_init(&msg);
        assert (rc == 0);
        rc = zmq_recvmsg(from, &msg, 0);
        assert (rc >= 0);                        
        size_t size = sizeof more;
        rc = zmq_getsockopt(from, ZMQ_RCVMORE, &more, &size);
        assert (rc == 0);

        int flags = (more ? ZMQ_SNDMORE : 0);
        rc = zmq_sendmsg(to, &msg, flags);
        assert (rc >= 0);
        rc = zmq_msg_close(&msg);
        assert (rc == 0);
    }
}
开发者ID:ninoles,项目名称:libzmq,代码行数:26,代码来源:test_queue_tcp.cpp

示例3: ForwardMessage

		static int ForwardMessage(void* srcSocket, void* desSocket, zmq_msg_t& msg)
		{
			int rc;
			int more;
			size_t moresz;

			while (true) 
			{
				rc = zmq_recvmsg(srcSocket, &msg, 0);
				if (rc < 0)	return -1;

				moresz = sizeof more;
				rc = zmq_getsockopt(srcSocket, ZMQ_RCVMORE, &more, &moresz);
				if (rc < 0)
					return -1;

				rc = zmq_sendmsg(desSocket, &msg, more? ZMQ_SNDMORE: 0);
				if (rc < 0)
					return -1;
				if (more == 0)
					break;
			}

			return 0;
		}
开发者ID:dario-DI,项目名称:DistributedCompute,代码行数:25,代码来源:lru.cpp

示例4: Java_org_zeromq_ZMQ_00024Socket_sendZeroCopy

JNIEXPORT jboolean JNICALL
Java_org_zeromq_ZMQ_00024Socket_sendZeroCopy (JNIEnv *env,
                                              jobject obj,
                                              jobject buffer,
                                              jint length,
                                              jint flags)
{
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3,0,0)
    int rc = 0;
    void *sock = get_socket (env, obj);

    // init the message
    zmq_msg_t message;
    jboolean retval = s_zerocopy_init (env, &message, buffer, length);
    if (retval == JNI_FALSE)
        return JNI_FALSE;

    rc = zmq_sendmsg (sock, &message, flags);
    if (rc == -1) {
        int err = zmq_errno();
        zmq_msg_close (&message);
        raise_exception (env, err);
        return JNI_FALSE;
    }
    return JNI_TRUE;
#else
    return JNI_FALSE;
#endif
}
开发者ID:Agnie-Software,项目名称:jzmq,代码行数:29,代码来源:Socket.cpp

示例5: zmq_msg_init_size

//  Send a monitor event
void zmq::socket_base_t::monitor_event (int event_, int value_, const std::string &addr_)
{
    if (monitor_socket) {
        //  Send event in first frame
        zmq_msg_t msg;
        zmq_msg_init_size (&msg, 6);
        uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
        *(uint16_t *) (data + 0) = (uint16_t) event_;
        *(uint32_t *) (data + 2) = (uint32_t) value_;
        zmq_sendmsg (monitor_socket, &msg, ZMQ_SNDMORE);

        //  Send address in second frame
        zmq_msg_init_size (&msg, addr_.size());
        memcpy (zmq_msg_data (&msg), addr_.c_str (), addr_.size ());
        zmq_sendmsg (monitor_socket, &msg, 0);
    }
}
开发者ID:cbrisket,项目名称:libzmq,代码行数:18,代码来源:socket_base.cpp

示例6: zsocket_signal

int
zsocket_signal (void *zocket)
{
    zmq_msg_t msg;
    zmq_msg_init_size (&msg, 0);
    int rc = zmq_sendmsg (zocket, &msg, 0);
    return rc == -1? -1: 0;
}
开发者ID:fars,项目名称:czmq,代码行数:8,代码来源:zsocket.c

示例7: send

 inline bool send (message_t &msg_, int flags_ = 0)
 {
     int nbytes = zmq_sendmsg (ptr, &(msg_.msg), flags_);
     if (nbytes >= 0)
         return true;
     if (zmq_errno () == EAGAIN)
         return false;
     throw error_t ();
 }
开发者ID:dangermanGls,项目名称:Lwdp,代码行数:9,代码来源:zmq.hpp

示例8: zmq_socket

static void *worker (void *ctx_)
#endif
{
    void *s;
    int rc;
    int i;
    zmq_msg_t msg;

    s = zmq_socket (ctx_, ZMQ_REP);
    if (!s) {
        printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
        exit (1);
    }

    rc = zmq_connect (s, "inproc://lat_test");
    if (rc != 0) {
        printf ("error in zmq_connect: %s\n", zmq_strerror (errno));
        exit (1);
    }

    rc = zmq_msg_init (&msg);
    if (rc != 0) {
        printf ("error in zmq_msg_init: %s\n", zmq_strerror (errno));
        exit (1);
    }

    for (i = 0; i != roundtrip_count; i++) {
        rc = zmq_recvmsg (s, &msg, 0);
        if (rc < 0) {
            printf ("error in zmq_recvmsg: %s\n", zmq_strerror (errno));
            exit (1);
        }
        rc = zmq_sendmsg (s, &msg, 0);
        if (rc < 0) {
            printf ("error in zmq_sendmsg: %s\n", zmq_strerror (errno));
            exit (1);
        }
    }

    rc = zmq_msg_close (&msg);
    if (rc != 0) {
        printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno));
        exit (1);
    }

    rc = zmq_close (s);
    if (rc != 0) {
        printf ("error in zmq_close: %s\n", zmq_strerror (errno));
        exit (1);
    }

#if defined ZMQ_HAVE_WINDOWS
    return 0;
#else
    return NULL;
#endif
}
开发者ID:adymitruk,项目名称:zeromq3-0,代码行数:57,代码来源:inproc_lat.cpp

示例9: main

int main(int argc, char *argv[]) {
  void *sp=NULL;
  void *set=NULL;
  int opt,rc=-1;
  char *config_file;
  set = kv_set_new();
  utarray_new(output_keys, &ut_str_icd);
  utarray_new(output_defaults, &ut_str_icd);
  utarray_new(output_types,&ut_int_icd);
  utstring_new(tmp);

  while ( (opt = getopt(argc, argv, "v+d:b:s")) != -1) {
    switch (opt) {
      case 'v': verbose++; break;
      case 's': push_mode++; break;
      case 'd': spool=strdup(optarg); break;
      case 'b': config_file=strdup(optarg); break;
      default: usage(argv[0]); break;
    }
  }
  if (optind < argc) pub_transport = argv[optind++];
  if (!pub_transport) usage(argv[0]);
  if (spool == NULL) usage(argv[0]);
  if (parse_config(config_file) < 0) goto done;

  if ( !(pub_context = zmq_init(1))) goto done;
  if ( !(pub_socket = zmq_socket(pub_context, push_mode?ZMQ_PUSH:ZMQ_PUB))) goto done;
  if (zmq_setsockopt(pub_socket, ZMQ_SNDHWM, &hwm, sizeof(hwm))) goto done;
  if (zmq_bind(pub_socket, pub_transport) == -1) goto done;

  sp = kv_spoolreader_new(spool);
  if (!sp) goto done;

  while (kv_spool_read(sp,set,1) > 0) { /* read til interrupted by signal */
    zmq_msg_t part;
    if (set_to_binary(set,&part) < 0) goto done;
    rc = zmq_sendmsg(pub_socket, &part, 0);
    zmq_msg_close(&part);
    if (rc == -1) goto done;
  }

  rc = 0;

 done:
  if (rc) fprintf(stderr,"zmq: %s %s\n", pub_transport, zmq_strerror(errno));
  if (pub_socket) zmq_close(pub_socket);
  if (pub_context) zmq_term(pub_context);
  if (sp) kv_spoolreader_free(sp);
  kv_set_free(set);
  utarray_free(output_keys);
  utarray_free(output_defaults);
  utarray_free(output_types);
  utstring_free(tmp);

  return 0;
}
开发者ID:JHUAPL,项目名称:kvspool,代码行数:56,代码来源:kvsp-bpub.c

示例10: main

int main(){
	zmq::context_t context(1);

	zmq::socket_t client (context, ZMQ_PUSH);
	client.setsockopt( ZMQ_IDENTITY, "B", 1);
	client.connect("tcp://127.0.0.1:5560");
	std::cout << "connected!" << std::endl;
	sleep(1);
	void *watch;
    unsigned long elapsed;
    unsigned long throughput;
    int message_count = 1;
	watch = zmq_stopwatch_start ();
	/*for( int i = 0; i < message_count; i++){
		//s_sendmore (client, "A");
		//s_sendmore(client, "");		
		s_send (client, "This is the workload");
		//s_dump(client);
		//std::string string = s_recv (client);
		//zmq::message_t message;
        //client.recv(&message);
	}*/


	for (i = 0; i != message_count; i++) {

        rc = zmq_msg_init_size (&msg, message_size);
        if (rc != 0) {
            printf ("error in zmq_msg_init_size: %s\n", zmq_strerror (errno));
            return -1;
        }
#if defined ZMQ_MAKE_VALGRIND_HAPPY
        memset (zmq_msg_data (&msg), 0, message_size);
#endif

        rc = zmq_sendmsg (s, &msg, 0);
        if (rc < 0) {
            printf ("error in zmq_sendmsg: %s\n", zmq_strerror (errno));
            return -1;
        }
        rc = zmq_msg_close (&msg);
        if (rc != 0) {
            printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno));
            return -1;
        }
    }



	elapsed = zmq_stopwatch_stop (watch);
	throughput = (unsigned long)
        ((double) message_count / (double) elapsed * 1000000);
    printf ("mean throughput: %d [msg/s]\n", (int) throughput);
	sleep(1);
	return 0;
}
开发者ID:gian788,项目名称:wsup,代码行数:56,代码来源:push.cpp

示例11: send_message

void send_message(void *z_sock, int flags, Arg &&arg) {
  msgpack::sbuffer buf;
  msgpack::pack(buf, arg);

  zmq_msg_t msg;
  zmq_msg_init_size(&msg, buf.size());
  memcpy(zmq_msg_data(&msg), buf.data(), buf.size());
  zmq_sendmsg(z_sock, &msg, flags);
  zmq_msg_close(&msg);
}
开发者ID:stanionascu,项目名称:smoc,代码行数:10,代码来源:rpc-pack.hpp

示例12: zmq_socket

static void *worker (void *ctx_)
#endif
{
    void *s;
    int rc;
    int i;
    zmq_msg_t msg;

    s = zmq_socket (ctx_, ZMQ_PUSH);
    if (!s) {
        printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
        exit (1);
    }

    rc = zmq_connect (s, "inproc://thr_test");
    if (rc != 0) {
        printf ("error in zmq_connect: %s\n", zmq_strerror (errno));
        exit (1);
    }

    for (i = 0; i != message_count; i++) {

        rc = zmq_msg_init_size (&msg, message_size);
        if (rc != 0) {
            printf ("error in zmq_msg_init_size: %s\n", zmq_strerror (errno));
            exit (1);
        }
#if defined ZMQ_MAKE_VALGRIND_HAPPY
        memset (zmq_msg_data (&msg), 0, message_size);
#endif

        rc = zmq_sendmsg (s, &msg, 0);
        if (rc < 0) {
            printf ("error in zmq_sendmsg: %s\n", zmq_strerror (errno));
            exit (1);
        }
        rc = zmq_msg_close (&msg);
        if (rc != 0) {
            printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno));
            exit (1);
        }
    }

    rc = zmq_close (s);
    if (rc != 0) {
        printf ("error in zmq_close: %s\n", zmq_strerror (errno));
        exit (1);
    }

#if defined ZMQ_HAVE_WINDOWS
    return 0;
#else
    return NULL;
#endif
}
开发者ID:5igm4,项目名称:libzmq,代码行数:55,代码来源:inproc_thr.cpp

示例13: zmq_msg_init_size

//  Send a monitor event
void zmq::socket_base_t::monitor_event (int event_, int value_, const std::string &addr_)
{
    if (monitor_socket) {
        //  Send event in first frame
        zmq_msg_t msg;
        zmq_msg_init_size (&msg, 6);
        uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
        //  Avoid dereferencing uint32_t on unaligned address
        uint16_t event = (uint16_t) event_;
        uint32_t value = (uint32_t) value_;
        memcpy (data + 0, &event, sizeof(event));
        memcpy (data + 2, &value, sizeof(value));
        zmq_sendmsg (monitor_socket, &msg, ZMQ_SNDMORE);

        //  Send address in second frame
        zmq_msg_init_size (&msg, addr_.size());
        memcpy (zmq_msg_data (&msg), addr_.c_str (), addr_.size ());
        zmq_sendmsg (monitor_socket, &msg, 0);
    }
}
开发者ID:snowattitudes,项目名称:libzmq,代码行数:21,代码来源:socket_base.cpp

示例14: zmq_msg_init_size

void zmq::socket_base_t::monitor_event (zmq_event_t event_, const std::string& addr_)
{
    if (monitor_socket) {
        const uint16_t eid = (uint16_t)event_.event;
        const uint32_t value = (uint32_t)event_.value;
        // prepare and send first message frame
        // containing event id and value
        zmq_msg_t msg;
        zmq_msg_init_size (&msg, sizeof(eid) + sizeof(value));
        char* data1 = (char*)zmq_msg_data(&msg);
        memcpy (data1, &eid, sizeof(eid));
        memcpy (data1+sizeof(eid), &value, sizeof(value));
        zmq_sendmsg (monitor_socket, &msg, ZMQ_SNDMORE);
        // prepare and send second message frame
        // containing the address (endpoint)
        zmq_msg_init_size (&msg, addr_.size());
        memcpy(zmq_msg_data(&msg), addr_.c_str(), addr_.size());
        zmq_sendmsg (monitor_socket, &msg, 0);
    }
}
开发者ID:BugFreeSoftware,项目名称:Open-Transactions,代码行数:20,代码来源:socket_base.cpp

示例15: malloc

void zmq::socket_base_t::monitor_event (zmq_event_t event_)
{
    if (monitor_socket) {
        zmq_msg_t msg;
        void *event_data = malloc (sizeof (event_));
        alloc_assert (event_data);
        memcpy (event_data, &event_, sizeof (event_));
        zmq_msg_init_data (&msg, event_data, sizeof (event_), zmq_free_event, NULL);
        zmq_sendmsg (monitor_socket, &msg, 0);
        zmq_msg_close (&msg);
    }
}
开发者ID:shks,项目名称:DoubleFishEyeGrabber,代码行数:12,代码来源:socket_base.cpp


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