stdout: Try to write as much as possible in one go.
authorAndre Noll <maan@systemlinux.org>
Sun, 10 Jan 2010 18:49:58 +0000 (19:49 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 10 Jan 2010 18:49:58 +0000 (19:49 +0100)
stdout.c

index 16e1646..34fe08c 100644 (file)
--- a/stdout.c
+++ b/stdout.c
@@ -106,20 +106,24 @@ static void stdout_post_select_btr(struct sched *s, struct task *t)
        t->error = 0;
        ret = btr_node_status(btrn, 0, BTR_NT_LEAF);
        if (ret < 0)
-               goto err;
+               goto out;
        if (ret == 0)
                return;
        if (!FD_ISSET(STDOUT_FILENO, &s->wfds))
                return;
-       sz = btr_next_buffer(btrn, &buf);
-       assert(sz > 0);
-       ret = write_nonblock(STDOUT_FILENO, buf, sz, 0);
+
+       for (;;) {
+               sz = btr_next_buffer(btrn, &buf);
+               if (sz == 0)
+                       break;
+               ret = write_nonblock(STDOUT_FILENO, buf, sz, 0);
+               if (ret <= 0)
+                       break;
+               btr_consume(btrn, ret);
+       }
+out:
        if (ret < 0)
-               goto err;
-       btr_consume(btrn, ret);
-       return;
-err:
-       btr_remove_node(btrn);
+               btr_remove_node(btrn);
        t->error = ret;
 }
 /**
@@ -127,7 +131,7 @@ err:
  *
  * \param sot The stdout task structure.
  *
- * This fills in the pre/post select function poinzters of the task structure
+ * This fills in the pre/post select function pointers of the task structure
  * given by \a sot.
  */
 void stdout_set_defaults(struct stdout_task *sot)
@@ -141,7 +145,7 @@ void stdout_set_defaults(struct stdout_task *sot)
                sot->task.pre_select = stdout_pre_select;
                sot->task.post_select = stdout_post_select;
        }
-       sprintf(sot->task.status, "stdout writer");
+       sprintf(sot->task.status, "stdout");
        ret = mark_fd_nonblocking(STDOUT_FILENO);
        if (ret >= 0)
                return;