/** The position of this client in the client list. */
struct list_head node;
/** The list of pending chunks for this client. */
- struct chunk_queue cq;
+ struct chunk_queue *cq;
};
/**
return 1;
}
-void cq_init(struct chunk_queue *cq, size_t max_pending)
+struct chunk_queue *cq_init(size_t max_pending)
{
+ struct chunk_queue *cq = para_malloc(sizeof(*cq));
INIT_LIST_HEAD(&cq->q);
cq->max_pending = max_pending;
cq->num_pending = 0;
+ return cq;
}
void cq_destroy(struct chunk_queue *cq)
list_del(&qc->node);
free(qc);
}
+ free(cq);
}
static void http_shutdown_client(struct http_client *hc, const char *msg)
numclients--;
close(hc->fd);
del_close_on_fork_list(hc->fd);
- cq_destroy(&hc->cq);
+ cq_destroy(hc->cq);
list_del(&hc->node);
free(hc);
}
static int send_queued_chunks(struct http_client *hc)
{
struct queued_chunk *qc;
- while ((qc = cq_peek(&hc->cq))) {
+ while ((qc = cq_peek(hc->cq))) {
char *buf;
size_t len;
int ret = write_ok(hc->fd);
ret = write(hc->fd, buf, len);
if (ret < 0)
return -1; /* FIXME */
- cq_update(&hc->cq, ret);
+ cq_update(hc->cq, ret);
if (ret != len)
return 1;
- cq_dequeue(&hc->cq);
+ cq_dequeue(hc->cq);
}
return 1;
}
static int queue_chunk_or_shutdown(struct http_client *hc, long unsigned chunk_num,
size_t sent)
{
- int ret = cq_enqueue(&hc->cq, chunk_num, sent);
+ int ret = cq_enqueue(hc->cq, chunk_num, sent);
if (ret < 0)
http_shutdown_client(hc, "queue error");
return ret;
goto err_out;
}
hc->status = HTTP_CONNECTED;
- cq_init(&hc->cq, MAX_BACKLOG);
+ hc->cq = cq_init(MAX_BACKLOG);
PARA_INFO_LOG("accepted client #%d: %s (fd %d)\n", numclients,
CLIENT_ADDR(hc), hc->fd);
numclients++;