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