-static int queue_chunk(struct http_client *hc, long unsigned chunk_num,
- size_t sent)
-{
- struct queued_chunk *qc;
- char *buf;
- size_t len;
- int ret;
-
- if (chunk_num != -1U) {
- ret = vss_get_chunk(chunk_num, &buf, &len);
- if (ret < 0)
- return ret;
- } else
- buf = vss_get_header(&len);
- if (hc->cq_bytes + len > MAX_BACKLOG)
- return -E_QUEUE;
- qc = para_malloc(sizeof(struct queued_chunk));
- hc->cq_bytes += len;
- qc->chunk_num = chunk_num;
- qc->sent = sent;
- list_add_tail(&qc->node, &hc->chunk_queue);
- PARA_INFO_LOG("%lu bytes queued for fd %d\n", hc->cq_bytes, hc->fd);
- return 1;
-}
-
-static int send_queued_chunks(struct http_client *hc)
-{
- int ret;
- struct queued_chunk *qc, *tmp;
-
- if (list_empty(&hc->chunk_queue))
- return 1;
- list_for_each_entry_safe(qc, tmp, &hc->chunk_queue, node) {
- char *buf;
- size_t len;
- ret = write_ok(hc->fd);
- if (ret <= 0)
- return ret? -E_WRITE_OK : 0;
- if (qc->chunk_num != -1U) {
- ret = vss_get_chunk(qc->chunk_num, &buf, &len);
- if (ret < 0)
- return ret;
- } else
- buf = vss_get_header(&len);
- assert(len && len > qc->sent);
- ret = write(hc->fd, buf + qc->sent, len - qc->sent);
- if (ret < 0)
- return -1; /* FIXME */
- hc->cq_bytes -= ret;
- if (ret != len - qc->sent) {
- qc->sent += ret;
- return 0;
- }
- list_del(&qc->node);
- free(qc);
- }
- return 1;
-}
-
-static int queue_chunk_or_shutdown(struct http_client *hc, long unsigned chunk_num,
- size_t sent)