]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
stdin/stdout cleanup.
authorAndre Noll <maan@systemlinux.org>
Fri, 15 Jan 2010 06:06:56 +0000 (07:06 +0100)
committerAndre Noll <maan@systemlinux.org>
Fri, 15 Jan 2010 06:06:56 +0000 (07:06 +0100)
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.

stdin.c
stdin.h
stdout.c
stdout.h

diff --git a/stdin.c b/stdin.c
index 868e1ed0e031744e1df39368ed241547e02fd836..79a9a3231d8a675c94f49ee6e0c0a98069ae6d0c 100644 (file)
--- a/stdin.c
+++ b/stdin.c
  * of \a s.
  */
 static void stdin_pre_select(struct sched *s, struct task *t)
  * 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;
 {
        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
  *
  * 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)
  */
 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;
 {
        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
  *
  * 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;
 
  */
 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;
        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);
 }
        PARA_EMERG_LOG("%s\n", para_strerror(-ret));
        exit(EXIT_FAILURE);
 }
diff --git a/stdin.h b/stdin.h
index 2b87f760d9caacc2dc69ae211016f8b85b7e141e..49fccf7c926ab0629aa19d663f29cb1c02a3d43b 100644 (file)
--- a/stdin.h
+++ b/stdin.h
@@ -8,20 +8,11 @@
 
 /** The task structure used for reading from stdin. */
 struct stdin_task {
 
 /** 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;
        /** 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;
        struct btr_node *btrn;
+       /* Use a buffer pool to minimize memcpy due to alignment problems. */
        struct btr_pool *btrp;
 };
 
        struct btr_pool *btrp;
 };
 
index 34fe08cd6a46e8305fa990988b1408f056fad191..1caa0e77023ff97d728fbe1445da8e3eb4bd5fdb 100644 (file)
--- a/stdout.c
+++ b/stdout.c
  * \param s The scheduler this task was registered to.
  * \param t The task structure of the stdout task.
  *
  * \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)
  */
 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;
 {
        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);
        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.
  *
  * \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)
  */
 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;
 {
        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
  * \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;
 
  */
 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)
        sprintf(sot->task.status, "stdout");
        ret = mark_fd_nonblocking(STDOUT_FILENO);
        if (ret >= 0)
index fee9800cbbe28a2a195ab62ec4f1bfa244dddac3..bb64e3d52ba6f11756ca35f607e732530ac2755d 100644 (file)
--- a/stdout.h
+++ b/stdout.h
@@ -4,23 +4,17 @@
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
  * 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.
 
 /**
  * The task structure used for writing to stdout.
+ *
+ * This is used by para_recv, para_filter and para_client.
  */
 struct stdout_task {
  */
 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;
        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;
 };
 
        struct btr_node *btrn;
 };