]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - stdin.c
aacdec: Reset "consumed" at each iteration.
[paraslash.git] / stdin.c
diff --git a/stdin.c b/stdin.c
index d978ee9a23cc7fe6f47eab17e7f46ac78032ceaf..abe69cafd4270ddf0e82ed9d2b30d3cf3603f43a 100644 (file)
--- a/stdin.c
+++ b/stdin.c
@@ -46,24 +46,18 @@ static void stdin_pre_select(struct sched *s, struct task *t)
        para_fd_set(STDIN_FILENO, &s->rfds, &s->max_fileno);
 }
 
-#define STDIN_MAX_PENDING (100 * 1024)
-
 static void stdin_pre_select_btr(struct sched *s, struct task *t)
 {
        struct stdin_task *sit = container_of(t, struct stdin_task, task);
+       int ret;
 
-       if (btr_no_children(sit->btrn)) { /* TODO: defer node deletion to post select */
-               t->error = -E_STDIN_NO_CHILD;
-               btr_del_node(sit->btrn);
-               sit->btrn = NULL;
-               return;
-       }
        t->error = 0;
-       if (btr_bytes_pending(sit->btrn) > STDIN_MAX_PENDING)
-               sit->check_fd = 0;
-       else {
-               sit->check_fd = 1;
+       ret = btr_node_status(sit->btrn, 0, BTR_NT_ROOT);
+       if (ret > 0)
                para_fd_set(STDIN_FILENO, &s->rfds, &s->max_fileno);
+       else if (ret < 0) {
+               s->timeout.tv_sec = 0;
+               s->timeout.tv_usec = 1;
        }
 }
 
@@ -101,38 +95,37 @@ static void stdin_post_select(struct sched *s, struct task *t)
                t->error = -E_STDIN_EOF;
 }
 
-#define STDIN_INPUT_BUFFER_SIZE 4000
+#define STDIN_INPUT_BUFFER_SIZE (1024 * 32)
 static void stdin_post_select_btr(struct sched *s, struct task *t)
 {
        struct stdin_task *sit = container_of(t, struct stdin_task, task);
        ssize_t ret;
        char *buf = NULL;
 
-       t->error = -E_STDIN_NO_CHILD;
-       if (btr_no_children(sit->btrn))
-               goto err;
-
        t->error = 0;
-       if (!sit->check_fd)
+       ret = btr_node_status(sit->btrn, 0, BTR_NT_ROOT);
+       if (ret < 0)
+               goto err;
+       if (ret == 0)
                return;
        if (!FD_ISSET(STDIN_FILENO, &s->rfds))
                return;
-
        buf = para_malloc(STDIN_INPUT_BUFFER_SIZE);
        ret = read(STDIN_FILENO, buf, STDIN_INPUT_BUFFER_SIZE);
        //PARA_CRIT_LOG("read ret: %d\n", ret);
-       if (ret < 0)
-               t->error = -ERRNO_TO_PARA_ERROR(errno);
-       if (ret == 0)
-               t->error = -E_STDIN_EOF;
-       if (t->error < 0)
+       if (ret <= 0) {
+               if (ret < 0)
+                       ret = -ERRNO_TO_PARA_ERROR(errno);
+               else
+                       ret = -E_STDIN_EOF;
                goto err;
+       }
        btr_add_output(buf, ret, sit->btrn);
        return;
 err:
        free(buf);
-       btr_del_node(sit->btrn);
-       sit->btrn = NULL;
+       btr_remove_node(sit->btrn);
+       t->error = ret;
 }
 
 /**