本文整理汇总了C++中zmq_recvmsg函数的典型用法代码示例。如果您正苦于以下问题:C++ zmq_recvmsg函数的具体用法?C++ zmq_recvmsg怎么用?C++ zmq_recvmsg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zmq_recvmsg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s_self_switch
static void
s_self_switch (self_t *self, zsock_t *input, zsock_t *output)
{
// We use the low-level libzmq API for best performance
void *zmq_input = zsock_resolve (input);
void *zmq_output = zsock_resolve (output);
void *zmq_capture = self->capture? zsock_resolve (self->capture): NULL;
zmq_msg_t msg;
zmq_msg_init (&msg);
if (zmq_recvmsg (zmq_input, &msg, 0) == -1)
return; // Nothing to do, probably interrupted
while (true) {
int send_flags = zsocket_rcvmore (zmq_input)? ZMQ_SNDMORE: 0;
if (zmq_capture) {
zmq_msg_t dup;
zmq_msg_init (&dup);
zmq_msg_copy (&dup, &msg);
if (zmq_sendmsg (zmq_capture, &dup, send_flags) == -1)
zmq_msg_close (&dup);
}
if (zmq_sendmsg (zmq_output, &msg, send_flags) == -1) {
zmq_msg_close (&msg);
break;
}
if (zmq_recvmsg (zmq_input, &msg, ZMQ_DONTWAIT) == -1)
break; // Presumably EAGAIN
}
}
示例2: main
int main (int argc, char *argv [])
{
// Create the infrastructure
void *ctx = zmq_init (0);
assert (ctx);
void *sb = zmq_socket (ctx, ZMQ_XREP);
assert (sb);
int rc = zmq_bind (sb, "inproc://a");
assert (rc == 0);
void *sc = zmq_socket (ctx, ZMQ_XREQ);
assert (sc);
rc = zmq_connect (sc, "inproc://a");
assert (rc == 0);
// Send 2-part message.
rc = zmq_send (sc, "A", 1, ZMQ_SNDMORE);
assert (rc == 1);
rc = zmq_send (sc, "B", 1, 0);
assert (rc == 1);
// Identity comes first.
zmq_msg_t msg;
rc = zmq_msg_init (&msg);
assert (rc == 0);
rc = zmq_recvmsg (sb, &msg, 0);
assert (rc >= 0);
int more;
size_t more_size = sizeof (more);
rc = zmq_getmsgopt (&msg, ZMQ_MORE, &more, &more_size);
assert (rc == 0);
assert (more == 1);
// Then the first part of the message body.
rc = zmq_recvmsg (sb, &msg, 0);
assert (rc == 1);
more_size = sizeof (more);
rc = zmq_getmsgopt (&msg, ZMQ_MORE, &more, &more_size);
assert (rc == 0);
assert (more == 1);
// And finally, the second part of the message body.
rc = zmq_recvmsg (sb, &msg, 0);
assert (rc == 1);
more_size = sizeof (more);
rc = zmq_getmsgopt (&msg, ZMQ_MORE, &more, &more_size);
assert (rc == 0);
assert (more == 0);
// Deallocate the infrastructure.
rc = zmq_close (sc);
assert (rc == 0);
rc = zmq_close (sb);
assert (rc == 0);
rc = zmq_term (ctx);
assert (rc == 0);
return 0 ;
}
示例3: router_start
int router_start(struct router_context *ctx) {
zmq_msg_t msg;
struct router_route *route_info;
char pipe_path[256];
int ret, forwarded = 0;
GList *l;
lock_and_log("process_list_lock", &ctx->process_list_lock);
// Forward messages from peer router
zmq_msg_init(&msg);
ret = zmq_recvmsg(ctx->zmq_sock, &msg, ZMQ_NOBLOCK);
if (ret > 0) {
route_info = zmq_msg_data(&msg);
syslog(LOG_DEBUG, "router_route: message base: %p", route_info);
syslog(LOG_DEBUG, "router_route: received message from forwarder to pid %d", route_info->pid);
for (l = ctx->process_list; l != NULL; l = l->next) {
syslog(LOG_DEBUG, "router_route: trying to %p", l->data);
syslog(LOG_DEBUG, "router_route: trying to %d", ((struct router_process*)l->data)->pid);
if (((struct router_process*)l->data)->pid == route_info->pid) {
syslog(LOG_DEBUG, "router_forward_msg: \tforwarding message to pid %u", route_info->pid);
router_forward_to_proc(((struct router_process*)l->data)->zmq_sock,
zmq_msg_data(&msg) + sizeof(struct router_route),
zmq_msg_size(&msg) - sizeof(struct router_route));
forwarded += 1;
break;
}
}
if (forwarded == 0)
syslog(LOG_WARNING, "router_route: pid %d not found", route_info->pid);
}
// Forward messages from running processes
for (l = ctx->process_list; l != NULL; l = l->next) {
zmq_msg_t msg;
zmq_msg_init(&msg);
ret = zmq_recvmsg(((struct router_process*)l->data)->zmq_sock, &msg, ZMQ_NOBLOCK);
if (ret > 0) {
syslog(LOG_DEBUG, "router_route: received message from pid %u", ((struct router_process*)l->data)->pid);
router_forward_from_proc(ctx->zmq_sock, &msg, ((struct router_process*)l->data)->pid);
forwarded += 1;
}
}
unlock_and_log("process_list_lock", &ctx->process_list_lock);
return forwarded;
}
示例4: 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;
}
示例5: 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);
}
}
示例6: zmq_recv
int zmq_recv (void *s_, void *buf_, size_t len_, int flags_)
{
zmq_msg_t msg;
int rc = zmq_msg_init (&msg);
errno_assert (rc == 0);
int nbytes = zmq_recvmsg (s_, &msg, flags_);
if (unlikely (nbytes < 0)) {
int err = errno;
rc = zmq_msg_close (&msg);
errno_assert (rc == 0);
errno = err;
return -1;
}
// At the moment an oversized message is silently truncated.
// TODO: Build in a notification mechanism to report the overflows.
size_t to_copy = size_t (nbytes) < len_ ? size_t (nbytes) : len_;
memcpy (buf_, zmq_msg_data (&msg), to_copy);
rc = zmq_msg_close (&msg);
errno_assert (rc == 0);
return nbytes;
}
示例7: recv_stub
CAMLprim value recv_stub(value socket, value rcv_option) {
CAMLparam2 (socket, rcv_option);
CAMLlocal1 (message);
void *sock = Socket_val(socket)->wrapped;
zmq_msg_t request;
int result = zmq_msg_init (&request);
stub_raise_if (result == -1);
caml_release_runtime_system();
result = zmq_recvmsg(sock, &request, Int_val(rcv_option));
caml_acquire_runtime_system();
stub_raise_if (result == -1);
size_t size = zmq_msg_size (&request);
if (size == 0) {
message = EMPTY_STRING;
} else {
message = caml_alloc_string(size);
memcpy (String_val(message), zmq_msg_data (&request), size);
}
result = zmq_msg_close(&request);
stub_raise_if (result == -1);
CAMLreturn (message);
}
示例8: sizeof
int CZmqThread::block_rcv_socket(QString & s){
QString msg;
int rc;
int64_t more;
size_t more_size = sizeof (more);
s="";
do {
rc = zmq_recvmsg (m_socket, &m_msg, ZMQ_DONTWAIT);
if (rc < 0) {
if ( zmq_errno () == EAGAIN ){
return (1);
}
printf ("error in zmq_rcv : %s\n", zmq_strerror (errno));
return(-1);
}else{
s +=(QString::fromLocal8Bit((char *)zmq_msg_data (&m_msg), (int)zmq_msg_size (&m_msg) ) );
rc = zmq_getsockopt (m_socket, ZMQ_RCVMORE, &more, &more_size);
if (rc != 0) {
printf ("error in zmq_getsockopt : %s\n", zmq_strerror (errno));
return(-1);
}
}
} while ( more );
return (0);
}
示例9: monitor
inline void monitor (monitor_t* mon)
{
zmq_event_t event;
int rc;
assert(mon);
void *s = zmq_socket (ctxptr, ZMQ_PAIR);
assert (s);
rc = zmq_connect (s, monaddr.c_str());
assert (rc == 0);
while (true) {
zmq_msg_t msg;
zmq_msg_init (&msg);
rc = zmq_recvmsg (s, &msg, 0);
if (rc == -1 && zmq_errno() == ETERM) break;
assert (rc != -1);
memcpy (&event, zmq_msg_data (&msg), sizeof (event));
switch (event.event) {
case ZMQ_EVENT_CONNECTED:
mon->on_event_connected(event.data.connected.addr);
break;
case ZMQ_EVENT_CONNECT_DELAYED:
mon->on_event_connect_delayed(event.data.connect_delayed.addr);
break;
case ZMQ_EVENT_CONNECT_RETRIED:
mon->on_event_connect_retried(event.data.connect_retried.addr);
break;
case ZMQ_EVENT_LISTENING:
mon->on_event_listening(event.data.listening.addr);
break;
case ZMQ_EVENT_BIND_FAILED:
mon->on_event_bind_failed(event.data.bind_failed.addr);
break;
case ZMQ_EVENT_ACCEPTED:
mon->on_event_accepted(event.data.accepted.addr);
break;
case ZMQ_EVENT_ACCEPT_FAILED:
mon->on_event_accept_failed(event.data.accept_failed.addr);
break;
case ZMQ_EVENT_CLOSED:
mon->on_event_closed(event.data.closed.addr);
break;
case ZMQ_EVENT_CLOSE_FAILED:
mon->on_event_close_failed(event.data.close_failed.addr);
break;
case ZMQ_EVENT_DISCONNECTED:
mon->on_event_disconnected(event.data.disconnected.addr);
break;
default:
mon->on_event_unknown(event.event);
break;
}
zmq_msg_close (&msg);
}
zmq_close (s);
}
示例10: zsocket_wait
int
zsocket_wait (void *zocket)
{
zmq_msg_t msg;
zmq_msg_init (&msg);
int rc = zmq_recvmsg (zocket, &msg, 0);
return rc == -1? -1: 0;
}
示例11: main
int main(int argc, char **argv) {
(void)argc;
(void)argv;
auto *context = zmq_ctx_new();
rpc_socket = zmq_socket(context, ZMQ_PAIR);
int rc = zmq_bind(rpc_socket, "tcp://127.0.0.1:9999");
if (rc == 0) {
std::cout << "Listening on: 127.0.0.1:9999" << std::endl;
}
while (true) {
zmq_msg_t header_zmsg;
zmq_msg_init(&header_zmsg);
zmq_recvmsg(rpc_socket, &header_zmsg, 0);
messages::header header;
msgpack::unpacked header_unpacked;
msgpack::unpack(&header_unpacked,
static_cast<char *>(zmq_msg_data(&header_zmsg)),
zmq_msg_size(&header_zmsg));
header_unpacked.get().convert(header);
zmq_msg_t body_zmsg;
zmq_msg_init(&body_zmsg);
zmq_recvmsg(rpc_socket, &body_zmsg, 0);
msgpack::unpacked body_unpacked;
msgpack::unpack(&body_unpacked,
static_cast<char *>(zmq_msg_data(&body_zmsg)),
zmq_msg_size(&body_zmsg));
execute_rpc_request(static_cast<rpc_call_name>(header.get<0>()),
body_unpacked.get());
zmq_msg_close(&header_zmsg);
zmq_msg_close(&body_zmsg);
}
zmq_close(rpc_socket);
zmq_ctx_destroy(context);
return 0;
}
示例12: recv
inline bool recv (message_t *msg_, int flags_ = 0)
{
int nbytes = zmq_recvmsg (ptr, &(msg_->msg), flags_);
if (nbytes >= 0)
return true;
if (zmq_errno () == EAGAIN)
return false;
throw error_t ();
}
示例13: 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
}
示例14: zsocket_wait
int
zsocket_wait (void *zocket)
{
zmq_msg_t msg;
zmq_msg_init (&msg);
if (zmq_recvmsg (zocket, &msg, 0) == -1)
return -1;
else {
zmq_msg_close (&msg);
return 0;
}
}
示例15: s_recv
// Receive 0MQ string from socket and convert into C string
static char *
s_recv (void *socket) {
zmq_msg_t message;
zmq_msg_init (&message);
zmq_recvmsg (socket, &message, 0);
// return (NULL);
int size = zmq_msg_size (&message);
char *string = malloc (size + 1);
memcpy (string, zmq_msg_data (&message), size);
zmq_msg_close (&message);
string [size] = 0;
printf("s: %s\n",string);
return (string);
}