+ 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);
+ ssize_t ret;
+ size_t sz = btr_get_input_queue_size(sot->btrn);
+ char *buf;
+
+ t->error = 0;
+ if (!sot->check_fd) {
+ if (sz == 0 && btr_no_parent(sot->btrn)) {
+ t->error = -E_ORPHAN;
+ goto err;
+ }
+ return;
+ }
+ if (!FD_ISSET(STDOUT_FILENO, &s->wfds))
+ return;
+ sz = btr_next_buffer(sot->btrn, &buf);
+ if (sz == 0)
+ return;
+ ret = write_nonblock(STDOUT_FILENO, buf, sz, 0);
+ if (ret < 0) {
+ t->error = -ERRNO_TO_PARA_ERROR(errno);
+ goto err;
+ }
+ btr_consume(sot->btrn, ret);
+ return;
+err:
+ btr_del_node(sot->btrn);
+}
+/**
+ * Initialize a stdout task structure with default values.
+ *
+ * \param sot The stdout task structure.
+ *
+ * This fills in the pre/post select function poinzters of the task structure
+ * given by \a sot.
+ */
+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;
+ }
+ sprintf(sot->task.status, "stdout writer");
+ ret = mark_fd_nonblocking(STDOUT_FILENO);
+ if (ret >= 0)
+ return;
+ PARA_EMERG_LOG("%s\n", para_strerror(-ret));
+ exit(EXIT_FAILURE);