struct timeval diff;
t->ret = 0;
- if (wng->eof && *wng->loaded < pad->bytes_per_frame)
+ if (*wng->eof && *wng->loaded < pad->bytes_per_frame)
return;
t->ret = 1;
if (*wng->loaded < pad->bytes_per_frame)
return;
if (tv_diff(&s->now, &pad->next_chunk, &diff) < 0) {
- if (tv_diff(&s->timeout, &diff, NULL) < 0)
+ if (tv_diff(&s->timeout, &diff, NULL) > 0)
s->timeout = diff;
} else {
s->timeout.tv_sec = 0;
unsigned char *data = (unsigned char*)wng->buf;
t->ret = 0;
- if (!frames)
+ if (!frames) {
+ if (*wng->eof)
+ t->ret = *wng->loaded;
return;
+ }
if (tv_diff(&s->now, &pad->next_chunk, NULL) < 0)
return;
// PARA_INFO_LOG("%zd frames\n", frames);
ret = read(STDIN_FILENO, sit->buf + sit->loaded, sit->bufsize - sit->loaded);
if (ret < 0)
t->ret = -E_STDIN_READ;
- else {
+ else if (ret > 0) {
sit->loaded += ret;
t->ret = ret;
- }
+ } else
+ t->ret = 0;
+ if (ret <= 0)
+ sit->eof = 1;
sprintf(t->status,
"%p stdin reader: loaded = %d, ret = %d",
sit, sit->loaded, t->ret);
}
-
-#if 0
-void stdin_init(struct stdin_task *sit)
-{
- sit->task.private_data = sit;
- sit->task.pre_select = stdin_pre_select;
- sit->task.post_select = stdin_post_select;
- sit->task.flags = POST_EOF_IS_ERROR;
- sprintf(sit->task.status, "%p stdin reader: initialized", &sit->task);
-}
-#endif
const char *writer_names[] ={WRITER_NAMES};
struct writer writers[NUM_SUPPORTED_WRITERS] = {WRITER_ARRAY};
-int wng_write(struct writer_node_group *g, char *buf, size_t *loaded)
-{
- int ret, i, need_more_writes = 1;
- size_t min_written = 0;
-
- while (need_more_writes) {
- need_more_writes = 0;
- FOR_EACH_WRITER_NODE(i, g) {
- size_t w = g->written[i];
- int bytes_to_write;
- struct writer_node *wn = &g->writer_nodes[i];
- if (!i)
- min_written = w;
- else
- min_written = PARA_MIN(min_written, w);
- if (w == *loaded)
- continue;
- if (!g->eof && (*loaded < wn->chunk_bytes + w))
- continue;
- bytes_to_write = PARA_MIN(wn->chunk_bytes,
- *loaded - w);
- ret = wn->writer->write(buf + w, bytes_to_write, wn);
- if (ret < 0)
- goto out;
- if (ret != bytes_to_write)
- PARA_WARNING_LOG("short write: %d/%d\n", ret,
- bytes_to_write);
- g->written[i] += ret;
- need_more_writes = 1;
- }
- }
- *loaded -= min_written;
- ret = 0;
- if (g->eof)
- goto out;
- if (*loaded)
- memmove(buf, buf + min_written, *loaded);
- FOR_EACH_WRITER_NODE(i, g)
- g->written[i] -= min_written;
- ret = 1;
-out:
- return ret;
-}
-
static void wng_post_select(struct sched *s, struct task *t)
{
struct writer_node_group *g = t->private_data;
min_written = PARA_MIN(min_written, t->ret);
}
*g->loaded -= min_written;
- if (!*g->loaded && g->eof)
+ if (!*g->loaded && *g->eof)
t->ret = 0;
else
t->ret = 1;
wn->task.pre_select = wn->writer->pre_select;
wn->task.post_select = wn->writer->post_select;
wn->task.private_data = wn;
+ wn->task.flags = POST_EOF_IS_ERROR;
register_task(&wn->task);
}
register_task(&g->task);