]> git.tuebingen.mpg.de Git - paraslash.git/blob - stdout.c
83703055c83c54edc9a7e17b050f3ca2d076c61e
[paraslash.git] / stdout.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 "stdout.h"
8
9 void stdout_pre_select(struct sched *s, struct task *t)
10 {
11         struct stdout_task *sot = t->private_data;
12
13         t->ret = 1;
14         sot->check_fd = 0;
15         if (!*sot->loaded)
16                 return;
17         sot->check_fd = 1;
18         para_fd_set(STDOUT_FILENO, &s->wfds, &s->max_fileno);
19 }
20
21 void stdout_post_select(struct sched *s, struct task *t)
22 {
23         struct stdout_task *sot = t->private_data;
24         ssize_t ret;
25
26         t->ret = 1;
27         if (!sot->check_fd) {
28                 if (*sot->eof)
29                         t->ret = -E_STDOUT_EOF;
30                 return;
31         }
32         if (!FD_ISSET(STDOUT_FILENO, &s->wfds))
33                 return;
34         t->ret = -E_STDOUT_WRITE;
35         ret = write(STDOUT_FILENO, sot->buf, *sot->loaded);
36         if (ret <= 0)
37                 return;
38         *sot->loaded -= ret;
39         t->ret = 1;
40 }