first version of the universal paraslash scheduler
[paraslash.git] / stdin.c
1 #include "para.h"
2 #include "string.h"
3 #include "list.h"
4 #include "sched.h"
5 #include "fd.h"
6 #include "error.h"
7 #include "stdin.h"
8
9 void stdin_pre_select(struct sched *s, struct task *t)
10 {
11 struct stdin_task *sit = t->private_data;
12 if (sit->loaded < sit->bufsize)
13 para_fd_set(STDIN_FILENO, &s->rfds, &s->max_fileno);
14 t->ret = 1; /* success */
15 }
16
17 void stdin_post_select(struct sched *s, struct task *t)
18 {
19 struct stdin_task *sit = t->private_data;
20 ssize_t ret;
21
22 t->ret = 1;
23 if (sit->loaded >= sit->bufsize)
24 return;
25 if (!FD_ISSET(STDIN_FILENO, &s->rfds))
26 return;
27 ret = read(STDIN_FILENO, sit->buf + sit->loaded, sit->bufsize - sit->loaded);
28 if (ret < 0)
29 t->ret = -E_STDIN_READ;
30 else {
31 sit->loaded += ret;
32 t->ret = ret;
33 }
34 sprintf(t->status,
35 "%p stdin reader: loaded = %d, ret = %d",
36 sit, sit->loaded, t->ret);
37 }
38
39 #if 0
40 void stdin_init(struct stdin_task *sit)
41 {
42 sit->task.private_data = sit;
43 sit->task.pre_select = stdin_pre_select;
44 sit->task.post_select = stdin_post_select;
45 sit->task.flags = POST_EOF_IS_ERROR;
46 sprintf(sit->task.status, "%p stdin reader: initialized", &sit->task);
47 }
48 #endif