convert para_audiod to the new scheduler.
[paraslash.git] / stdin.c
diff --git a/stdin.c b/stdin.c
index cecdcb7..22f1dd9 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 */
 }
 
+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;
@@ -27,22 +33,24 @@ void stdin_post_select(struct sched *s, struct task *t)
        ret = read(STDIN_FILENO, sit->buf + sit->loaded, sit->bufsize - sit->loaded);
        if (ret < 0)
                t->ret = -E_STDIN_READ;
-       else {
+       else if (ret > 0) {
                sit->loaded += ret;
                t->ret = ret;
-       }
-       sprintf(t->status,
-               "%p stdin reader: loaded = %d, ret = %d",
-               sit, sit->loaded, t->ret);
+       } else
+               t->ret = -E_STDIN_EOF;
+       if (t->ret < 0)
+               sit->eof = 1;
 }
 
-#if 0
-void stdin_init(struct stdin_task *sit)
+void stdin_set_defaults(struct stdin_task *sit)
 {
-       sit->task.private_data = 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.flags = POST_EOF_IS_ERROR;
-       sprintf(sit->task.status, "%p stdin reader: initialized", &sit->task);
+       sit->task.event_handler = stdin_default_event_handler;
+       sit->task.private_data = sit;
+       sprintf(sit->task.status, "stdin reader");
 }
-#endif