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 */
31 * the pre_select function of the stdout task
33 * \param s the scheduler this task was registered to
34 * \param t the task structure of the stdout task
36 * This function is always successful. If there is data available in the input
37 * buffer, it adds \a STDOUT_FILENO to the write fd set of \a s.
39 void stdout_pre_select(struct sched
*s
, struct task
*t
)
41 struct stdout_task
*sot
= t
->private_data
;
46 if (*sot
->input_eof
) {
47 t
->ret
= -E_STDOUT_EOF
;
48 s
->timeout
.tv_sec
= 0;
49 s
->timeout
.tv_usec
= 1;
54 para_fd_set(STDOUT_FILENO
, &s
->wfds
, &s
->max_fileno
);
58 * the post select function of the stdout task
60 * \param s the scheduler this task was registered to
61 * \param t the task structure of the stdout task
63 * This function checks if \a STDOUT_FILENO was included by in the write fd set
64 * of \a s during the previous pre_select call. If yes, and STDOUT_FILENO
65 * appeears to be writable, the data loaded in the input buffer is written to
68 void stdout_post_select(struct sched
*s
, struct task
*t
)
70 struct stdout_task
*sot
= t
->private_data
;
76 t
->ret
= -E_STDOUT_EOF
;
79 if (!FD_ISSET(STDOUT_FILENO
, &s
->wfds
))
81 t
->ret
= -E_STDOUT_WRITE
;
82 ret
= write(STDOUT_FILENO
, sot
->buf
, *sot
->loaded
);
89 static void stdout_default_event_handler(struct task
*t
)
91 PARA_NOTICE_LOG("%p: %s\n", t
, PARA_STRERROR(-t
->ret
));
96 * initialize a stdout task structure with default values
98 * \param sot the stdout task structure
100 * This fills in the pre/post select function poinzters of the task structure
101 * given by \a sot. It also sets up a default error handler which unregisters
102 * the task on errors and clears the eof flag of \a sot.
104 void stdout_set_defaults(struct stdout_task
*sot
)
106 sot
->task
.private_data
= sot
;
107 sot
->task
.pre_select
= stdout_pre_select
;
108 sot
->task
.post_select
= stdout_post_select
;
109 sot
->task
.event_handler
= stdout_default_event_handler
;
111 sprintf(sot
->task
.status
, "stdout writer");