flux_msg_t *flux_event_encode (const char *topic, const char *json_str) { flux_msg_t *msg = NULL; if (!topic) { errno = EINVAL; goto error; } if (!(msg = flux_msg_create (FLUX_MSGTYPE_EVENT))) goto error; if (flux_msg_set_topic (msg, topic) < 0) goto error; if (flux_msg_enable_route (msg) < 0) goto error; if (json_str && flux_msg_set_payload_json (msg, json_str) < 0) goto error; return msg; error: if (msg) { int saved_errno = errno; flux_msg_destroy (msg); errno = saved_errno; } return NULL; }
static flux_msg_t *encode_event (const char *topic, int flags, uint32_t rolemask, uint32_t userid, uint32_t seq, const char *src) { flux_msg_t *msg; void *dst = NULL; int saved_errno; if (!(msg = flux_msg_create (FLUX_MSGTYPE_EVENT))) goto error; if (flux_msg_set_topic (msg, topic) < 0) goto error; if (flux_msg_set_userid (msg, userid) < 0) goto error; if (flux_msg_set_rolemask (msg, rolemask) < 0) goto error; if (flux_msg_set_seq (msg, seq) < 0) goto error; if ((flags & FLUX_MSGFLAG_PRIVATE)) { if (flux_msg_set_private (msg) < 0) goto error; } if (src) { // optional payload int srclen = strlen (src); size_t dstlen = BASE64_DECODE_SIZE (srclen); if (!(dst = malloc (dstlen))) goto error; if (sodium_base642bin ((unsigned char *)dst, dstlen, src, srclen, NULL, &dstlen, NULL, sodium_base64_VARIANT_ORIGINAL) < 0) { errno = EPROTO; goto error; } if (flux_msg_set_payload (msg, dst, dstlen) < 0) { if (errno == EINVAL) errno = EPROTO; goto error; } } free (dst); return msg; error: saved_errno = errno; free (dst); flux_msg_destroy (msg); errno = saved_errno; return NULL; }
static flux_msg_t *flux_event_create (const char *topic) { flux_msg_t *msg = NULL; if (!topic) { errno = EINVAL; goto error; } if (!(msg = flux_msg_create (FLUX_MSGTYPE_EVENT))) goto error; if (flux_msg_set_topic (msg, topic) < 0) goto error; if (flux_msg_enable_route (msg) < 0) goto error; return msg; error: flux_msg_destroy (msg); return NULL; }
static void disconnect_destroy (client_t *c, struct disconnect_notify *d) { flux_msg_t *msg; if (!(msg = flux_msg_create (FLUX_MSGTYPE_REQUEST))) goto done; if (flux_msg_set_topic (msg, d->topic) < 0) goto done; if (flux_msg_enable_route (msg) < 0) goto done; if (flux_msg_push_route (msg, zuuid_str (c->uuid)) < 0) goto done; if (flux_msg_set_nodeid (msg, d->nodeid, d->flags) < 0) goto done; (void)flux_send (c->ctx->h, msg, 0); done: flux_msg_destroy (msg); free (d->topic); free (d); }
/* Send shutdown request, broker to module. */ int module_stop (module_t *p, const flux_msg_t *rmmod) { assert (p->magic == MODULE_MAGIC); char *topic = xasprintf ("%s.shutdown", p->name); flux_msg_t *msg; int rc = -1; if (!(msg = flux_msg_create (FLUX_MSGTYPE_REQUEST))) goto done; if (flux_msg_set_topic (msg, topic) < 0) goto done; if (flux_msg_sendzsock (p->sock, msg) < 0) goto done; if (rmmod) { flux_msg_t *cpy = flux_msg_copy (rmmod, true); if (!cpy || zlist_append (p->rmmod, cpy) < 0) oom (); } rc = 0; done: free (topic); flux_msg_destroy (msg); return rc; }
int main (int argc, char *argv[]) { waitqueue_t *q; waitqueue_t *q2; wait_t *w; flux_msg_t *msg; int count = 0; int i; plan (NO_PLAN); q = wait_queue_create (); q2 = wait_queue_create (); ok (q && q2, "wait_queue_create works"); ok (wait_queue_length (q) == 0 && wait_queue_length (q2) == 0, "wait_queue_length on brandnew waitqueue_t returns zero"); msg = flux_msg_create (FLUX_MSGTYPE_REQUEST); ok (msg != NULL, "flux_msg_create works"); w = wait_create (NULL, NULL, msg, msghand, &count); ok (w != NULL, "wait_create works"); flux_msg_destroy (msg); wait_addqueue (q, w); wait_addqueue (q2, w); ok (wait_queue_length (q) == 1 && wait_queue_length (q2) == 1, "wait_addqueue can add wait_t to a two queues"); wait_runqueue (q); ok (wait_queue_length (q) == 0 && wait_queue_length (q2) == 1, "wait_runqueue dequeued wait_t from first queue"); wait_runqueue (q2); ok (wait_queue_length (q) == 0 && wait_queue_length (q2) == 0, "wait_runqueue dequeued wait_t from second queue"); ok (count == 1, "wait_runqueue ran the wait_t once"); for (i = 0; i < 20; i++) { char *s = xasprintf ("%d", i); msg = flux_msg_create (FLUX_MSGTYPE_REQUEST); if (!msg) break; if (flux_msg_enable_route (msg) < 0 || flux_msg_push_route (msg, s) < 0) break; w = wait_create (NULL, NULL, msg, msghand, &count); if (!w) break; wait_addqueue (q, w); free (s); } ok (wait_queue_length (q) == 20, "wait_addqueue 20x works"); wait_destroy_match (q, msgcmp, NULL); ok (wait_queue_length (q) == 17, "wait_destroy_match on sender works"); wait_destroy_match (q, msgcmp2, NULL); ok (wait_queue_length (q) == 0, "all-match wait_destroy_match works"); wait_queue_destroy (q); wait_queue_destroy (q2); done_testing (); return (0); }