- 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;
- }
+ FOR_EACH_WRITER_NODE(i, g) {
+ struct writer_node *wn = &g->writer_nodes[i];
+ struct writer *w = writers + wn->writer_num;
+ t->error = w->post_select(s, wn);
+ if (t->error < 0)
+ return;
+ if (!i)
+ min_written = wn->written;
+ else
+ min_written = PARA_MIN(min_written, wn->written);
+ }
+ //PARA_INFO_LOG("loaded: %zd, min_written: %zd bytes\n", *g->loaded, min_written);
+ if (min_written) {
+ *g->loaded -= min_written;
+ FOR_EACH_WRITER_NODE(i, g)
+ g->writer_nodes[i].written -= min_written;
+ }
+ if (!*g->loaded && *g->input_error) {
+ t->error = *g->input_error;
+ return;
+ }
+ if (*g->loaded && min_written) {
+// PARA_INFO_LOG("moving %zd bytes\n", *g->loaded);
+ memmove(*g->bufp, *g->bufp + min_written, *g->loaded);