本文整理汇总了C++中zmsg_recv函数的典型用法代码示例。如果您正苦于以下问题:C++ zmsg_recv函数的具体用法?C++ zmsg_recv怎么用?C++ zmsg_recv使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zmsg_recv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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);
}
示例2: main
int main (void)
{
zctx_t *ctx = zctx_new ();
void *frontend = zsocket_new (ctx, ZMQ_ROUTER);
void *backend = zsocket_new (ctx, ZMQ_ROUTER);
zsocket_bind (frontend, "tcp://*:5555"); // For clients
zsocket_bind (backend, "tcp://*:5556"); // For workers
// Queue of available workers
zlist_t *workers = zlist_new ();
// The body of this example is exactly the same as lruqueue2.
// .skip
while (1) {
zmq_pollitem_t items [] = {
{ backend, 0, ZMQ_POLLIN, 0 },
{ frontend, 0, ZMQ_POLLIN, 0 }
};
// Poll frontend only if we have available workers
int rc = zmq_poll (items, zlist_size (workers)? 2: 1, -1);
if (rc == -1)
break; // Interrupted
// Handle worker activity on backend
if (items [0].revents & ZMQ_POLLIN) {
// Use worker address for LRU routing
zmsg_t *msg = zmsg_recv (backend);
if (!msg)
break; // Interrupted
zframe_t *address = zmsg_unwrap (msg);
zlist_append (workers, address);
// Forward message to client if it's not a READY
zframe_t *frame = zmsg_first (msg);
if (memcmp (zframe_data (frame), LRU_READY, 1) == 0)
zmsg_destroy (&msg);
else
zmsg_send (&msg, frontend);
}
if (items [1].revents & ZMQ_POLLIN) {
// Get client request, route to first available worker
zmsg_t *msg = zmsg_recv (frontend);
if (msg) {
zmsg_wrap (msg, (zframe_t *) zlist_pop (workers));
zmsg_send (&msg, backend);
}
}
}
// When we're done, clean up properly
while (zlist_size (workers)) {
zframe_t *frame = (zframe_t *) zlist_pop (workers);
zframe_destroy (&frame);
}
zlist_destroy (&workers);
zctx_destroy (&ctx);
return 0;
// .until
}
示例3: main
int main (void)
{
s_version_assert (2, 1);
// Prepare our context and sockets
void *context = zmq_init (1);
void *frontend = zmq_socket (context, ZMQ_XREP);
void *backend = zmq_socket (context, ZMQ_XREP);
zmq_bind (frontend, "tcp://*:5555"); // For clients
zmq_bind (backend, "tcp://*:5556"); // For workers
// Queue of available workers
int available_workers = 0;
char *worker_queue [MAX_WORKERS];
while (1) {
zmq_pollitem_t items [] = {
{ backend, 0, ZMQ_POLLIN, 0 },
{ frontend, 0, ZMQ_POLLIN, 0 }
};
// Poll frontend only if we have available workers
if (available_workers)
zmq_poll (items, 2, -1);
else
zmq_poll (items, 1, -1);
// Handle worker activity on backend
if (items [0].revents & ZMQ_POLLIN) {
zmsg_t *zmsg = zmsg_recv (backend);
// Use worker address for LRU routing
assert (available_workers < MAX_WORKERS);
worker_queue [available_workers++] = zmsg_unwrap (zmsg);
// Return reply to client if it's not a READY
if (strcmp (zmsg_address (zmsg), "READY") == 0)
zmsg_destroy (&zmsg);
else
zmsg_send (&zmsg, frontend);
}
if (items [1].revents & ZMQ_POLLIN) {
// Now get next client request, route to next worker
zmsg_t *zmsg = zmsg_recv (frontend);
// REQ socket in worker needs an envelope delimiter
zmsg_wrap (zmsg, worker_queue [0], "");
zmsg_send (&zmsg, backend);
// Dequeue and drop the next worker address
free (worker_queue [0]);
DEQUEUE (worker_queue);
available_workers--;
}
}
// We never exit the main loop
return 0;
}
示例4: event
static int event(zloop_t *loop, zmq_pollitem_t *item, void *arg)
{
if (interrupt)
return -1;
zmsg_t *msg = zmsg_recv(dealer);
zframe_t *payload = zmsg_pop(msg);
zmsg_destroy(&msg);
msgpack_unpacked object;
msgpack_unpacked_init(&object);
if (msgpack_unpack_next(&object, (char*)zframe_data(payload), zframe_size(payload) , NULL))
{
//zclock_log("message");
//msgpack_object_print(stdout, object.data);
char *command = (char*)m_lookup(object.data, "command");
if (command) {
//zclock_log("command: %s", command);
if (streq(command, "exception")) {
failed++;
}
if (streq(command, "result")) {
success++;
}
free(command);
}
}
msgpack_unpacked_destroy(&object);
zframe_destroy(&payload);
return 0;
}
示例5: curve_server_recv
zmsg_t *
curve_server_recv (curve_server_t *self)
{
assert (self);
zmsg_t *msg = zmsg_recv (self->data);
return msg;
}
示例6: client_task
static void *
client_task (void *args)
{
zctx_t *ctx = zctx_new ();
void *client = zsocket_new (ctx, ZMQ_DEALER);
// Set random identity to make tracing easier
char identity [10];
sprintf (identity, "%04X-%04X", randof (0x10000), randof (0x10000));
zsocket_set_identity (client, identity);
zsocket_connect (client, "tcp://localhost:5570");
zmq_pollitem_t items [] = { { client, 0, ZMQ_POLLIN, 0 } };
int request_nbr = 0;
while (true) {
// Tick once per second, pulling in arriving messages
int centitick;
for (centitick = 0; centitick < 100; centitick++) {
zmq_poll (items, 1, 10 * ZMQ_POLL_MSEC);
if (items [0].revents & ZMQ_POLLIN) {
zmsg_t *msg = zmsg_recv (client);
zframe_print (zmsg_last (msg), identity);
zmsg_destroy (&msg);
}
}
zstr_send (client, "request #%d");
}
zctx_destroy (&ctx);
return NULL;
}
示例7: actor_command
static
int actor_command(zloop_t *loop, zsock_t *socket, void *callback_data)
{
static size_t ticks = 0;
int rc = 0;
subscriber_state_t *state = callback_data;
zmsg_t *msg = zmsg_recv(socket);
if (msg) {
char *cmd = zmsg_popstr(msg);
if (streq(cmd, "$TERM")) {
fprintf(stderr, "[D] subscriber: received $TERM command\n");
rc = -1;
} else if (streq(cmd, "tick")) {
printf("[I] subscriber: %5zu messages "
"(gap_size: %zu, no_info: %zu, dev_zero: %zu, blocks: %zu, drops: %zu)\n",
state->message_count, state->message_gap_size, state->meta_info_failures,
state->messages_dev_zero, state->message_blocks, state->message_drops);
state->message_count = 0;
state->message_gap_size = 0;
state->meta_info_failures = 0;
state->messages_dev_zero = 0;
state->message_drops = 0;
if (++ticks % HEART_BEAT_INTERVAL == 0)
device_tracker_reconnect_stale_devices(state->tracker);
} else {
fprintf(stderr, "[E] subscriber: received unknown actor command: %s\n", cmd);
}
free(cmd);
zmsg_destroy(&msg);
}
return rc;
}
示例8: curve_client_recv
zmsg_t *
curve_client_recv (curve_client_t *self)
{
assert (self);
zmsg_t *msg = zmsg_recv (self->data);
return msg;
}
示例9: someactor_recv_api
static void
someactor_recv_api (someactor_t *self)
{
// Get the whole message of the pipe in one go
zmsg_t *request = zmsg_recv (self->pipe);
if (!request)
return; // Interrupted
char *command = zmsg_popstr (request);
if (streq (command, "START"))
zsock_signal (self->pipe, someactor_start (self));
else
if (streq (command, "STOP"))
zsock_signal (self->pipe, someactor_stop (self));
else
if (streq (command, "VERBOSE")) {
self->verbose = true;
zsock_signal (self->pipe, 0);
}
else
if (streq (command, "$TERM"))
// The $TERM command is send by zactor_destroy() method
self->terminated = true;
else {
zsys_error ("invalid command '%s'", command);
assert (false);
}
}
示例10: main
int main(int argc, char *argv[])
{
if (argc < 2) {
printf("syntax: %s <endpoint>\n", argv[0]);
exit(EXIT_SUCCESS);
}
zctx_t *ctx = zctx_new();
void *server = zsocket_new(ctx, ZMQ_REP);
zsocket_bind(server, argv[1]);
printf("Server is ready at %s\n", argv[1]);
while (TRUE) {
zmsg_t *msg = zmsg_recv(server);
if (!msg) break;
zmsg_send(&msg, server);
}
if (zctx_interrupted) {
printf("context interrupted\n");
}
zctx_destroy(&ctx);
return 0;
}
示例11: zsock_wait
int
zsock_wait (void *self)
{
assert (self);
// A signal is a message containing one frame with our 8-byte magic
// value. If we get anything else, we discard it and continue to look
// for the signal message
while (true) {
zmsg_t *msg = zmsg_recv (self);
if (!msg)
return -1;
if (zmsg_size (msg) == 1
&& zmsg_content_size (msg) == 8) {
zframe_t *frame = zmsg_first (msg);
int64_t signal_value = *((int64_t *) zframe_data (frame));
if ((signal_value & 0xFFFFFFFFFFFFFF00L) == 0x7766554433221100L) {
zmsg_destroy (&msg);
return signal_value & 255;
}
}
zmsg_destroy (&msg);
}
return -1;
}
示例12: echo_actor
static void
echo_actor (zsock_t *pipe, void *args)
{
// Do some initialization
assert (streq ((char *) args, "Hello, World"));
zsock_signal (pipe, 0);
bool terminated = false;
while (!terminated) {
zmsg_t *msg = zmsg_recv (pipe);
if (!msg)
break; // Interrupted
char *command = zmsg_popstr (msg);
// All actors must handle $TERM in this way
if (streq (command, "$TERM"))
terminated = true;
else
// This is an example command for our test actor
if (streq (command, "ECHO"))
zmsg_send (&msg, pipe);
else {
puts ("E: invalid message to actor");
assert (false);
}
free (command);
zmsg_destroy (&msg);
}
}
示例13: pthread_self
/**
*
* @param foundId
* @param foundReply
* @return
*/
bool BoomStick::ReadFromReadySocket(std::string& foundId, std::string& foundReply) {
if (0 == mUtilizedThread) {
mUtilizedThread = pthread_self();
} else {
CHECK(pthread_self() == mUtilizedThread);
}
if (!mChamber) {
LOG(WARNING) << "Invalid socket";
return false;
}
bool success = false;
zmsg_t* msg = zmsg_recv(mChamber);
if (!msg) {
foundReply = zmq_strerror(zmq_errno());
} else if (zmsg_size(msg) == 2) {
char* msgChar;
msgChar = zmsg_popstr(msg);
foundId = msgChar;
free(msgChar);
msgChar = zmsg_popstr(msg);
foundReply = msgChar;
free(msgChar);
success = true;
} else {
foundReply = "Malformed reply, expecting 2 parts";
}
if (msg) {
zmsg_destroy(&msg);
}
return success;
}
示例14: zmqreader
static void zmqreader (flux_reactor_t *r, flux_watcher_t *w,
int revents, void *arg)
{
void *sock = flux_zmq_watcher_get_zsock (w);
static int count = 0;
if (revents & FLUX_POLLERR) {
fprintf (stderr, "%s: FLUX_POLLERR is set\n", __FUNCTION__);
goto error;
}
if (revents & FLUX_POLLIN) {
zmsg_t *zmsg = zmsg_recv (sock);
if (!zmsg) {
fprintf (stderr, "%s: zmsg_recv: %s\n",
__FUNCTION__, strerror (errno));
goto error;
}
zmsg_destroy (&zmsg);
count++;
if (count == zmqwriter_msgcount)
flux_watcher_stop (w);
}
return;
error:
flux_reactor_stop_error (r);
}
示例15: main
int main (int argc, char *argv [])
{
int verbose = (argc > 1 && streq (argv [1], "-v"));
broker_t *self = s_broker_new (verbose);
s_broker_bind (self, "tcp://*:5555");
// Get and process messages forever or until interrupted
while (TRUE) {
zmq_pollitem_t items [] = {
{ self->socket, 0, ZMQ_POLLIN, 0 } };
int rc = zmq_poll (items, 1, HEARTBEAT_INTERVAL * ZMQ_POLL_MSEC);
if (rc == -1)
break; // Interrupted
// Process next input message, if any
if (items [0].revents & ZMQ_POLLIN) {
zmsg_t *msg = zmsg_recv (self->socket);
if (!msg)
break; // Interrupted
if (self->verbose) {
zclock_log ("I: received message:");
zmsg_dump (msg);
}
zframe_t *sender = zmsg_pop (msg);
zframe_t *empty = zmsg_pop (msg);
zframe_t *header = zmsg_pop (msg);
if (zframe_streq (header, MDPC_CLIENT))
s_client_process (self, sender, msg);
else
if (zframe_streq (header, MDPW_WORKER))
s_worker_process (self, sender, msg);
else {
zclock_log ("E: invalid message:");
zmsg_dump (msg);
zmsg_destroy (&msg);
}
zframe_destroy (&sender);
zframe_destroy (&empty);
zframe_destroy (&header);
}
// Disconnect and delete any expired workers
// Send heartbeats to idle workers if needed
if (zclock_time () > self->heartbeat_at) {
s_broker_purge_workers (self);
worker_t *worker = (worker_t *) zlist_first (self->waiting);
while (worker) {
s_worker_send (self, worker, MDPW_HEARTBEAT, NULL, NULL);
worker = (worker_t *) zlist_next (self->waiting);
}
self->heartbeat_at = zclock_time () + HEARTBEAT_INTERVAL;
}
}
if (zctx_interrupted)
printf ("W: interrupt received, shutting down...\n");
s_broker_destroy (&self);
return 0;
}