/* * Flush any buffered output and EOF from zio READER object * to destination. */ int zio_flush (zio_t *zio) { int len; int rc = 0; if ((zio == NULL) || (zio->magic != ZIO_MAGIC)) return (-1); if (zio_reader (zio) && !zio->send) return (-1); zio_debug (zio, "zio_flush\n"); /* * Nothing to flush if EOF already sent to consumer: */ if (zio_eof_sent (zio)) return (0); if (zio_writer (zio)) return zio_writer_flush_all (zio); /* else zio reader: */ while (((len = zio_data_to_flush (zio)) > 0) || zio_eof (zio)) { char * buf = NULL; int n = 0; zio_debug (zio, "zio_flush: len = %d, eof = %d\n", len, zio_eof (zio)); if (len > 0) { buf = xzmalloc (len + 1); if ((n = zio_fd_read (zio, buf, len + 1)) <= 0) { if (n < 0) { zio_debug (zio, "zio_read: %s", strerror (errno)); rc = -1; } /* * We may not be able to read any data from the buffer * because we are line buffering and there is not yet * a full line in the buffer. In this case just exit * so we can buffer more data. */ free (buf); return (rc); } } zio_debug (zio, "zio_data_to_flush = %d\n", zio_data_to_flush (zio)); zio_debug (zio, "zio_flush: Sending %d (%s) [eof=%d]\n", n, buf, zio_eof(zio)); rc = zio_send (zio, buf, n); if (buf) free (buf); if (zio_eof_sent (zio)) break; } return (rc); }
static int zio_flux_read_cb (flux_t f, int fd, short revents, zio_t *zio) { 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_fdhandler_remove (f, fd, ZMQ_POLLIN|ZMQ_POLLERR); rc = zio_close (zio); } zio_handler_end (zio); return (rc); }
static int zio_zloop_read_cb (zloop_t *zl, zmq_pollitem_t *zp, zio_t *zio) { 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 zloop\n"); zloop_poller_end (zl, zp); rc = zio_close (zio); } zio_handler_end (zio); return (rc); }
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); }