send_common: Combine generic_com_on() and open_sender().
[paraslash.git] / vss.c
diff --git a/vss.c b/vss.c
index 6aac9d5..f69225e 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -997,7 +997,7 @@ static void recv_afs_result(struct vss_task *vsst, fd_set *rfds)
                goto err;
        }
        ret = para_mmap(statbuf.st_size, PROT_READ, MAP_PRIVATE | MAP_POPULATE,
-               passed_fd, 0, &vsst->map);
+               passed_fd, &vsst->map);
        if (ret < 0)
                goto err;
        vsst->mapsize = statbuf.st_size;
@@ -1034,6 +1034,8 @@ static void vss_send(struct vss_task *vsst)
        bool fec_active = false;
        struct timeval due;
        struct fec_client *fc, *tmp_fc;
+       char *buf;
+       size_t len;
 
        if (!vsst->map || !vss_playing())
                return;
@@ -1064,35 +1066,31 @@ static void vss_send(struct vss_task *vsst)
        }
        compute_chunk_time(mmd->chunks_sent, &mmd->afd.afhi.chunk_tv,
                &mmd->stream_start, &due);
-       if (tv_diff(&due, now, NULL) <= 0) {
-               char *buf;
-               size_t len;
-
-               if (!mmd->chunks_sent) {
-                       mmd->stream_start = *now;
-                       mmd->events++;
-                       set_mmd_offset();
-               }
-               ret = vss_get_chunk(mmd->current_chunk, vsst, &buf, &len);
-               if (ret < 0) {
-                       PARA_ERROR_LOG("could not get chunk %lu: %s\n",
-                               mmd->current_chunk, para_strerror(-ret));
-               } else {
-                       /*
-                        * We call ->send() even if len is zero because senders
-                        * might have data queued which can be sent now.
-                        */
-                       for (i = 0; senders[i].name; i++) {
-                               if (!senders[i].send)
-                                       continue;
-                               senders[i].send(mmd->current_chunk,
-                                       mmd->chunks_sent, buf, len,
-                                       vsst->header_buf, vsst->header_len);
-                       }
+       if (tv_diff(&due, now, NULL) > 0)
+               return;
+       if (!mmd->chunks_sent) {
+               mmd->stream_start = *now;
+               mmd->events++;
+               set_mmd_offset();
+       }
+       ret = vss_get_chunk(mmd->current_chunk, vsst, &buf, &len);
+       if (ret < 0) {
+               PARA_ERROR_LOG("could not get chunk %lu: %s\n",
+                       mmd->current_chunk, para_strerror(-ret));
+       } else {
+               /*
+                * We call ->send() even if len is zero because senders might
+                * have data queued which can be sent now.
+                */
+               for (i = 0; senders[i].name; i++) {
+                       if (!senders[i].send)
+                               continue;
+                       senders[i].send(mmd->current_chunk, mmd->chunks_sent,
+                               buf, len, vsst->header_buf, vsst->header_len);
                }
-               mmd->chunks_sent++;
-               mmd->current_chunk++;
        }
+       mmd->chunks_sent++;
+       mmd->current_chunk++;
 }
 
 static int vss_post_select(struct sched *s, void *context)
@@ -1196,7 +1194,7 @@ void vss_init(int afs_socket, struct sched *s)
                        &vsst->data_send_barrier);
        }
        vsst->task = task_register(&(struct task_info) {
-               .name = "vss task",
+               .name = "vss",
                .pre_select = vss_pre_select,
                .post_select = vss_post_select,
                .context = vsst,