X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=stdin.c;h=abe69cafd4270ddf0e82ed9d2b30d3cf3603f43a;hp=d080e2165b169ec3fd03bf0c669ac6ec05188985;hb=fc65f69bcfca74994e837adebdbbc16117ee77e2;hpb=aa05cb41dd2f031935507e89b56b1e6096b846db diff --git a/stdin.c b/stdin.c index d080e216..abe69caf 100644 --- 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 (1024 * 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)) { - 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,37 +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); - if (ret < 0) - t->error = -ERRNO_TO_PARA_ERROR(errno); - if (ret == 0) - t->error = -E_STDIN_EOF; - if (t->error < 0) + //PARA_CRIT_LOG("read ret: %d\n", ret); + 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; } /**