server: Move ->size from mmd to struct vss_task.
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 21 Dec 2016 12:58:28 +0000 (13:58 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 25 Mar 2017 10:54:36 +0000 (11:54 +0100)
This field stores the size of the memory mapping of the current audio
file, if any. No command handler ever changes the value, and the
value is not read from com_stat(), so there is no reason for ->size
to be part of the mmd shared memory area.

Unlike ->size, the pointer to the mapping is stored in struct vss_task.
Given that vss.c is the only file which reads ->map or ->size, it
makes sense to store both values together in the vss task struct.

server.h
vss.c

index 8de691ca321bd49db2d7c25398537f31b7d03a0c..7f276ab92edb4d06d312fc1c1c12f0003b7ae9ac 100644 (file)
--- a/server.h
+++ b/server.h
@@ -48,8 +48,6 @@ struct sender_command_data {
  * propagate to the stat command handlers.
  */
 struct misc_meta_data {
-       /** The size of the current audio file in bytes. */
-       size_t size;
        /** The "old" status flags -- commands may only read them. */
        unsigned int vss_status_flags;
        /** The new status flags -- commands may set them. */
diff --git a/vss.c b/vss.c
index 5484db9d9479401fe90e481f842c37a9afed8e4f..792a7393c443590f06ebe469ee95c789c5947278 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -88,6 +88,8 @@ struct vss_task {
        enum afs_socket_status afsss;
        /** The memory mapped audio file. */
        char *map;
+       /** The size of the memory mapping. */
+       size_t mapsize;
        /** Used by the scheduler. */
        struct task *task;
        /** Pointer to the header of the mapped audio file. */
@@ -846,7 +848,7 @@ static void vss_eof(struct vss_task *vsst)
        set_eof_barrier(vsst);
        afh_free_header(vsst->header_buf, mmd->afd.audio_format_id);
        vsst->header_buf = NULL;
-       para_munmap(vsst->map, mmd->size);
+       para_munmap(vsst->map, vsst->mapsize);
        vsst->map = NULL;
        mmd->chunks_sent = 0;
        //mmd->offset = 0;
@@ -855,7 +857,7 @@ static void vss_eof(struct vss_task *vsst)
        mmd->afd.afhi.chunk_tv.tv_usec = 0;
        free(mmd->afd.afhi.chunk_table);
        mmd->afd.afhi.chunk_table = NULL;
-       mmd->size = 0;
+       vsst->mapsize = 0;
        mmd->events++;
 }
 
@@ -973,11 +975,11 @@ static void recv_afs_result(struct vss_task *vsst, fd_set *rfds)
                ret = -ERRNO_TO_PARA_ERROR(errno);
                goto err;
        }
-       mmd->size = statbuf.st_size;
-       ret = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE | MAP_POPULATE,
+       ret = para_mmap(statbuf.st_size, PROT_READ, MAP_PRIVATE | MAP_POPULATE,
                passed_fd, 0, &vsst->map);
        if (ret < 0)
                goto err;
+       vsst->mapsize = statbuf.st_size;
        close(passed_fd);
        mmd->chunks_sent = 0;
        mmd->current_chunk = 0;
@@ -986,7 +988,7 @@ static void recv_afs_result(struct vss_task *vsst, fd_set *rfds)
        mmd->num_played++;
        mmd->new_vss_status_flags &= (~VSS_NEXT);
        afh_get_header(&mmd->afd.afhi, mmd->afd.audio_format_id,
-               vsst->map, mmd->size, &vsst->header_buf, &vsst->header_len);
+               vsst->map, vsst->mapsize, &vsst->header_buf, &vsst->header_len);
        return;
 err:
        free(mmd->afd.afhi.chunk_table);
@@ -1076,7 +1078,7 @@ static void vss_send(struct vss_task *vsst)
                 */
                if (mmd->current_chunk > 0) { /* chunk 0 might be on the heap */
                        buf += len;
-                       for (i = 0; i < 5 && buf < vsst->map + mmd->size; i++) {
+                       for (i = 0; i < 5 && buf < vsst->map + vsst->mapsize; i++) {
                                __a_unused volatile char x = *buf;
                                buf += 4096;
                        }