-/*
- * ret: Negative on errors, zero if nothing was written and write returned
- * EAGAIN, number of bytes written else.
- */
-static int http_write(int fd, const char *buf, size_t len)
-{
- size_t written = 0;
-
- while (written < len) {
- int ret = write(fd, buf + written, len - written);
- if (ret < 0 && errno == EAGAIN)
- return written;
- if (ret < 0)
- return -ERRNO_TO_PARA_ERROR(errno);
- written += ret;
- }
- return written;
-}
-
-
-static int send_queued_chunks(struct http_client *hc)
-{
- struct queued_chunk *qc;
- while ((qc = cq_peek(hc->cq))) {
- char *buf;
- size_t len;
- int ret;
- cq_get(qc, &buf, &len);
- ret = http_write(hc->fd, buf, len);
- if (ret < 0)
- return ret;
- cq_update(hc->cq, ret);
- if (ret != len)
- return 1;
- cq_dequeue(hc->cq);
- }
- return 1;
-}
-
-static int queue_chunk_or_shutdown(struct http_client *hc, long unsigned chunk_num,
- size_t sent)