/* * Write json string to this zio object, buffering unwritten data. */ int zio_write_json (zio_t *zio, const char *json_str) { char *s = NULL; int len, rc = 0; bool eof; if ((zio == NULL) || (zio->magic != ZIO_MAGIC) || !zio_writer (zio)) { errno = EINVAL; return (-1); } len = zio_json_decode (json_str, (void **)&s, &eof); if (len < 0) { errno = EINVAL; return (-1); } if (eof) zio_set_eof (zio); if (len > 0) rc = zio_write_internal (zio, s, len); else if (zio_write_pending (zio)) zio_writer_schedule (zio); free (s); return rc; }
int zio_write_eof (zio_t *zio) { if ((zio == NULL) || (zio->magic != ZIO_MAGIC) || !zio_writer (zio)) { errno = EINVAL; return (-1); } zio_set_eof (zio); /* If no data is buffered, then we can close the dst fd: */ if (zio_buffer_empty (zio)) zio_close (zio); return (0); }
int zio_read (zio_t *zio) { int n; assert ((zio != NULL) && (zio->magic == ZIO_MAGIC)); if ((n = cbuf_write_from_fd (zio->buf, zio->srcfd, -1, NULL)) < 0) return (-1); zio_debug (zio, "zio_read: read = %d\n", n); if (n == 0) { zio_set_eof (zio); zio_debug (zio, "zio_read_cb: Got eof\n"); } zio_flush (zio); return (n); }