#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)
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;
}
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;
}