static int disconnect_update (client_t *c, const flux_msg_t *msg) { char *p; char *key = NULL; char *svc = NULL; const char *topic; uint32_t nodeid; int flags; struct disconnect_notify *d; int rc = -1; if (flux_msg_get_topic (msg, &topic) < 0) goto done; if (flux_msg_get_nodeid (msg, &nodeid, &flags) < 0) goto done; svc = xstrdup (topic); if ((p = strchr (svc, '.'))) *p = '\0'; key = xasprintf ("%s:%u:%d", svc, nodeid, flags); if (!zhash_lookup (c->disconnect_notify, key)) { d = xzmalloc (sizeof (*d)); d->nodeid = nodeid; d->flags = flags; d->topic = xasprintf ("%s.disconnect", svc); zhash_update (c->disconnect_notify, key, d); } rc = 0; done: if (svc) free (svc); if (key) free (key); return rc; }
int rpctest_nodeid_cb (flux_t h, int type, zmsg_t **zmsg, void *arg) { int errnum = 0; uint32_t nodeid; JSON o = NULL; int flags; if (flux_request_decode (*zmsg, NULL, NULL) < 0 || flux_msg_get_nodeid (*zmsg, &nodeid, &flags) < 0) { errnum = errno; goto done; } if (nodeid == nodeid_fake_error) { nodeid_fake_error = -1; errnum = EPERM; /* an error not likely to be seen */ goto done; } o = Jnew (); Jadd_int (o, "nodeid", nodeid); Jadd_int (o, "flags", flags); done: (void)flux_respond (h, *zmsg, errnum, Jtostr (o)); Jput (o); zmsg_destroy (zmsg); return 0; }
/* Handle the simplest possible request. * Verify that everything is as expected; log it and stop the reactor if not. */ void null_request_cb (flux_t h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { ctx_t *ctx = arg; const char *topic; int type, size; void *buf; uint32_t nodeid; int flags; if (!msg) { flux_log (h, LOG_ERR, "%s: got NULL msg!", __FUNCTION__); goto error; } if (flux_msg_get_type (msg, &type) < 0) { flux_log_error (h, "%s: flux_msg_get_type", __FUNCTION__); goto error; } if (type != FLUX_MSGTYPE_REQUEST) { flux_log (h, LOG_ERR, "%s: unexpected type %s", __FUNCTION__, flux_msg_typestr (type)); goto error; } if (flux_msg_get_nodeid (msg, &nodeid, &flags) < 0) { flux_log_error (h, "%s: flux_msg_get_nodeid", __FUNCTION__); goto error; } if (nodeid != ctx->rank && nodeid != FLUX_NODEID_ANY) { flux_log (h, LOG_ERR, "%s: unexpected nodeid: %"PRIu32"", __FUNCTION__, nodeid); goto error; } if (flux_msg_get_topic (msg, &topic) < 0) { flux_log_error (h, "%s: flux_msg_get_topic", __FUNCTION__); goto error; } if (strcmp (topic, "req.null") != 0) { flux_log (h, LOG_ERR, "%s: unexpected topic: %s", __FUNCTION__, topic); goto error; } if (flux_msg_get_payload (msg, &flags, &buf, &size) == 0) { flux_log (h, LOG_ERR, "%s: unexpected payload size %d", __FUNCTION__, size); goto error; } if (errno != EPROTO) { flux_log (h, LOG_ERR, "%s: get nonexistent payload: %s", __FUNCTION__, strerror (errno)); goto error; } if (flux_respond (h, msg, 0, NULL) < 0) { flux_log_error (h, "%s: flux_respond", __FUNCTION__); goto error; } return; error: flux_reactor_stop_error (flux_get_reactor (h)); }
/* request nodeid and flags returned in response */ void rpctest_nodeid_cb (flux_t h, flux_msg_watcher_t *w, const flux_msg_t *msg, void *arg) { int errnum = 0; uint32_t nodeid; JSON o = NULL; int flags; if (flux_request_decode (msg, NULL, NULL) < 0 || flux_msg_get_nodeid (msg, &nodeid, &flags) < 0) { errnum = errno; goto done; } o = Jnew (); Jadd_int (o, "nodeid", nodeid); Jadd_int (o, "flags", flags); done: (void)flux_respond (h, msg, errnum, Jtostr (o)); Jput (o); }
/* Handle the simplest possible request. * Verify that everything is as expected; log it and stop the reactor if not. */ static int null_request_cb (flux_t h, int typemask, zmsg_t **zmsg, void *arg) { //ctx_t *ctx = arg; const char *topic; int type, size, flags; int rc = -1; void *buf; uint32_t nodeid; if (!zmsg || !*zmsg) { flux_log (h, LOG_ERR, "%s: got NULL zmsg!", __FUNCTION__); goto done; } if (flux_msg_get_type (*zmsg, &type) < 0) { flux_log (h, LOG_ERR, "%s: flux_msg_get_type: %s", __FUNCTION__, strerror (errno)); goto done; } if (type != FLUX_MSGTYPE_REQUEST) { flux_log (h, LOG_ERR, "%s: unexpected type %s", __FUNCTION__, flux_msg_typestr (type)); goto done; } if (flux_msg_get_nodeid (*zmsg, &nodeid, &flags) < 0) { flux_log (h, LOG_ERR, "%s: flux_msg_get_nodeid: %s", __FUNCTION__, strerror (errno)); goto done; } if (nodeid != FLUX_NODEID_ANY && nodeid != flux_rank (h)) { flux_log (h, LOG_ERR, "%s: unexpected nodeid: %"PRIu32"", __FUNCTION__, nodeid); goto done; } if (flux_msg_get_topic (*zmsg, &topic) < 0) { flux_log (h, LOG_ERR, "%s: flux_msg_get_topic: %s", __FUNCTION__, strerror (errno)); goto done; } if (strcmp (topic, "req.null") != 0) { flux_log (h, LOG_ERR, "%s: unexpected topic: %s", __FUNCTION__, topic); goto done; } if (flux_msg_get_payload (*zmsg, &flags, &buf, &size) == 0) { flux_log (h, LOG_ERR, "%s: unexpected payload size %d", __FUNCTION__, size); goto done; } if (errno != EPROTO) { flux_log (h, LOG_ERR, "%s: get nonexistent payload: %s", __FUNCTION__, strerror (errno)); goto done; } errno = 0; if (flux_err_respond (h, 0, zmsg) < 0) { flux_log (h, LOG_ERR, "%s: flux_err_respond: %s", __FUNCTION__, strerror (errno)); goto done; } rc = 0; done: return rc; }