X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=stdin.c;h=abe69cafd4270ddf0e82ed9d2b30d3cf3603f43a;hp=079865f7ac982bbcdf8103a5418e58a0d05e25b2;hb=fc65f69bcfca74994e837adebdbbc16117ee77e2;hpb=aa234b7afe223879a7bd7274ce05a3a315a2ec49 diff --git a/stdin.c b/stdin.c index 079865f7..abe69caf 100644 --- a/stdin.c +++ b/stdin.c @@ -46,18 +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; 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; } } @@ -102,30 +102,30 @@ static void stdin_post_select_btr(struct sched *s, struct task *t) 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_remove_node(sit->btrn); + t->error = ret; } /**