本文整理汇总了C++中zmsg_send函数的典型用法代码示例。如果您正苦于以下问题:C++ zmsg_send函数的具体用法?C++ zmsg_send怎么用?C++ zmsg_send使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zmsg_send函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s_connect_to_broker
void s_connect_to_broker (mdwrk_t *self)
{
if (self->worker)
zmq_close (self->worker);
self->worker = zmq_socket (self->context, ZMQ_XREQ);
int linger = 0;
zmq_setsockopt (self->worker, ZMQ_LINGER, &linger, sizeof (linger));
zmq_connect (self->worker, self->broker);
// Register service with broker
zmsg_t *msg = zmsg_new ();
zmsg_append (msg, MDPS_HEADER);
zmsg_append (msg, MDPS_READY);
zmsg_append (msg, self->service);
zmsg_send (&msg, self->worker);
// If liveness hits zero, queue is considered disconnected
self->liveness = HEARTBEAT_LIVENESS;
self->heartbeat_at = s_clock () + HEARTBEAT_INTERVAL;
}
示例2: main
int main (void)
{
srandom ((unsigned) time (NULL));
void *context = zmq_init (1);
void *worker = zmq_socket (context, ZMQ_REQ);
// Set random identity to make tracing easier
char identity [10];
sprintf (identity, "%04X-%04X", randof (0x10000), randof (0x10000));
zmq_setsockopt (worker, ZMQ_IDENTITY, identity, strlen (identity));
zmq_connect (worker, "tcp://localhost:5556");
// Tell queue we're ready for work
printf ("I: (%s) worker ready\n", identity);
s_send (worker, "READY");
int cycles = 0;
while (1) {
zmsg_t *zmsg = zmsg_recv (worker);
// Simulate various problems, after a few cycles
cycles++;
if (cycles > 3 && randof (5) == 0) {
printf ("I: (%s) simulating a crash\n", identity);
zmsg_destroy (&zmsg);
break;
}
else
if (cycles > 3 && randof (5) == 0) {
printf ("I: (%s) simulating CPU overload\n", identity);
sleep (5);
}
printf ("I: (%s) normal reply - %s\n", identity, zmsg_body (zmsg));
sleep (1); // Do some heavy work
zmsg_send (&zmsg, worker);
}
zmq_close (worker);
zmq_term (context);
return 0;
}
示例3: s_worker_send
static void
s_worker_send (worker_t *self, char *command, char *option, zmsg_t *msg)
{
msg = msg? zmsg_dup (msg): zmsg_new ();
// Stack protocol envelope to start of message
if (option)
zmsg_pushstr (msg, option);
zmsg_pushstr (msg, command);
zmsg_pushstr (msg, MDPW_WORKER);
// Stack routing envelope to start of message
zmsg_wrap (msg, zframe_dup (self->address));
if (self->broker->verbose) {
zclock_log ("I: sending %s to worker",
mdpw_commands [(int) *command]);
zmsg_dump (msg);
}
zmsg_send (&msg, self->broker->socket);
}
示例4: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
zclock_sleep(20000);
char* broker_loc = "tcp://localhost:5555";
zctx_t* ctx = zctx_new();
void* scket = zsocket_new(ctx,ZMQ_REQ);
zsocket_connect(scket,broker_loc);
zmsg_t* msg = zmsg_new();
zmsg_addstr(msg,TWRK_CLI_VER);
zmsg_addstr(msg,"Echo");
zmsg_addstr(msg,TMSG_TYPE_REQUEST);
int64_t sleep = 10*1000;
zclock_sleep(sleep);
zmsg_add(msg,zframe_new(&sleep,sizeof(sleep)));
zmsg_send(&msg,scket);
zmsg_t* reply = zmsg_recv(scket);
zmsg_dump(reply);
return 0;
}
示例5: mdcli_send
int
mdcli_send (mdcli_t *self, char *service, zmsg_t **request_p)
{
assert (self);
assert (request_p);
zmsg_t *request = *request_p;
// Prefix request with protocol frames
// Frame 0: empty (REQ emulation)
// Frame 1: "MDPCxy" (six bytes, MDP/Client x.y)
// Frame 2: Service name (printable string)
zmsg_push (request, service);
zmsg_push (request, MDPC_CLIENT);
zmsg_push (request, "");
if (self->verbose) {
s_console ("I: send request to '%s' service:", service);
zmsg_dump (request);
}
zmsg_send (&request, self->client);
return 0;
}
示例6: graph_response_newLinkDataResponse
void graph_response_newLinkDataResponse(req_t * req, json_t * request,
json_t * response, int32_t requestId,
void *sweb, req_store_t * req_store)
{
if (strcmp
(json_string_value(json_object_get(response, "ack")), "ok") == 0) {
json_t *link = json_object_get(request, "link");
json_t *web_resp = json_object();
json_object_set_new(web_resp, "type",
json_string("newLinkData"));
//TODO at the moment only the original node gets the update, which is good enough for me
json_t *sessionIds = json_array();
json_array_append
(sessionIds, json_object_get(req->request, "sessionId"));
json_object_set_new(web_resp, "sessionIds", sessionIds);
json_t *newData = json_object();
json_t *newLinkData = json_array();
json_array_append(newLinkData, link);
json_object_set_new(newData, "newLinkData", newLinkData);
json_object_set_new(web_resp, "newData", newData);
zmsg_t *res = zmsg_new();
char *web_res_str = json_dumps(web_resp,
JSON_COMPACT);
printf("\nbroker:sweb sent: %s\n", web_res_str);
zmsg_addstr(res, web_res_str);
free(web_res_str);
zmsg_wrap(res, req->address);
zmsg_send(&res, sweb);
json_decref(web_resp);
} else {
}
request_store_delete(req_store, requestId);
}
示例7: s_service_internal
static void
s_service_internal (broker_t *self, char *service_name, zmsg_t *msg)
{
if (streq (service_name, "mmi.service")) {
service_t *service =
(service_t *) zhash_lookup (self->services, zmsg_body (msg));
if (service && service->workers)
zmsg_body_set (msg, "200");
else
zmsg_body_set (msg, "404");
}
else
zmsg_body_set (msg, "501");
// Remove & save client return envelope and insert the
// protocol header and service name, then rewrap envelope.
char *client = zmsg_unwrap (msg);
zmsg_wrap (msg, MDPC_CLIENT, service_name);
zmsg_wrap (msg, client, "");
free (client);
zmsg_send (&msg, self->socket);
}
示例8: worker_task
// Worker using REQ socket to do load-balancing
//
static void *
worker_task (void *args)
{
zctx_t *ctx = zctx_new ();
void *worker = zsocket_new (ctx, ZMQ_REQ);
zsocket_connect (worker, "ipc://backend.ipc");
// Tell broker we're ready for work
zframe_t *frame = zframe_new (WORKER_READY, 1);
zframe_send (&frame, worker, 0);
// Process messages as they arrive
while (true) {
zmsg_t *msg = zmsg_recv (worker);
if (!msg)
break; // Interrupted
zframe_reset (zmsg_last (msg), "OK", 2);
zmsg_send (&msg, worker);
}
zctx_destroy (&ctx);
return NULL;
}
示例9: sleep_loop
static int sleep_loop(zloop_t *loop, int item, void *arg)
{
int *c = (int*)arg;
int i;
for (i = 0; i < *c; i++)
{
if (interrupt)
return -1;
char *actionid = getActionid();
zmsg_t *msg = create_call(actionid, "worker", "sleep", "echo");
free(actionid);
if (msg) {
zmsg_send(&msg, dealer);
counter ++;
}
}
return 0;
}
示例10: prob_get_label_group
void prob_get_label_group(prob_client_t pc, ProBState s, int group, int *res) {
zmsg_t *request = zmsg_new();
zmsg_addstr(request, "get-state-label-group");
zmsg_addstrf(request, "%d", pc->id_count);
zmsg_addstrf(request, "DA%d", group);
prob_put_state(request, s);
zmsg_send(&request, pc->zocket);
zmsg_destroy(&request);
zmsg_t *response = zmsg_recv(pc->zocket);
drop_frame(response);
drop_frame(response);
char *result_s;
for (int i = 0; (result_s = zmsg_popstr(response)) != NULL; i++) {
int r;
sscanf(result_s, "%d", &r);
res[i] = r;
RTfree(result_s);
}
zmsg_destroy(&response);
}
示例11: prob_get_state_label
int
prob_get_state_label(prob_client_t pc, ProBState s, char *label)
{
zmsg_t *request = zmsg_new();
zmsg_addstr(request, "get-state-label");
zmsg_addstrf(request, "%d", pc->id_count);
zmsg_addstrf(request, "DA%s", label);
prob_put_state(request, s);
zmsg_send(&request, pc->zocket);
zmsg_destroy(&request);
zmsg_t *response = zmsg_recv(pc->zocket);
drop_frame(response);
drop_frame(response);
char *result_s = zmsg_popstr(response);
int res;
sscanf(result_s, "%d", &res);
RTfree(result_s);
zmsg_destroy(&response);
return res;
}
示例12: s_worker_send
static void
s_worker_send (
broker_t *self, worker_t *worker,
char *command, char *option, zmsg_t *msg)
{
msg = msg? zmsg_dup (msg): zmsg_new (NULL);
// Stack protocol envelope to start of message
if (option) // Optional frame after command
zmsg_push (msg, option);
zmsg_push (msg, command);
zmsg_push (msg, MDPW_WORKER);
// Stack routing envelope to start of message
zmsg_wrap (msg, worker->identity, "");
if (self->verbose) {
s_console ("I: sending %s to worker",
mdps_commands [(int) *command]);
zmsg_dump (msg);
}
zmsg_send (&msg, self->socket);
}
示例13: flclient_request
zmsg_t *
flclient_request (flclient_t *self, zmsg_t **request_p)
{
assert (self);
assert (*request_p);
zmsg_t *request = *request_p;
// Prefix request with sequence number and empty envelope
char sequence_text [10];
sprintf (sequence_text, "%u", ++self->sequence);
zmsg_push (request, sequence_text);
zmsg_push (request, "");
// Blast the request to all connected servers
int server;
for (server = 0; server < self->servers; server++) {
zmsg_t *msg = zmsg_dup (request);
zmsg_send (&msg, self->socket);
}
// Wait for a matching reply to arrive from anywhere
// Since we can poll several times, calculate each one
zmsg_t *reply = NULL;
uint64_t endtime = s_clock () + GLOBAL_TIMEOUT;
while (s_clock () < endtime) {
zmq_pollitem_t items [] = { { self->socket, 0, ZMQ_POLLIN, 0 } };
zmq_poll (items, 1, (endtime - s_clock ()) * 1000);
if (items [0].revents & ZMQ_POLLIN) {
reply = zmsg_recv (self->socket);
assert (zmsg_parts (reply) == 3);
free (zmsg_pop (reply));
if (atoi (zmsg_address (reply)) == self->sequence)
break;
zmsg_destroy (&reply);
}
}
zmsg_destroy (request_p);
return reply;
}
示例14: main
int main(void) {
zmsg_t *msg;
zframe_t *frame;
char *str;
int i, rc;
// create push/pull sockets
zsock_t *push = zsock_new_push("inproc://example");
zsock_t *pull = zsock_new_pull("inproc://example");
// send multi-frame message
msg = zmsg_new();
zmsg_addmem(msg, "apple", 5);
zmsg_addmem(msg, "banana", 6);
zmsg_addmem(msg, "cherry", 6);
assert(zmsg_size(msg) == 3);
assert(zmsg_content_size(msg) == 5+6+6);
rc = zmsg_send(&msg, push);
assert(msg == NULL);
assert(rc == 0);
// receive multi-frame message
msg = zmsg_recv(pull);
assert(msg);
assert(zmsg_size(msg) == 3);
assert(zmsg_content_size(msg) == 5+6+6);
for (i = 0; i < 3; i++) {
str = zmsg_popstr(msg);
puts(str);
}
zmsg_destroy(&msg);
// disconnect
zsock_destroy(&push);
zsock_destroy(&pull);
return 0;
}
示例15: prob_next_x
static ProBState *
prob_next_x(prob_client_t pc, ProBState s, char *transitiongroup, int *size, char *header) {
zmsg_t *request = zmsg_new();
zmsg_addstr(request, header);
zmsg_addstrf(request, "%d", pc->id_count);
zmsg_addstr(request, transitiongroup);
prob_put_state(request, s);
Debugf("requesting next-state, contents:\n");
#ifdef LTSMIN_DEBUG
if (log_active(debug)) zmsg_print(request);
#endif
zmsg_send(&request, pc->zocket);
zmsg_destroy(&request);
zmsg_t *response = zmsg_recv(pc->zocket);
Debugf("response for next-state, contents:\n");
#ifdef LTSMIN_DEBUG
if (log_active(debug)) zmsg_print(response);
#endif
drop_frame(response);
drop_frame(response);
char *nr_of_states_s = zmsg_popstr(response);
sscanf(nr_of_states_s, "%d", size);
RTfree(nr_of_states_s);
ProBState *successors = RTmalloc(sizeof(ProBState) * (*size));
int i;
for (i = 0; i < (*size); i++) {
successors[i] = prob_get_state(response);
}
zmsg_destroy(&response);
return successors;
}