X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=http_recv.c;h=bedd989ee1f364a751f9e21069f8f2a95c434b94;hp=7a751e4acbc846bf3feb81e22448f90ec1389002;hb=ebc3f5891079568a0b0e120e1504170bd6000f78;hpb=33a282ec9378ca6b2d0707c6e9642a3e6b625cb4 diff --git a/http_recv.c b/http_recv.c index 7a751e4a..bedd989e 100644 --- a/http_recv.c +++ b/http_recv.c @@ -6,6 +6,7 @@ /** \file http_recv.c paraslash's http receiver */ +#include #include #include @@ -20,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) @@ -95,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; @@ -127,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)