X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=stdin.c;h=d025b949e8e8d2566abde3f2f214db7998ba44ff;hp=e5c40bcb092a1faa59a91a33bd2d7b1975f1f3e7;hb=HEAD;hpb=f167629b3191c57a6b691cd2a6af04a45a74ccb0 diff --git a/stdin.c b/stdin.c index e5c40bcb..d025b949 100644 --- a/stdin.c +++ b/stdin.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 2006 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2006 Andre Noll , see file COPYING. */ /** \file stdin.c Functions that deal with reading from stdin. */ @@ -18,10 +14,10 @@ #include "string.h" /* - * If there is space left in the buffer of the stdin task add STDIN_FILENO to - * the read fd set of s. + * If there is space left in the buffer of the stdin task, ask the scheduler to + * monitor STDIN_FILENO. */ -static void stdin_pre_select(struct sched *s, void *context) +static void stdin_pre_monitor(struct sched *s, void *context) { struct stdin_task *sit = context; int ret; @@ -32,16 +28,15 @@ static void stdin_pre_select(struct sched *s, void *context) if (ret <= 0) return; if (btr_pool_unused(sit->btrp) > 0) - return para_fd_set(STDIN_FILENO, &s->rfds, &s->max_fileno); + return sched_monitor_readfd(STDIN_FILENO, s); sched_request_timeout_ms(100, s); } /* - * This function checks if STDIN_FILENO was included by in the read fd set of s - * during the previous pre_select call. If so, and if STDIN_FILENO is readable, - * data is read from stdin and fed into the buffer tree. + * Feed data from stdin into the buffer tree if STDIN_FILENO is ready for + * reading. */ -static int stdin_post_select(struct sched *s, void *context) +static int stdin_post_monitor(__a_unused struct sched *s, void *context) { struct stdin_task *sit = context; ssize_t ret; @@ -68,7 +63,7 @@ static int stdin_post_select(struct sched *s, void *context) * reference can not be freed, we're stuck. */ sz = PARA_MIN(sz, btr_pool_size(sit->btrp) / 2); - ret = read_nonblock(STDIN_FILENO, buf, sz, &s->rfds, &n); + ret = read_nonblock(STDIN_FILENO, buf, sz, &n); if (n > 0) btr_add_output_pool(sit->btrp, n, sit->btrn); if (ret >= 0) @@ -95,8 +90,8 @@ void stdin_task_register(struct stdin_task *sit, struct sched *s) int ret; struct task_info ti = { .name = "stdin", - .pre_select = stdin_pre_select, - .post_select = stdin_post_select, + .pre_monitor = stdin_pre_monitor, + .post_monitor = stdin_post_monitor, .context = sit, }; @@ -114,6 +109,7 @@ void stdin_task_register(struct stdin_task *sit, struct sched *s) exit(EXIT_FAILURE); } sit->fd_flags = ret; - sit->must_set_nonblock_flag = (sit->fd_flags & O_NONBLOCK) == 0; + sit->must_set_nonblock_flag = (sit->fd_flags & O_NONBLOCK) == 0 + && !isatty(STDIN_FILENO); sit->task = task_register(&ti, s); }