+ /*
+ * Do not use the maximal size to avoid having only a single buffer
+ * reference for the whole pool. This is bad because if that single
+ * 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);
+ if (n > 0)
+ btr_add_output_pool(sit->btrp, n, sit->btrn);
+ if (ret >= 0)
+ return;
+err:
+ btr_remove_node(&sit->btrn);
+ //btr_pool_free(sit->btrp);
+ t->error = ret;
+}
+
+/**
+ * Initialize a stdin task structure with default values.
+ *
+ * \param sit The stdin task structure.
+ *
+ * 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 buffer tree is created.
+ */
+void stdin_set_defaults(struct stdin_task *sit)
+{
+ int ret;
+
+ sit->task.pre_select = stdin_pre_select;
+ sit->task.post_select = stdin_post_select;
+ sit->btrp = btr_pool_new("stdin", 128 * 1024);
+ sprintf(sit->task.status, "stdin reader");
+ ret = mark_fd_nonblocking(STDIN_FILENO);
+ if (ret >= 0)
+ return;
+ PARA_EMERG_LOG("%s\n", para_strerror(-ret));
+ exit(EXIT_FAILURE);