- PARA_DEBUG_LOG("timeout: %lums\n", tv2ms(&timeout));
- ret = select(max + 1, &rfds, &wfds, NULL, &timeout);
- if (ret < 0) {
- if (errno == EINTR || errno == EAGAIN)
- goto recv;
- ret = -E_RECV_SELECT;
- goto out;
- }
- ret = r->post_select(&rn, ret, &rfds, &wfds);
- if (ret < 0)
- goto out;
- if (!ret)
- eof = 1;
- if (!rn.loaded) {
- if (eof)
- goto out;
- goto recv;
- }
- ret = write(STDOUT_FILENO, rn.buf, rn.loaded);
- PARA_DEBUG_LOG("wrote %d/%zd\n", ret, rn.loaded);
- if (ret < 0) {
- ret = -E_WRITE_STDOUT;
- goto out;
- }
- if (ret != rn.loaded) {
- PARA_INFO_LOG("short write %d/%zd\n", ret, rn.loaded);
- memmove(rn.buf, rn.buf + ret, rn.loaded - ret);
- }
- rn.loaded -= ret;
- if (rn.loaded || !eof)
- goto recv;
+ stdout_set_defaults(&sot);
+ sot.buf = rn.buf;
+ sot.loaded = &rn.loaded;
+ sot.input_error = &rn.error;
+ register_task(&sot.task);
+
+ rn.task.private_data = &rn;
+ rn.task.pre_select = r->pre_select;
+ rn.task.post_select = r->post_select;
+ rn.task.event_handler = rn_event_handler;
+ sprintf(rn.task.status, "receiver node");
+ register_task(&rn.task);
+
+ ret = schedule(&s);