fix dccp sender/receiver
[paraslash.git] / write_common.c
index 39f124f..dda6016 100644 (file)
@@ -37,8 +37,10 @@ static void wng_post_select(__a_unused struct sched *s, struct task *t)
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
                t->ret = wn->task.ret;
-               if (t->ret < 0)
+               if (t->ret < 0) {
+                       g->eof = 1;
                        return;
+               }
                if (!i)
                        min_written = t->ret;
                else
@@ -67,8 +69,6 @@ int wng_open(struct writer_node_group *g)
                        goto out;
                wn->chunk_bytes = ret;
                g->max_chunk_bytes = PARA_MAX(g->max_chunk_bytes, ret);
-               PARA_DEBUG_LOG("pre_select: %p\n", &wn->writer->pre_select);
-               PARA_DEBUG_LOG("post_select: %p\n", &wn->writer->post_select);
                wn->task.pre_select = wn->writer->pre_select;
                wn->task.post_select = wn->writer->post_select;
                wn->task.private_data = wn;
@@ -81,13 +81,16 @@ out:
        return ret;
 }
 
-void wng_destroy(struct writer_node_group *g)
+void wng_unregister(struct writer_node_group *g)
 {
-       if (!g)
-               return;
-       free(g->written);
-       free(g->writer_nodes);
-       free(g);
+       int i;
+
+       FOR_EACH_WRITER_NODE(i, g) {
+               struct writer_node *wn = &g->writer_nodes[i];
+               unregister_task(&wn->task);
+       }
+       unregister_task(&g->task);
+       g->eof = 1;
 }
 
 void wng_close(struct writer_node_group *g)
@@ -99,9 +102,11 @@ void wng_close(struct writer_node_group *g)
        PARA_NOTICE_LOG("closing wng with %d writer(s)\n", g->num_writers);
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
-               unregister_task(&wn->task);
                wn->writer->close(wn);
        }
+       free(g->written);
+       free(g->writer_nodes);
+       free(g);
 }
 
 struct writer_node_group *wng_new(unsigned num_writers)