static void s_io_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { struct context *ctx = arg; int *rfd, fd = flux_fd_watcher_get_fd (w); char *resp; int rc; if (dgetline (fd, ctx->buf, ctx->buflen) < 0) { diag ("dgetline: %s", strerror (errno)); flux_reactor_stop_error (r); return; } rc = pmi_simple_server_request (ctx->pmi, ctx->buf, &ctx->fds[1]); if (rc < 0) { diag ("pmi_simple_server_request: %s", strerror (errno)); flux_reactor_stop_error (r); return; } while (pmi_simple_server_response (ctx->pmi, &resp, &rfd) == 0) { if (dputline (*rfd, resp) < 0) { diag ("dputline: %s", strerror (errno)); flux_reactor_stop_error (r); return; } free (resp); } if (rc == 1) { close (fd); flux_watcher_stop (w); } }
static void fdreader (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { int fd = flux_fd_watcher_get_fd (w); static char *buf = NULL; static int count = 0; int n; if (!buf) buf = xzmalloc (fdwriter_bufsize); if (revents & FLUX_POLLERR) { fprintf (stderr, "%s: FLUX_POLLERR is set\n", __FUNCTION__); goto error; } if (revents & FLUX_POLLIN) { if ((n = read (fd, buf + count, fdwriter_bufsize - count)) < 0 && errno != EWOULDBLOCK && errno != EAGAIN) { fprintf (stderr, "%s: read failed: %s\n", __FUNCTION__, strerror (errno)); goto error; } if (n > 0) { count += n; if (count == fdwriter_bufsize) { flux_watcher_stop (w); free (buf); } } } return; error: flux_reactor_stop_error (r); }
static void zmqwriter (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { void *sock = flux_zmq_watcher_get_zsock (w); static int count = 0; if (revents & FLUX_POLLERR) { fprintf (stderr, "%s: FLUX_POLLERR is set\n", __FUNCTION__); goto error; } if (revents & FLUX_POLLOUT) { uint8_t blob[64]; zmsg_t *zmsg = zmsg_new (); if (!zmsg || zmsg_addmem (zmsg, blob, sizeof (blob)) < 0) { fprintf (stderr, "%s: failed to create message: %s\n", __FUNCTION__, strerror (errno)); goto error; } if (zmsg_send (&zmsg, sock) < 0) { fprintf (stderr, "%s: zmsg_send: %s\n", __FUNCTION__, strerror (errno)); goto error; } count++; if (count == zmqwriter_msgcount) flux_watcher_stop (w); } return; error: flux_reactor_stop_error (r); }
static void zmqreader (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { void *sock = flux_zmq_watcher_get_zsock (w); static int count = 0; if (revents & FLUX_POLLERR) { fprintf (stderr, "%s: FLUX_POLLERR is set\n", __FUNCTION__); goto error; } if (revents & FLUX_POLLIN) { zmsg_t *zmsg = zmsg_recv (sock); if (!zmsg) { fprintf (stderr, "%s: zmsg_recv: %s\n", __FUNCTION__, strerror (errno)); goto error; } zmsg_destroy (&zmsg); count++; if (count == zmqwriter_msgcount) flux_watcher_stop (w); } return; error: flux_reactor_stop_error (r); }
/* check: * Runs right after reactor calls poll(2). * Stop idle watcher, and send next alloc request, if available. */ static void check_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { struct alloc_ctx *ctx = arg; struct job *job; flux_watcher_stop (ctx->idle); if (!ctx->ready) return; if (ctx->mode == SCHED_SINGLE && ctx->active_alloc_count > 0) return; if ((job = queue_first (ctx->inqueue))) { if (alloc_request (ctx, job) < 0) { flux_log_error (ctx->h, "alloc_request fatal error"); flux_reactor_stop_error (flux_get_reactor (ctx->h)); return; } queue_delete (ctx->inqueue, job, job->aux_queue_handle); job->aux_queue_handle = NULL; job->alloc_pending = 1; job->alloc_queued = 0; ctx->active_alloc_count++; if ((job->flags & FLUX_JOB_DEBUG)) (void)event_job_post_pack (ctx->event_ctx, job, "debug.alloc-request", NULL); } }
/* 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)); }
static void multmatch2 (flux_t h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { const char *topic; if (flux_msg_get_topic (msg, &topic) < 0 || strcmp (topic, "foo.bar")) flux_reactor_stop_error (flux_get_reactor (h)); flux_msg_handler_stop (w); multmatch_count++; }
static void oneshot (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { oneshot_ran = true; if (oneshot_errno != 0) { errno = oneshot_errno; flux_reactor_stop_error (r); } }
static void zio_flux_writer_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { zio_t *zio = arg; int rc; zio_handler_start (zio); rc = zio_writer_cb (zio); if (!zio_write_pending (zio)) flux_watcher_stop (w); zio_handler_end (zio); if (rc < 0) flux_reactor_stop_error (r); }
static void s_io_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { struct context *ctx = arg; int fd = flux_fd_watcher_get_fd (w); int rc; if (dgetline (fd, ctx->buf, sizeof (ctx->buf)) < 0) { diag ("dgetline: %s", strerror (errno)); flux_reactor_stop_error (r); return; } rc = pmi_simple_server_request (ctx->pmi, ctx->buf, &ctx->fds[1]); if (rc < 0) { diag ("pmi_simple_server_request: %s", strerror (errno)); flux_reactor_stop_error (r); return; } if (rc == 1) { close (fd); flux_watcher_stop (w); } }
static void zio_flux_read_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { zio_t *zio = arg; int rc; zio_handler_start (zio); rc = zio_read_cb_common (zio); if (rc >= 0 && zio_eof_sent (zio)) { zio_debug (zio, "reader detaching from flux reactor\n"); flux_watcher_stop (w); rc = zio_close (zio); } zio_handler_end (zio); if (rc < 0) flux_reactor_stop_error (r); }
static void handle_cb (flux_reactor_t *r, flux_watcher_t *hw, int revents, void *arg) { struct dispatch *d = arg; flux_msg_handler_t *w; flux_msg_t *msg = NULL; int type; if (revents & FLUX_POLLERR) goto fatal; if (!(msg = flux_recv (d->h, FLUX_MATCH_ANY, FLUX_O_NONBLOCK))) { if (errno != EAGAIN && errno != EWOULDBLOCK) goto fatal; else goto done; } if (flux_msg_get_type (msg, &type) < 0) goto done; /* Message matches a coproc that yielded. * Resume, arranging for msg to be returned next by flux_recv(). */ if ((w = find_waiting_handler (d, msg))) { if (flux_requeue (d->h, msg, FLUX_RQ_HEAD) < 0) goto fatal; zlist_remove (d->waiters, w); if (resume_coproc (w) < 0) goto fatal; /* Message matches a handler. * If coproc already running, queue message as backlog. * Else if FLUX_O_COPROC, start coproc. * If coprocs not enabled, call handler directly. */ } else if ((w = find_handler (d, msg))) { if (w->coproc && coproc_started (w->coproc)) { if (backlog_append (w, &msg) < 0) /* msg now property of backlog */ goto fatal; } else if ((flux_flags_get (d->h) & FLUX_O_COPROC)) { if (flux_requeue (d->h, msg, FLUX_RQ_HEAD) < 0) goto fatal; if (start_coproc (w) < 0) goto fatal; } else { w->fn (d->h, w, msg, w->arg); } /* Message matched nothing. * Respond with ENOSYS if it was a request. * Else log it if FLUX_O_TRACE */ } else { if (type == FLUX_MSGTYPE_REQUEST) { if (flux_respond (d->h, msg, ENOSYS, NULL)) goto done; } else if (flux_flags_get (d->h) & FLUX_O_TRACE) { const char *topic = NULL; (void)flux_msg_get_topic (msg, &topic); fprintf (stderr, "nomatch: %s '%s'\n", flux_msg_typestr (type), topic ? topic : ""); } } done: flux_msg_destroy (msg); return; fatal: flux_msg_destroy (msg); flux_reactor_stop_error (r); FLUX_FATAL (d->h); }