2 * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file stdout.c functions that deal with writing to stdout */
30 * the pre_select function of the stdout task
32 * \param s the scheduler this task was registered to
33 * \param t the task structure of the stdout task
35 * This function is always successful. If there is data available in the input
36 * buffer, it adds \p STDOUT_FILENO to the write fd set of \a s.
38 void stdout_pre_select(struct sched
*s
, struct task
*t
)
40 struct stdout_task
*sot
= t
->private_data
;
45 if (*sot
->input_eof
) {
46 t
->ret
= -E_STDOUT_EOF
;
47 s
->timeout
.tv_sec
= 0;
48 s
->timeout
.tv_usec
= 1;
53 para_fd_set(STDOUT_FILENO
, &s
->wfds
, &s
->max_fileno
);
57 * the post select function of the stdout task
59 * \param s the scheduler this task was registered to
60 * \param t the task structure of the stdout task
62 * This function checks if \p STDOUT_FILENO was included by in the write fd set
63 * of \a s during the previous pre_select call. If yes, and \p STDOUT_FILENO
64 * appeears to be writable, the data loaded in the input buffer is written to
67 void stdout_post_select(struct sched
*s
, struct task
*t
)
69 struct stdout_task
*sot
= t
->private_data
;
75 t
->ret
= -E_STDOUT_EOF
;
78 if (!FD_ISSET(STDOUT_FILENO
, &s
->wfds
))
80 t
->ret
= -E_STDOUT_WRITE
;
81 ret
= write(STDOUT_FILENO
, sot
->buf
, *sot
->loaded
);
88 static void stdout_default_event_handler(struct task
*t
)
90 PARA_NOTICE_LOG("%p: %s\n", t
, PARA_STRERROR(-t
->ret
));
95 * initialize a stdout task structure with default values
97 * \param sot the stdout task structure
99 * This fills in the pre/post select function poinzters of the task structure
100 * given by \a sot. It also sets up a default error handler which unregisters
101 * the task on errors and clears the eof flag of \a sot.
103 void stdout_set_defaults(struct stdout_task
*sot
)
105 sot
->task
.private_data
= sot
;
106 sot
->task
.pre_select
= stdout_pre_select
;
107 sot
->task
.post_select
= stdout_post_select
;
108 sot
->task
.event_handler
= stdout_default_event_handler
;
110 sprintf(sot
->task
.status
, "stdout writer");