From: Andre Noll Date: Mon, 28 Dec 2009 21:51:59 +0000 (+0100) Subject: http_recv: Add buffer tree support. X-Git-Tag: v0.4.2~249 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=8bb9f71c3b9e8e6d3087f186addbb966bcd1f946 http_recv: Add buffer tree support. --- diff --git a/http_recv.c b/http_recv.c index 13e9ede2..b1d3f5f3 100644 --- a/http_recv.c +++ b/http_recv.c @@ -21,6 +21,7 @@ #include "net.h" #include "string.h" #include "fd.h" +#include "buffer_tree.h" /** the output buffer size of the http receiver */ #define BUFSIZE (32 * 1024) @@ -96,11 +97,14 @@ static void http_recv_pre_select(struct sched *s, struct task *t) para_fd_set(phd->fd, &s->rfds, &s->max_fileno); } +#define HTTP_RECV_MAX_PENDING (1024 * 1024) +#define HTTP_RECV_READ_BUF_SIZE 4096 static void http_recv_post_select(struct sched *s, struct task *t) { struct receiver_node *rn = container_of(t, struct receiver_node, task); struct private_http_recv_data *phd = rn->private_data; + struct http_recv_args_info *conf = rn->conf; if (rn->output_error && *rn->output_error < 0) { t->error = *rn->output_error; @@ -128,17 +132,29 @@ static void http_recv_post_select(struct sched *s, struct task *t) } return; } - if (rn->loaded >= BUFSIZE) { - t->error = -E_HTTP_RECV_OVERRUN; + if (conf->buffer_tree_given) { + char *buf; + if (btr_bytes_pending(rn->btr_root) > HTTP_RECV_MAX_PENDING) { + t->error = -E_HTTP_RECV_OVERRUN; + return; + } + buf = para_malloc(HTTP_RECV_READ_BUF_SIZE); + t->error = recv_bin_buffer(phd->fd, buf, HTTP_RECV_READ_BUF_SIZE); + if (t->error == 0) + t->error = -E_RECV_EOF; + if (t->error < 0) { + free(buf); + return; + } + btr_add_output(buf, t->error, rn->btr_root); return; } + t->error = -E_HTTP_RECV_OVERRUN; + if (rn->loaded >= BUFSIZE) + return; t->error = recv_bin_buffer(phd->fd, rn->buf + rn->loaded, BUFSIZE - rn->loaded); - if (t->error > 0) { - rn->loaded += t->error; - return; - } - if (!t->error) + if (t->error == 0) t->error = -E_RECV_EOF; }