From 65d6f677cb6f79c69b8b35c5b3fe6aa337dbfb23 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 13 Jan 2010 02:17:30 +0100 Subject: [PATCH] Add btr support for the dccp receiver. --- dccp_recv.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/dccp_recv.c b/dccp_recv.c index a5a648b9..85842248 100644 --- a/dccp_recv.c +++ b/dccp_recv.c @@ -24,6 +24,7 @@ #include "string.h" #include "net.h" #include "fd.h" +#include "buffer_tree.h" #include "dccp_recv.cmdline.h" @@ -38,6 +39,7 @@ struct private_dccp_recv_data { /** the file descriptor for the dccp socket */ int fd; + struct btr_pool *btrp; }; @@ -80,6 +82,7 @@ static int dccp_recv_open(struct receiver_node *rn) goto err; rn->buf = para_calloc(DCCP_BUFSIZE); rn->private_data = pdd = para_calloc(sizeof(struct private_dccp_recv_data)); + pdd->btrp = btr_pool_new("dccp_recv", 320 * 1024); pdd->fd = fd; return 1; err: @@ -102,6 +105,9 @@ static void dccp_recv_pre_select(struct sched *s, struct task *t) struct receiver_node *rn = container_of(t, struct receiver_node, task); struct private_dccp_recv_data *pdd = rn->private_data; + if (rn->btrn) + if (generic_recv_pre_select(s, t) <= 0) + return; t->error = 0; para_fd_set(pdd->fd, &s->rfds, &s->max_fileno); } @@ -110,10 +116,20 @@ static void dccp_recv_post_select(struct sched *s, struct task *t) { struct receiver_node *rn = container_of(t, struct receiver_node, task); struct private_dccp_recv_data *pdd = rn->private_data; - - if (rn->output_error && *rn->output_error < 0) { - t->error = *rn->output_error; - return; + struct btr_node *btrn = rn->btrn; + int ret; + + if (btrn) { + ret = btr_node_status(btrn, 0, BTR_NT_ROOT); + if (ret < 0) + goto err; + if (ret == 0) + return; + } else { + if (rn->output_error && *rn->output_error < 0) { + t->error = *rn->output_error; + return; + } } if (!FD_ISSET(pdd->fd, &s->rfds)) return; /* nothing to do */ @@ -121,6 +137,24 @@ static void dccp_recv_post_select(struct sched *s, struct task *t) t->error = -E_DCCP_OVERRUN; return; } + if (btrn) { + char *buf; + size_t sz; + + sz = btr_pool_get_buffer(pdd->btrp, &buf); + ret = -E_DCCP_OVERRUN; + if (sz == 0) + goto err; + //buf = para_malloc(HTTP_RECV_READ_BUF_SIZE); + //sz = HTTP_RECV_READ_BUF_SIZE; + ret = recv_bin_buffer(pdd->fd, buf, sz); + if (ret == 0) + ret = -E_RECV_EOF; + if (ret < 0) + goto err; + btr_add_output_pool(pdd->btrp, ret, btrn); + return; + } t->error = recv_bin_buffer(pdd->fd, rn->buf + rn->loaded, DCCP_BUFSIZE - rn->loaded); if (t->error > 0) { @@ -129,6 +163,11 @@ static void dccp_recv_post_select(struct sched *s, struct task *t) } if (!t->error) t->error = -E_RECV_EOF; + return; +err: + if (btrn) + btr_remove_node(rn->btrn); + t->error = ret; } static void dccp_recv_free_config(void *conf) -- 2.39.2