Merge branch 'sched'
[paraslash.git] / stdin.c
diff --git a/stdin.c b/stdin.c
index 6b9c80988b365c76fe77e8a470004e2398739d5f..22f1dd97b2bb6b18d028b890dd6b73eab73fa567 100644 (file)
--- a/stdin.c
+++ b/stdin.c
@@ -14,6 +14,12 @@ void stdin_pre_select(struct sched *s, struct task *t)
        t->ret = 1; /* success */
 }
 
        t->ret = 1; /* success */
 }
 
+static void stdin_default_event_handler(struct task *t)
+{
+       PARA_NOTICE_LOG("%p: %s\n", t, PARA_STRERROR(-t->ret));
+       unregister_task(t);
+}
+
 void stdin_post_select(struct sched *s, struct task *t)
 {
        struct stdin_task *sit = t->private_data;
 void stdin_post_select(struct sched *s, struct task *t)
 {
        struct stdin_task *sit = t->private_data;
@@ -31,10 +37,20 @@ void stdin_post_select(struct sched *s, struct task *t)
                sit->loaded += ret;
                t->ret = ret;
        } else
                sit->loaded += ret;
                t->ret = ret;
        } else
-               t->ret = 0;
-       if (ret <= 0)
+               t->ret = -E_STDIN_EOF;
+       if (t->ret < 0)
                sit->eof = 1;
                sit->eof = 1;
-       sprintf(t->status,
-               "%p stdin reader: loaded = %d, ret = %d",
-               sit, sit->loaded, t->ret);
+}
+
+void stdin_set_defaults(struct stdin_task *sit)
+{
+       sit->bufsize = 16 * 1024,
+       sit->loaded = 0,
+       sit->eof = 0,
+       sit->task.flags = 0,
+       sit->task.pre_select = stdin_pre_select;
+       sit->task.post_select = stdin_post_select;
+       sit->task.event_handler = stdin_default_event_handler;
+       sit->task.private_data = sit;
+       sprintf(sit->task.status, "stdin reader");
 }
 }