void rpctest_begin_cb (flux_t h, flux_msg_watcher_t *w, const flux_msg_t *msg, void *arg) { const char *json_str; flux_rpc_t *r; errno = 0; ok (!(r = flux_rpc (h, NULL, NULL, FLUX_NODEID_ANY, 0)) && errno == EINVAL, "flux_rpc with NULL topic fails with EINVAL"); /* working no-payload RPC */ ok ((r = flux_rpc (h, "rpctest.hello", NULL, FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with no payload when none is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); ok (flux_rpc_get (r, NULL, NULL) == 0, "flux_rpc_get works"); flux_rpc_destroy (r); /* cause remote EPROTO (unexpected payload) - will be picked up in _get() */ ok ((r = flux_rpc (h, "rpctest.hello", "foo", FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with payload when none is expected works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* cause remote EPROTO (missing payload) - will be picked up in _get() */ errno = 0; ok ((r = flux_rpc (h, "rpctest.echo", NULL, FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with no payload when payload is expected works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* working with-payload RPC */ ok ((r = flux_rpc (h, "rpctest.echo", "foo", FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with payload when payload is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); json_str = NULL; ok (flux_rpc_get (r, NULL, &json_str) == 0 && json_str && !strcmp (json_str, "foo"), "flux_rpc_get works and returned expected payload"); flux_rpc_destroy (r); flux_reactor_stop (h); }
void mod_rmmod (flux_t h, opt_t opt) { char *modname = NULL; if (opt.argc != 1) usage (); modname = opt.argv[0]; if (opt.direct) { char *service = getservice (modname); char *topic = xasprintf ("%s.rmmod", service); char *json_str = flux_rmmod_json_encode (modname); assert (json_str != NULL); flux_rpc_t *r = flux_rpc_multi (h, topic, json_str, opt.nodeset, 0); if (!r) err_exit ("%s", topic); while (!flux_rpc_completed (r)) { uint32_t nodeid = FLUX_NODEID_ANY; if (flux_rpc_get (r, &nodeid, NULL) < 0) err ("%s[%d]", topic, nodeid == FLUX_NODEID_ANY ? -1 : nodeid); } flux_rpc_destroy (r); free (topic); free (service); free (json_str); } else { if (flux_modctl_unload (h, opt.nodeset, modname) < 0) err_exit ("%s", modname); } }
void mod_lsmod (flux_t h, opt_t opt) { char *service = "cmb"; if (opt.argc > 1) usage (); if (opt.argc == 1) service = opt.argv[0]; printf ("%-20s %6s %7s %4s %s\n", "Module", "Size", "Digest", "Idle", "Nodeset"); if (opt.direct) { zhash_t *mods = zhash_new (); if (!mods) oom (); char *topic = xasprintf ("%s.lsmod", service); flux_rpc_t *r = flux_rpc_multi (h, topic, NULL, opt.nodeset, 0); if (!r) err_exit ("%s", topic); while (!flux_rpc_completed (r)) { const char *json_str; uint32_t nodeid; if (flux_rpc_get (r, &nodeid, &json_str) < 0) err_exit ("%s", topic); if (lsmod_hash_cb (nodeid, json_str, mods) < 0) err_exit ("%s[%u]", topic, nodeid); } flux_rpc_destroy (r); lsmod_map_hash (mods, lsmod_print_cb, NULL); zhash_destroy (&mods); free (topic); } else { if (flux_modctl_list (h, service, opt.nodeset, lsmod_print_cb, NULL) < 0) err_exit ("modctl_list"); } }
static void request_hwloc_reload (flux_t h, const char *nodeset, const char *walk_topology) { flux_rpc_t *rpc; JSON o = NULL; const char *json_str = NULL; if ((o = hwloc_reload_json_create (walk_topology))) json_str = Jtostr (o); if (!(rpc = flux_rpc_multi (h, "resource-hwloc.reload", json_str, nodeset, 0))) log_err_exit ("flux_rpc_multi"); while (!flux_rpc_completed (rpc)) { const char *json_str; uint32_t nodeid = FLUX_NODEID_ANY; if (flux_rpc_get (rpc, &nodeid, &json_str) < 0) { if (nodeid == FLUX_NODEID_ANY) log_err ("flux_rpc_get"); else log_err ("rpc(%"PRIu32")", nodeid); } } flux_rpc_destroy (rpc); Jput (o); }
static int64_t next_jobid (flux_t h) { int64_t ret = (int64_t) -1; const char *json_str; json_object *req, *resp; flux_rpc_t *rpc; req = Jnew (); Jadd_str (req, "name", "lwj"); Jadd_int64 (req, "preincrement", 1); Jadd_int64 (req, "postincrement", 0); Jadd_bool (req, "create", true); rpc = flux_rpc (h, "cmb.seq.fetch", json_object_to_json_string (req), 0, 0); json_object_put (req); if ((flux_rpc_get (rpc, NULL, &json_str) < 0) || !(resp = json_tokener_parse (json_str))) { flux_log_error (h, "rpc_get"); goto out; } Jget_int64 (resp, "value", &ret); json_object_put (resp); out: flux_rpc_destroy (rpc); return ret; }
void test_clog (flux_t *h, uint32_t nodeid) { flux_future_t *f; if (!(f = flux_rpc (h, "req.clog", NULL, nodeid, 0)) || flux_rpc_get (f, NULL) < 0) log_err_exit ("req.clog"); flux_future_destroy (f); }
/* Handle responses */ void ping_continuation (flux_rpc_t *rpc, void *arg) { struct ping_ctx *ctx = arg; const char *json_str, *route, *pad; int64_t sec, nsec; struct timespec t0; int seq; json_object *out = NULL; struct ping_data *pdata = flux_rpc_aux_get (rpc); tstat_t *tstat = pdata->tstat; if (flux_rpc_get (rpc, &json_str) < 0) { log_err ("flux_rpc_get"); goto done; } if (!(out = Jfromstr (json_str)) || !Jget_int (out, "seq", &seq) || !Jget_int64 (out, "time.tv_sec", &sec) || !Jget_int64 (out, "time.tv_nsec", &nsec) || !Jget_str (out, "pad", &pad) || !Jget_str (out, "route", &route) || strcmp (ctx->pad, pad) != 0) { log_err ("error decoding ping response"); goto done; } t0.tv_sec = sec; t0.tv_nsec = nsec; tstat_push (tstat, monotime_since (t0)); pdata->seq = seq; if (pdata->route) free (pdata->route); pdata->route = xstrdup (route); pdata->rpc_count++; done: if (flux_rpc_next (rpc) < 0 && pdata->rpc_count) { if (ctx->rank != NULL) { printf ("%s!%s pad=%lu seq=%d time=(%0.3f:%0.3f:%0.3f) ms stddev %0.3f\n", ctx->rank, ctx->topic, strlen (ctx->pad), pdata->seq, tstat_min (tstat), tstat_mean (tstat), tstat_max (tstat), tstat_stddev (tstat)); } else { char s[16]; snprintf (s, sizeof (s), "%u", ctx->nodeid); printf ("%s%s%s pad=%lu seq=%d time=%0.3f ms (%s)\n", ctx->nodeid == FLUX_NODEID_ANY ? "" : s, ctx->nodeid == FLUX_NODEID_ANY ? "" : "!", ctx->topic, strlen (ctx->pad), pdata->seq, tstat_mean (tstat), pdata->route); } flux_rpc_destroy (rpc); } Jput (out); }
static void then_cb (flux_rpc_t *r, void *arg) { flux_t h = arg; uint32_t nodeid; if (flux_rpc_get (r, &nodeid, NULL) < 0 || !nodeset_add_rank (then_ns, nodeid) || ++then_count == 128) { flux_reactor_stop (flux_get_reactor (h)); } }
void get_rank (flux_rpc_t *rpc) { const char *json_str; JSON o; int rank; if (flux_rpc_get (rpc, NULL, &json_str) < 0) err_exit ("flux_rpc_get"); if (!(o = Jfromstr (json_str)) || !Jget_int (o, "rank", &rank)) msg_exit ("response protocol error"); printf ("rank is %d\n", rank); Jput (o); }
static void then_cb (flux_rpc_t *r, void *arg) { flux_t h = arg; const char *json_str; ok (flux_rpc_check (r) == true, "flux_rpc_check says get won't block in then callback"); json_str = NULL; ok (flux_rpc_get (r, NULL, &json_str) == 0 && json_str && !strcmp (json_str, "xxx"), "flux_rpc_get works and returned expected payload in then callback"); flux_reactor_stop (h); }
void mod_insmod (flux_t h, opt_t opt) { char *modpath = NULL; char *modname = NULL; if (opt.argc < 1) usage (); if (strchr (opt.argv[0], '/')) { if (!(modpath = realpath (opt.argv[0], NULL))) oom (); if (!(modname = flux_modname (modpath))) msg_exit ("%s", dlerror ()); } else { char *searchpath = getenv ("FLUX_MODULE_PATH"); if (!searchpath) searchpath = MODULE_PATH; modname = xstrdup (opt.argv[0]); if (!(modpath = flux_modfind (searchpath, modname))) msg_exit ("%s: not found in module search path", modname); } opt.argv++; opt.argc--; if (opt.direct) { char *service = getservice (modname); char *topic = xasprintf ("%s.insmod", service); char *json_str = flux_insmod_json_encode (modpath, opt.argc, opt.argv); assert (json_str != NULL); flux_rpc_t *r = flux_rpc_multi (h, topic, json_str, opt.nodeset, 0); if (!r) err_exit ("%s", topic); while (!flux_rpc_completed (r)) { uint32_t nodeid = FLUX_NODEID_ANY; if (flux_rpc_get (r, NULL, NULL) < 0) err_exit ("%s[%d]", topic, nodeid == FLUX_NODEID_ANY ? -1 : nodeid); } flux_rpc_destroy (r); free (topic); free (service); free (json_str); } else { if (flux_modctl_load (h, opt.nodeset, modpath, opt.argc, opt.argv) < 0) err_exit ("%s", modname); } if (modpath) free (modpath); if (modname) free (modname); }
static int dmesg_clear (flux_t *h, int seq) { flux_rpc_t *rpc; int rc = -1; if (!(rpc = flux_rpcf (h, "cmb.dmesg.clear", FLUX_NODEID_ANY, 0, "{s:i}", "seq", seq))) goto done; if (flux_rpc_get (rpc, NULL) < 0) goto done; rc = 0; done: flux_rpc_destroy (rpc); return rc; }
/* * Gather concatenated hwloc xml topo file with resource-hwloc.topo RPC * and save results until destroyed by hwloc_topo_destroy (). */ static struct hwloc_topo * hwloc_topo_create (optparse_t *p) { const char *json_str; struct hwloc_topo *t = xzmalloc (sizeof (*t)); if (!(t->h = builtin_get_flux_handle (p))) log_err_exit ("flux_open"); t->rpc = flux_rpc (t->h, "resource-hwloc.topo", NULL, 0, 0); if (!t->rpc || (flux_rpc_get (t->rpc, NULL, &json_str) < 0)) log_err_exit ("flux_rpc"); if (!(t->o = Jfromstr (json_str)) || !Jget_str (t->o, "topology", &t->topo)) log_msg_exit ("failed to parse json topology"); return (t); }
static int op_event_unsubscribe (void *impl, const char *topic) { ctx_t *c = impl; assert (c->magic == CTX_MAGIC); flux_rpc_t *rpc = NULL; JSON in = Jnew (); int rc = 0; Jadd_str (in, "topic", topic); if (!(rpc = flux_rpc (c->h, "local.unsub", Jtostr (in), FLUX_NODEID_ANY, 0)) || flux_rpc_get (rpc, NULL, NULL) < 0) goto done; rc = 0; done: flux_rpc_destroy (rpc); Jput (in); return rc; }
static int dmesg_clear (flux_t h, int seq) { flux_rpc_t *rpc; JSON o = Jnew (); int rc = -1; Jadd_int (o, "seq", seq); if (!(rpc = flux_rpc (h, "cmb.dmesg.clear", Jtostr (o), FLUX_NODEID_ANY, 0))) goto done; if (flux_rpc_get (rpc, NULL, NULL) < 0) goto done; rc = 0; done: flux_rpc_destroy (rpc); Jput (o); return rc; }
void test_src (flux_t *h, uint32_t nodeid) { flux_future_t *f; const char *json_str; json_object *out = NULL; int i; if (!(f = flux_rpc (h, "req.src", NULL, nodeid, 0)) || flux_rpc_get (f, &json_str) < 0) log_err_exit ("%s", __FUNCTION__); if (!json_str || !(out = Jfromstr (json_str)) || !Jget_int (out, "wormz", &i) || i != 42) log_msg_exit ("%s: didn't get expected payload", __FUNCTION__); Jput (out); flux_future_destroy (f); }
static int internal_heaptrace_stop (optparse_t *p, int ac, char *av[]) { flux_t *h; flux_rpc_t *rpc; if (optparse_optind (p) != ac) { optparse_print_usage (p); exit (1); } if (!(h = builtin_get_flux_handle (p))) log_err_exit ("flux_open"); if (!(rpc = flux_rpc (h, "cmb.heaptrace.stop", NULL, FLUX_NODEID_ANY, 0)) || flux_rpc_get (rpc, NULL) < 0) log_err_exit ("cmb.heaptrace.stop"); flux_rpc_destroy (rpc); flux_close (h); return (0); }
static void request_hwloc_reload (flux_t h, const char *nodeset) { flux_rpc_t *rpc; if (!(rpc = flux_rpc_multi (h, "resource-hwloc.reload", NULL, nodeset, 0))) err_exit ("flux_rpc_multi"); while (!flux_rpc_completed (rpc)) { const char *json_str; uint32_t nodeid = FLUX_NODEID_ANY; if (flux_rpc_get (rpc, &nodeid, &json_str) < 0) { if (nodeid == FLUX_NODEID_ANY) err ("flux_rpc_get"); else err ("rpc(%"PRIu32")", nodeid); } } flux_rpc_destroy (rpc); }
static int op_event_unsubscribe (void *impl, const char *topic) { ctx_t *ctx = impl; assert (ctx->magic == MODHANDLE_MAGIC); JSON in = Jnew (); flux_rpc_t *rpc = NULL; int rc = -1; if (connect_socket (ctx) < 0) goto done; Jadd_str (in, "topic", topic); if (!(rpc = flux_rpc (ctx->h, "cmb.unsub", Jtostr (in), FLUX_NODEID_ANY, 0)) || flux_rpc_get (rpc, NULL, NULL) < 0) goto done; rc = 0; done: Jput (in); flux_rpc_destroy (rpc); return rc; }
static int dmesg_rpc_get (flux_rpc_t *rpc, int *seq, flux_log_f fun, void *arg) { const char *json_str; const char *buf; JSON o = NULL; int rc = -1; if (flux_rpc_get (rpc, NULL, &json_str) < 0) goto done; if (!(o = Jfromstr (json_str)) || !Jget_str (o, "buf", &buf) || !Jget_int (o, "seq", seq)) { errno = EPROTO; goto done; } fun (buf, strlen (buf), arg); rc = 0; done: Jput (o); return rc; }
static int internal_content_dropcache (optparse_t *p, int ac, char *av[]) { flux_t *h; flux_rpc_t *rpc = NULL; const char *topic = "content.dropcache"; if (optparse_optind (p) != ac) { optparse_print_usage (p); exit (1); } if (!(h = builtin_get_flux_handle (p))) log_err_exit ("flux_open"); if (!(rpc = flux_rpc (h, topic, NULL, FLUX_NODEID_ANY, 0))) log_err_exit ("%s", topic); if (flux_rpc_get (rpc, NULL) < 0) log_err_exit ("%s", topic); flux_rpc_destroy (rpc); flux_close (h); return (0); }
void test_echo (flux_t *h, uint32_t nodeid) { json_object *in = Jnew (); json_object *out = NULL; const char *json_str; const char *s; flux_future_t *f; Jadd_str (in, "mumble", "burble"); if (!(f = flux_rpc (h, "req.echo", Jtostr (in), nodeid, 0)) || flux_rpc_get (f, &json_str) < 0) log_err_exit ("%s", __FUNCTION__); if (!json_str || !(out = Jfromstr (json_str)) || !Jget_str (out, "mumble", &s) || strcmp (s, "burble") != 0) log_msg_exit ("%s: returned payload wasn't an echo", __FUNCTION__); Jput (in); Jput (out); flux_future_destroy (f); }
int get_watch_stats (flux_t *h, int *count) { flux_rpc_t *rpc; const char *json_str; json_object *o = NULL; int rc = -1; if (!(rpc = flux_rpc (h, "kvs.stats.get", NULL, FLUX_NODEID_ANY, 0))) goto done; if (flux_rpc_get (rpc, &json_str) < 0) goto done; if (!(o = Jfromstr (json_str)) || !Jget_int (o, "#watchers", count)) { errno = EPROTO; goto done; } rc = 0; done: flux_rpc_destroy (rpc); Jput (o); return rc; }
static int internal_heaptrace_dump (optparse_t *p, int ac, char *av[]) { flux_t *h; flux_rpc_t *rpc; json_object *in = Jnew (); if (optparse_optind (p) != ac - 1) { optparse_print_usage (p); exit (1); } Jadd_str (in, "reason", av[ac - 1]); if (!(h = builtin_get_flux_handle (p))) log_err_exit ("flux_open"); if (!(rpc = flux_rpc (h, "cmb.heaptrace.dump", Jtostr (in), FLUX_NODEID_ANY, 0)) || flux_rpc_get (rpc, NULL) < 0) log_err_exit ("cmb.heaptrace.dump"); flux_rpc_destroy (rpc); flux_close (h); return (0); }
static void xping (flux_t *h, uint32_t nodeid, uint32_t xnodeid, const char *svc) { flux_future_t *f; const char *json_str; json_object *in = Jnew (); json_object *out = NULL; const char *route; Jadd_int (in, "rank", xnodeid); Jadd_str (in, "service", svc); if (!(f = flux_rpc (h, "req.xping", Jtostr (in), nodeid, 0)) || flux_rpc_get (f, &json_str) < 0) log_err_exit ("req.xping"); if (!json_str || !(out = Jfromstr (json_str)) || !Jget_str (out, "route", &route)) log_errn_exit (EPROTO, "req.xping"); printf ("hops=%d\n", count_hops (route)); Jput (out); Jput (in); flux_future_destroy (f); }
static int lwj_kvs_path (flux_t *h, int64_t id, char **pathp) { int rc = -1; const char *path; const char *json_str; flux_future_t *f; uint32_t nodeid = FLUX_NODEID_ANY; json_object *o = kvspath_request_json (id); if (!(f = flux_rpc (h, "job.kvspath", Jtostr (o), nodeid, 0)) || (flux_rpc_get (f, &json_str) < 0)) { flux_log_error (h, "flux_rpc (job.kvspath)"); goto out; } Jput (o); o = NULL; if (!json_str) { flux_log (h, LOG_ERR, "flux_rpc (job.kvspath): empty payload"); goto out; } if (!(o = Jfromstr (json_str))) { flux_log_error (h, "flux_rpc (job.kvspath): failed to parse json"); goto out; } if (!(path = kvs_path_json_get (o))) { flux_log_error (h, "flux_rpc (job.kvspath): failed to get path"); goto out; } if (!(*pathp = strdup (path))) { flux_log_error (h, "flux_rpc (job.kvspath): strdup"); goto out; } rc = 0; out: flux_future_destroy (f); Jput (o); return (rc); }
int rpctest_begin_cb (flux_t h, int type, zmsg_t **zmsg, void *arg) { uint32_t nodeid; int i, errors; int old_count; flux_rpc_t *r; const char *json_str; errno = 0; ok (!(r = flux_rpc_multi (h, NULL, "foo", "all", 0)) && errno == EINVAL, "flux_rpc_multi [0] with NULL topic fails with EINVAL"); errno = 0; ok (!(r = flux_rpc_multi (h, "bar", "foo", NULL, 0)) && errno == EINVAL, "flux_rpc_multi [0] with NULL nodeset fails with EINVAL"); errno = 0; ok (!(r = flux_rpc_multi (h, "bar", "foo", "xyz", 0)) && errno == EINVAL, "flux_rpc_multi [0] with bad nodeset fails with EINVAL"); /* working no-payload RPC */ old_count = hello_count; ok ((r = flux_rpc_multi (h, "rpctest.hello", NULL, "all", 0)) != NULL, "flux_rpc_multi [0] with no payload when none is expected works"); if (!r) BAIL_OUT ("can't continue without successful rpc call"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); ok (flux_rpc_get (r, NULL, NULL) == 0, "flux_rpc_get works"); ok (hello_count == old_count + 1, "rpc was called once"); flux_rpc_destroy (r); /* cause remote EPROTO (unexpected payload) - picked up in _get() */ ok ((r = flux_rpc_multi (h, "rpctest.hello", "foo", "all", 0)) != NULL, "flux_rpc_multi [0] with unexpected payload works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* fake that we have a larger session */ fake_size = 128; char s[16]; uint32_t size = 0; snprintf (s, sizeof (s), "%u", fake_size); flux_attr_fake (h, "size", s, FLUX_ATTRFLAG_IMMUTABLE); flux_get_size (h, &size); cmp_ok (size, "==", fake_size, "successfully faked flux_get_size() of %d", fake_size); /* repeat working no-payload RPC test (now with 128 nodes) */ old_count = hello_count; ok ((r = flux_rpc_multi (h, "rpctest.hello", NULL, "all", 0)) != NULL, "flux_rpc_multi [0-%d] with no payload when none is expected works", fake_size - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errors = 0; for (i = 0; i < fake_size; i++) if (flux_rpc_get (r, NULL, NULL) < 0) errors++; ok (errors == 0, "flux_rpc_get succeded %d times", fake_size); cmp_ok (hello_count - old_count, "==", fake_size, "rpc was called %d times", fake_size); flux_rpc_destroy (r); /* same with a subset */ old_count = hello_count; ok ((r = flux_rpc_multi (h, "rpctest.hello", NULL, "[0-63]", 0)) != NULL, "flux_rpc_multi [0-%d] with no payload when none is expected works", 64 - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errors = 0; for (i = 0; i < 64; i++) if (flux_rpc_get (r, &nodeid, NULL) < 0 || nodeid != i) errors++; ok (errors == 0, "flux_rpc_get succeded %d times, with correct nodeid map", 64); cmp_ok (hello_count - old_count, "==", 64, "rpc was called %d times", 64); flux_rpc_destroy (r); /* same with echo payload */ ok ((r = flux_rpc_multi (h, "rpctest.echo", "foo", "[0-63]", 0)) != NULL, "flux_rpc_multi [0-%d] ok", 64 - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errors = 0; for (i = 0; i < 64; i++) { if (flux_rpc_get (r, NULL, &json_str) < 0 || !json_str || strcmp (json_str, "foo") != 0) errors++; } ok (errors == 0, "flux_rpc_get succeded %d times, with correct return payload", 64); flux_rpc_destroy (r); /* detect partial failure without mresponse */ nodeid_fake_error = 20; ok ((r = flux_rpc_multi (h, "rpctest.nodeid", NULL, "[0-63]", 0)) != NULL, "flux_rpc_multi [0-%d] ok", 64 - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); for (i = 0; i < 64; i++) { if (flux_rpc_get (r, &nodeid, &json_str) < 0) break; } ok (i == 20 && errno == EPERM, "flux_rpc_get correctly reports single error"); flux_rpc_destroy (r); /* test _then (still at fake session size of 128) */ ok ((then_r = flux_rpc_multi (h, "rpctest.hello", NULL, "[0-127]", 0)) != NULL, "flux_rpc_multi [0-127] ok"); ok (flux_rpc_then (then_r, then_cb, h) == 0, "flux_rpc_then works"); /* then_cb stops reactor; results reported, then_r destroyed in main() */ return 0; }
void rpctest_begin_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { const char *json_str; flux_rpc_t *r; errno = 0; ok (!(r = flux_rpc (h, NULL, NULL, FLUX_NODEID_ANY, 0)) && errno == EINVAL, "flux_rpc with NULL topic fails with EINVAL"); /* working no-payload RPC */ ok ((r = flux_rpc (h, "rpctest.hello", NULL, FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with no payload when none is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); ok (flux_rpc_get (r, NULL) == 0, "flux_rpc_get works"); flux_rpc_destroy (r); /* cause remote EPROTO (unexpected payload) - will be picked up in _get() */ ok ((r = flux_rpc (h, "rpctest.hello", "{}", FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with payload when none is expected works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* cause remote EPROTO (missing payload) - will be picked up in _get() */ errno = 0; ok ((r = flux_rpc (h, "rpctest.echo", NULL, FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with no payload when payload is expected works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* working with-payload RPC */ ok ((r = flux_rpc (h, "rpctest.echo", "{}", FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with payload when payload is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); json_str = NULL; ok (flux_rpc_get (r, &json_str) == 0 && json_str && !strcmp (json_str, "{}"), "flux_rpc_get works and returned expected payload"); flux_rpc_destroy (r); /* working with-payload RPC (raw) */ char *d, data[] = "aaaaaaaaaaaaaaaaaaaa"; int l, len = strlen (data); ok ((r = flux_rpc_raw (h, "rpctest.rawecho", data, len, FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc_raw with payload when payload is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); json_str = NULL; ok (flux_rpc_get_raw (r, &d, &l) == 0 && d != NULL && l == len && memcmp (data, d, len) == 0, "flux_rpc_get_raw works and returned expected payload"); flux_rpc_destroy (r); /* use newish pack/unpack payload interfaces */ int i = 0; ok ((r = flux_rpcf (h, "rpctest.incr", FLUX_NODEID_ANY, 0, "{s:i}", "n", 107)) != NULL, "flux_rpcf works"); ok (flux_rpc_getf (r, "{s:i}", "n", &i) == 0, "flux_rpc_getf works"); ok (i == 108, "and service returned incremented value"); flux_rpc_destroy (r); flux_reactor_stop (flux_get_reactor (h)); }
static flux_msg_t *op_recv (void *impl, int flags) { ctx_t *ctx = impl; assert (ctx->magic == MODHANDLE_MAGIC); zmq_pollitem_t zp = { .events = ZMQ_POLLIN, .socket = ctx->sock, .revents = 0, .fd = -1, }; flux_msg_t *msg = NULL; if (connect_socket (ctx) < 0) goto done; if ((flags & FLUX_O_NONBLOCK)) { int n; if ((n = zmq_poll (&zp, 1, 0L)) <= 0) { if (n == 0) errno = EWOULDBLOCK; goto done; } } msg = flux_msg_recvzsock (ctx->sock); done: return msg; } static int op_event_subscribe (void *impl, const char *topic) { ctx_t *ctx = impl; assert (ctx->magic == MODHANDLE_MAGIC); json_object *in = Jnew (); flux_rpc_t *rpc = NULL; int rc = -1; if (connect_socket (ctx) < 0) goto done; Jadd_str (in, "topic", topic); if (!(rpc = flux_rpc (ctx->h, "cmb.sub", Jtostr (in), FLUX_NODEID_ANY, 0)) || flux_rpc_get (rpc, NULL) < 0) goto done; rc = 0; done: Jput (in); flux_rpc_destroy (rpc); return rc; }