]> git.tue.mpg.de Git - paraslash.git/commitdiff
Add btr support for the dccp receiver.
authorAndre Noll <maan@systemlinux.org>
Wed, 13 Jan 2010 01:17:30 +0000 (02:17 +0100)
committerAndre Noll <maan@systemlinux.org>
Wed, 13 Jan 2010 01:17:30 +0000 (02:17 +0100)
dccp_recv.c

index a5a648b98831a435b60745679892430d6269e383..85842248a97999b60824a267ed1180e0a8dafe0c 100644 (file)
@@ -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)