From: Andre Noll Date: Fri, 15 Jan 2010 06:06:56 +0000 (+0100) Subject: stdin/stdout cleanup. X-Git-Tag: v0.4.2~92 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=47abdd7c11a8e58df82a13470553cf5683e61a00;p=paraslash.git stdin/stdout cleanup. para_client was the last user of the non-btr code in stdin.[ch] and stdout.[ch]. Remove this unused code and update the documentation. --- diff --git a/stdin.c b/stdin.c index 868e1ed0..79a9a323 100644 --- a/stdin.c +++ b/stdin.c @@ -31,22 +31,6 @@ * of \a s. */ static void stdin_pre_select(struct sched *s, struct task *t) -{ - struct stdin_task *sit = container_of(t, struct stdin_task, task); - - if (sit->output_error && *sit->output_error < 0) { - t->error = *sit->output_error; - return; - } - t->error = 0; - sit->check_fd = 0; - if (sit->loaded >= sit->bufsize) - return; - sit->check_fd = 1; - para_fd_set(STDIN_FILENO, &s->rfds, &s->max_fileno); -} - -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; @@ -70,33 +54,10 @@ static void stdin_pre_select_btr(struct sched *s, struct task *t) * * This function checks if \p STDIN_FILENO was included by in the read fd set * of \a s during the previous pre_select call. If yes, and \p STDIN_FILENO - * appears to be readable, data is read from stdin into the buffer of the - * stdin task. + * appears to be readable, data is read from stdin and fed into the buffer + * tree. */ static void stdin_post_select(struct sched *s, struct task *t) -{ - struct stdin_task *sit = container_of(t, struct stdin_task, task); - ssize_t ret; - - if (sit->output_error && *sit->output_error < 0) { - t->error = *sit->output_error; - return; - } - t->error = 0; - if (!sit->check_fd) - return; - if (!FD_ISSET(STDIN_FILENO, &s->rfds)) - return; - ret = read(STDIN_FILENO, sit->buf + sit->loaded, sit->bufsize - sit->loaded); - if (ret < 0) - t->error = ERRNO_TO_PARA_ERROR(errno); - else if (ret > 0) - sit->loaded += ret; - else - t->error = -E_STDIN_EOF; -} - -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; @@ -142,26 +103,19 @@ err: * * This fills in the pre/post select function pointers of the task structure * given by \a sit. Moreover, the stdin file desctiptor is set to nonblocking - * mode and \a bufsize is initialized (but no buffer is allocated). + * mode, and a buffer tree is created. */ void stdin_set_defaults(struct stdin_task *sit) { int ret; - sit->bufsize = 32 * 1024; - if (sit->btrn) { - sit->task.pre_select = stdin_pre_select_btr; - sit->task.post_select = stdin_post_select_btr; - sit->btrp = btr_pool_new("stdin", 64 * 1024); - } else { - sit->task.pre_select = stdin_pre_select; - sit->task.post_select = stdin_post_select; - } + sit->task.pre_select = stdin_pre_select; + sit->task.post_select = stdin_post_select; + sit->btrp = btr_pool_new("stdin", 64 * 1024); sprintf(sit->task.status, "stdin reader"); ret = mark_fd_nonblocking(STDIN_FILENO); if (ret >= 0) return; - sit->output_error = NULL; PARA_EMERG_LOG("%s\n", para_strerror(-ret)); exit(EXIT_FAILURE); } diff --git a/stdin.h b/stdin.h index 2b87f760..49fccf7c 100644 --- a/stdin.h +++ b/stdin.h @@ -8,20 +8,11 @@ /** The task structure used for reading from stdin. */ struct stdin_task { - /** Input buffer. */ - char *buf; - /** The size of \a buf. */ - size_t bufsize; - /** Number of bytes currently loaded in \a buf. */ - size_t loaded; - /** Pointer to the error member of the consumer. */ - int *output_error; - /** Whether \p STDIN_FILENO was included in the read fd set. */ - int check_fd; /** The task structure. */ struct task task; - /** Non-null if buffer tree API should be used. */ + /** Stdin is always the root of a buffer tree. */ struct btr_node *btrn; + /* Use a buffer pool to minimize memcpy due to alignment problems. */ struct btr_pool *btrp; }; diff --git a/stdout.c b/stdout.c index 34fe08cd..1caa0e77 100644 --- a/stdout.c +++ b/stdout.c @@ -24,41 +24,20 @@ * \param s The scheduler this task was registered to. * \param t The task structure of the stdout task. * - * This function is always successful. If there is data available in the input - * buffer, it adds \p STDOUT_FILENO to the write fd set of \a s. + * This function is always successful. If there is input data available, it + * adds \p STDOUT_FILENO to the write fd set of \a s. */ static void stdout_pre_select(struct sched *s, struct task *t) -{ - struct stdout_task *sot = container_of(t, struct stdout_task, task); - - t->error = 0; - sot->check_fd = 0; - if (!*sot->loaded) { - if (*sot->input_error < 0) { - t->error = *sot->input_error; - s->timeout.tv_sec = 0; - s->timeout.tv_usec = 1; - } - return; - } - sot->check_fd = 1; - para_fd_set(STDOUT_FILENO, &s->wfds, &s->max_fileno); -} - -static void stdout_pre_select_btr(struct sched *s, struct task *t) { struct stdout_task *sot = container_of(t, struct stdout_task, task); int ret; t->error = 0; - sot->check_fd = 0; ret = btr_node_status(sot->btrn, 0, BTR_NT_LEAF); if (ret > 0) para_fd_set(STDOUT_FILENO, &s->wfds, &s->max_fileno); - else if (ret < 0) { - s->timeout.tv_sec = 0; - s->timeout.tv_usec = 1; - } + else if (ret < 0) + sched_min_delay(s); } /** @@ -67,35 +46,10 @@ static void stdout_pre_select_btr(struct sched *s, struct task *t) * \param s The scheduler this task was registered to. * \param t The task structure of the stdout task. * - * This function checks if \p STDOUT_FILENO was included by in the write fd set - * of \a s during the previous pre_select call. If yes, and \p STDOUT_FILENO - * appeears to be writable, the data loaded in the input buffer is written to - * stdout. + * This function writes input data from the buffer tree to stdout if \p + * STDOUT_FILENO is writable. */ static void stdout_post_select(struct sched *s, struct task *t) -{ - struct stdout_task *sot = container_of(t, struct stdout_task, task); - ssize_t ret; - - t->error = 0; - if (!sot->check_fd) { - if (!*sot->loaded && *sot->input_error < 0) - t->error = *sot->input_error; - return; - } - if (!FD_ISSET(STDOUT_FILENO, &s->wfds)) - return; - ret = write(STDOUT_FILENO, *sot->bufp, *sot->loaded); - if (ret < 0) { - t->error = -ERRNO_TO_PARA_ERROR(errno); - return; - } - *sot->loaded -= ret; - if (*sot->loaded) - memmove(*sot->bufp, *sot->bufp + ret, *sot->loaded); -} - -static void stdout_post_select_btr(struct sched *s, struct task *t) { struct stdout_task *sot = container_of(t, struct stdout_task, task); struct btr_node *btrn = sot->btrn; @@ -132,19 +86,14 @@ out: * \param sot The stdout task structure. * * This fills in the pre/post select function pointers of the task structure - * given by \a sot. + * given by \a sot and sets the stdout file descriptor to nonblocking mode. */ void stdout_set_defaults(struct stdout_task *sot) { int ret; - if (sot->btrn) { - sot->task.pre_select = stdout_pre_select_btr; - sot->task.post_select = stdout_post_select_btr; - } else { - sot->task.pre_select = stdout_pre_select; - sot->task.post_select = stdout_post_select; - } + sot->task.pre_select = stdout_pre_select; + sot->task.post_select = stdout_post_select; sprintf(sot->task.status, "stdout"); ret = mark_fd_nonblocking(STDOUT_FILENO); if (ret >= 0) diff --git a/stdout.h b/stdout.h index fee9800c..bb64e3d5 100644 --- a/stdout.h +++ b/stdout.h @@ -4,23 +4,17 @@ * Licensed under the GPL v2. For licencing details see COPYING. */ -/** \file stdout.h The standard out task structure. */ +/** \file stdout.h Writing to stdout via buffer trees. */ /** * The task structure used for writing to stdout. + * + * This is used by para_recv, para_filter and para_client. */ struct stdout_task { - /** Pointer to the data buffer pointer. */ - char **bufp; - /** Number of bytes loaded in \a buf. */ - size_t *loaded; - /** Pointer to the error variable of the feeding task. */ - int *input_error; - /** The task structure. */ + /** The task structure used by the scheduler. */ struct task task; - /** Whether \p STDOUT_FILENO was included in the write fd set. */ - int check_fd; - /** Non-null if buffer tree API should be used. */ + /** Stdout is always a leaf node in the buffer tree. */ struct btr_node *btrn; };