From: Andre Noll Date: Sun, 12 Aug 2007 16:47:50 +0000 (+0200) Subject: struct http_client: Use a _pointer_ to the chunk_queue. X-Git-Tag: v0.2.17~30 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=28ca8e57ce76f5496f0d1ba143ec2c1c725bc90a struct http_client: Use a _pointer_ to the chunk_queue. This way, http_send.c no longer needs to know the size of struct chunk_queue(). Allocation of the proper struct is now done in cq_init(). --- diff --git a/http_send.c b/http_send.c index 65b6c5a2..1f28f722 100644 --- a/http_send.c +++ b/http_send.c @@ -72,7 +72,7 @@ struct http_client { /** 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; }; /** @@ -172,11 +172,13 @@ int cq_get(struct queued_chunk *qc, char **buf, size_t *len) 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) @@ -186,6 +188,7 @@ 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) @@ -195,7 +198,7 @@ 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); } @@ -232,7 +235,7 @@ static int http_send_err_msg(struct http_client *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); @@ -242,10 +245,10 @@ static int send_queued_chunks(struct http_client *hc) 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; } @@ -253,7 +256,7 @@ static int send_queued_chunks(struct http_client *hc) 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; @@ -380,7 +383,7 @@ static void http_post_select(fd_set *rfds, fd_set *wfds) 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++;