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
37 * available in the input buffer, it adds the STDOUT_FILENO
38 * to the write fd set of \a s.
40 void stdout_pre_select(struct sched
*s
, struct task
*t
)
42 struct stdout_task
*sot
= t
->private_data
;
47 if (*sot
->input_eof
) {
48 t
->ret
= -E_STDOUT_EOF
;
49 s
->timeout
.tv_sec
= 0;
50 s
->timeout
.tv_usec
= 1;
55 para_fd_set(STDOUT_FILENO
, &s
->wfds
, &s
->max_fileno
);
59 * the post select function of the stdout task
61 * \param s the scheduler this task was registered to
62 * \param t the task structure of the stdout task
64 * This function checks if STDOUT_FILENO was included by in the write fd set of
65 * \a s during the previous pre_select call. If yes, and STDOUT_FILENO appeears
66 * to be writable, the data loaded in the input buffer is written to stdout.
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
101 * structure given by \a sot. It also sets up a default error handler
102 * which unregisteres the task on errors and clears the eof flag of
105 void stdout_set_defaults(struct stdout_task
*sot
)
107 sot
->task
.private_data
= sot
;
108 sot
->task
.pre_select
= stdout_pre_select
;
109 sot
->task
.post_select
= stdout_post_select
;
110 sot
->task
.event_handler
= stdout_default_event_handler
;
112 sprintf(sot
->task
.status
, "stdout writer");