X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=http_recv.c;h=bedd989ee1f364a751f9e21069f8f2a95c434b94;hp=13e9ede23d4d3cda0dcea71fbeef9dc0602dbd6f;hb=ebc3f5891079568a0b0e120e1504170bd6000f78;hpb=ad6c68022eea0b0962855a2120cf242446bf10b9 diff --git a/http_recv.c b/http_recv.c index 13e9ede2..bedd989e 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,18 +132,33 @@ 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->btrn) > 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->btrn); 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; + if (t->error < 0) + return; + rn->loaded += t->error; } static void http_recv_close(struct receiver_node *rn)