void test_selfmod (int argc, char **argv) { flux_t h; char *key; if (argc != 1) { fprintf (stderr, "Usage: selfmod key\n"); exit (1); } key = argv[0]; if (!(h = flux_open (NULL, 0))) err_exit ("flux_open"); if (kvs_put_int (h, key, -1) < 0) err_exit ("kvs_put_int"); if (kvs_commit (h) < 0) err_exit ("kvs_commit"); if (kvs_watch_int (h, key, selfmod_watch_cb, h) < 0) err_exit ("kvs_watch_int"); msg ("reactor: start"); flux_reactor_start (h); msg ("reactor: end"); flux_close (h); }
void *thread (void *arg) { thd_t *t = arg; if (!(t->h = flux_open (NULL, 0))) { err ("%d: flux_open", t->n); goto done; } signal_ready (); /* The first kvs.watch reply is handled synchronously, then other kvs.watch * replies will arrive asynchronously and be handled by the reactor. */ if (kvs_watch_int (t->h, key, mt_watch_cb, t) < 0) { err ("%d: kvs_watch_int", t->n); goto done; } if (kvs_watch_int (t->h, "nonexistent-key", mt_watchnil_cb, t) < 0) { err ("%d: kvs_watch_int", t->n); goto done; } if (kvs_watch_int (t->h, key_stable, mt_watchstable_cb, t) < 0) { err ("%d: kvs_watch_int", t->n); goto done; } if (flux_reactor_start (t->h) < 0) { err ("%d: flux_reactor_start", t->n); goto done; } done: if (t->h) flux_close (t->h); return NULL; }
int mod_main (flux_t h, int argc, char **argv) { _store_hosts(h); if (flux_reactor_start (h) < 0) { flux_log (h, LOG_ERR, "flux_reactor_start: %s", strerror (errno)); return -1; } return 0; }
int mod_main (flux_t h, int argc, char **argv) { ctx_t *ctx = getctx (h); char *sockpath = NULL, *dfltpath = NULL; int rc = -1; /* Parse args. */ if (argc > 0) sockpath = argv[0]; if (!sockpath) sockpath = dfltpath = xasprintf ("%s/flux-api", flux_get_tmpdir ()); /* Create listen socket and watcher to handle new connections */ if ((ctx->listen_fd = listener_init (ctx, sockpath)) < 0) goto done; if (!(ctx->listen_w = flux_fd_watcher_create (ctx->listen_fd, FLUX_POLLIN | FLUX_POLLERR, listener_cb, ctx))) { flux_log (h, LOG_ERR, "flux_fd_watcher_create: %s", strerror (errno)); goto done; } flux_fd_watcher_start (h, ctx->listen_w); /* Create/start event/response message watchers */ if (flux_msg_watcher_addvec (h, htab, ctx) < 0) { flux_log (h, LOG_ERR, "flux_msg_watcher_addvec: %s", strerror (errno)); goto done; } /* Start reactor */ if (flux_reactor_start (h) < 0) { flux_log (h, LOG_ERR, "flux_reactor_start: %s", strerror (errno)); goto done; } rc = 0; done: if (dfltpath) free (dfltpath); flux_msg_watcher_delvec (h, htab); flux_fd_watcher_destroy (ctx->listen_w); if (ctx->listen_fd >= 0) { if (close (ctx->listen_fd) < 0) flux_log (h, LOG_ERR, "close listen_fd: %s", strerror (errno)); } if (ctx->clients) { client_t *c; while ((c = zlist_pop (ctx->clients))) client_destroy (c); } return rc; }
int mod_main (flux_t h, int argc, char **argv) { if (flux_msghandler_add (h, FLUX_MSGTYPE_REQUEST, "job.*", job_request_cb, NULL) < 0) { flux_log (h, LOG_ERR, "flux_msghandler_add: %s", strerror (errno)); return -1; } if (flux_reactor_start (h) < 0) { flux_log (h, LOG_ERR, "flux_reactor_start: %s", strerror (errno)); return -1; } return 0; }
int mod_main (flux_t h, int argc, char **argv) { flux_flags_set (h, FLUX_O_COPROC); if (flux_msghandler_addvec (h, htab, htablen, NULL) < 0) { flux_log (h, LOG_ERR, "flux_msghandler_addvec: %s", strerror (errno)); return -1; } if (flux_reactor_start (h) < 0) { flux_log (h, LOG_ERR, "flux_reactor_start: %s", strerror (errno)); return -1; } return 0; }
int mod_main (flux_t h, int argc, char **argv) { ctx_t *ctx = getctx (h); if (flux_msghandler_addvec (h, htab, htablen, ctx) < 0) { flux_log (h, LOG_ERR, "flux_msghandler_addvec: %s", strerror (errno)); return -1; } if (flux_reactor_start (h) < 0) { flux_log (h, LOG_ERR, "flux_reactor_start: %s", strerror (errno)); return -1; } return 0; }
int mod_main (flux_t h, zhash_t *args) { ctx_t *ctx = getctx (h); if (flux_event_subscribe (h, "xbarrier.") < 0) { err ("%s: flux_event_subscribe", __FUNCTION__); return -1; } if (flux_msghandler_addvec (h, htab, htablen, ctx) < 0) { flux_log (h, LOG_ERR, "flux_msghandler_addvec: %s", strerror (errno)); return -1; } if (flux_reactor_start (h) < 0) { flux_log (h, LOG_ERR, "flux_reactor_start: %s", strerror (errno)); return -1; } return 0; }
/* Timer pops every 1 ms, writing a new value to key. * After 10 calls, it calls kvs_unwatch(). * After 20 calls, it calls flux_reactor_stop(). * The kvs_unwatch_cb() counts the number of times it is called, should be 10. */ void test_unwatch (int argc, char **argv) { flux_t h; char *key; int count = 0; if (argc != 1) { fprintf (stderr, "Usage: unwatch key\n"); exit (1); } key = argv[0]; if (!(h = flux_open (NULL, 0))) err_exit ("flux_open"); if (kvs_watch_int (h, key, unwatch_watch_cb, &count) < 0) err_exit ("kvs_watch_int %s", key); if (flux_tmouthandler_add (h, 1, false, unwatch_timer_cb, key) < 0) err_exit ("flux_tmouthandler_add"); if (flux_reactor_start (h) < 0) err_exit ("flux_reactor_start"); if (count != 10) msg_exit ("watch called %d times (should be 10)", count); flux_close (h); }
int main (int argc, char *argv[]) { flux_msg_t *msg; flux_t h; plan (33); (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0); ok ((h = flux_open ("loop://", FLUX_O_COPROC)) != NULL, "opened loop connector"); if (!h) BAIL_OUT ("can't continue without loop handle"); flux_fatal_set (h, fatal_err, NULL); ok (flux_msg_watcher_addvec (h, htab, NULL) == 0, "registered message handlers"); /* test continues in rpctest_begin_cb() so that rpc calls * can sleep while we answer them */ ok ((msg = flux_request_encode ("rpctest.begin", NULL)) != NULL, "encoded rpctest.begin request OK"); ok (flux_send (h, msg, 0) == 0, "sent rpctest.begin request"); ok (flux_reactor_start (h) == 0, "reactor completed normally"); flux_msg_destroy (msg); /* test _then: Slightly tricky. * Send request. We're not in a coproc ctx here in main(), so there * will be no response, therefore, check will be false. Register * continuation, start reactor. Response will be received, continuation * will be invoked. Continuation stops the reactor. */ flux_rpc_t *r; ok ((r = flux_rpc (h, "rpctest.echo", "xxx", 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"); /* reg/unreg _then a couple times for fun */ ok (flux_rpc_then (r, NULL, 0) == 0, "flux_rpc_then with NULL cb works"); ok (flux_rpc_then (r, then_cb, h) == 0, "flux_rpc_then works after NULL"); ok (flux_rpc_then (r, NULL, 0) == 0, "flux_rpc_then with NULL cb after non-NULL works"); ok (flux_rpc_then (r, then_cb, h) == 0, "flux_rpc_then works"); /* enough of that */ ok (flux_reactor_start (h) == 0, "reactor completed normally"); flux_rpc_destroy (r); /* Test a _then corner case: * If _check() is called before _then(), a message may have been cached * in the flux_rpc_t. rpctest_thenbug_cb creates this condition. * Next, _then continuation is installed, but will reactor call it? * This will hang if rpc implementation doesn't return a cached message * back to the handle in _then(). Else, continuation will stop reactor. */ ok ((thenbug_r = flux_rpc (h, "rpctest.echo", "xxx", FLUX_NODEID_ANY, 0)) != NULL, "thenbug: sent echo request"); do { if (!(msg = flux_request_encode ("rpctest.thenbug", NULL)) || flux_send (h, msg, 0) < 0 || flux_reactor_start (h) < 0) { flux_msg_destroy (msg); break; } flux_msg_destroy (msg); } while (!flux_rpc_check (thenbug_r)); ok (true, "thenbug: check says message ready"); ok (flux_rpc_then (thenbug_r, then_cb, h) == 0, "thenbug: registered then - hangs on failure"); ok (flux_reactor_start (h) == 0, "reactor completed normally"); flux_rpc_destroy (thenbug_r); flux_msg_watcher_delvec (h, htab); flux_close (h); done_testing(); return (0); }
int main (int argc, char **argv) { flux_t h; heartbeat_t *hb; flux_msg_watcher_t *w; plan (21); check_codec (); (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0); ok ((h = flux_open ("loop://", 0)) != NULL, "opened loop connector"); if (!h) BAIL_OUT ("can't continue without loop handle"); flux_fatal_set (h, fatal_err, NULL); ok ((hb = heartbeat_create ()) != NULL, "heartbeat_create works"); heartbeat_set_flux (hb, h); heartbeat_set_callback (hb, heartbeat_cb, NULL); ok (heartbeat_get_rate (hb) == 2., "heartbeat_get_rate returns default of 2s"); errno = 0; ok (heartbeat_set_rate (hb, -1) < 1 && errno == EINVAL, "heartbeat_set_rate -1 fails with EINVAL"); errno = 0; ok (heartbeat_set_rate (hb, 1000000) < 1 && errno == EINVAL, "heartbeat_set_rate 1000000 fails with EINVAL"); ok (heartbeat_set_ratestr (hb, "250ms") == 0, "heartbeat_set_ratestr 250ms works"); ok (heartbeat_get_rate (hb) == 0.250, "heartbeat_get_rate returns what was set"); ok (heartbeat_set_rate (hb, 0.1) == 0, "heartbeat_set_rate 0.1 works"); ok (heartbeat_get_rate (hb) == 0.1, "heartbeat_get_rate returns what was set"); ok (heartbeat_get_epoch (hb) == 0, "heartbeat_get_epoch works, default is zero"); w = flux_msg_watcher_create (FLUX_MATCH_EVENT, heartbeat_event_cb, hb); ok (w != NULL, "created event watcher"); flux_msg_watcher_start (h, w); ok (heartbeat_start (hb) == 0, "heartbeat_start works"); ok (flux_reactor_start (h) == 0, "flux reactor exited normally"); heartbeat_destroy (hb); flux_msg_watcher_destroy (w); flux_close (h); done_testing (); return 0; }