]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - http_send.c
struct http_client: Use a _pointer_ to the chunk_queue.
[paraslash.git] / http_send.c
index 65b6c5a2ebee3b518a5383acd45273ce696a629c..1f28f722952b2b235e2e509c5b9b03f9a3e769dc 100644 (file)
@@ -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++;