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 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); } }
void fd_read (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { struct counts *c = arg; char buf[64]; int fd = flux_fd_watcher_get_fd (w); int n = -1; if ((revents & FLUX_POLLIN)) { n = read (fd, buf, sizeof (buf)); if (n < 0) c->fd_read_errors++; else if (n == 0) { c->fd_read_eof++; flux_watcher_stop (w); } else if (n > 0) c->fd_read_data += n; } if ((revents & FLUX_POLLERR)) c->fd_read_errors++; diag ("%s: %d", __FUNCTION__, n); }
static void attach_stdin_ready_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { int fd = flux_fd_watcher_get_fd (w); t_kzutil_ctx_t *ctx = arg; char *buf = xzmalloc (ctx->blocksize); int len; do { if ((len = read (fd, buf, ctx->blocksize)) < 0) { if (errno != EAGAIN) log_err_exit ("read stdin"); } else if (len > 0) { if (kz_put (ctx->kz[0], buf, len) < 0) log_err_exit ("kz_put"); } } while (len > 0); if (len == 0) { /* EOF */ if (kz_close (ctx->kz[0]) < 0) log_err_exit ("kz_close"); } free (buf); }
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); } }