cleaner.c 1.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <unistd.h>
#include "../socket.h"
#include"../../util/dbg.h"
#include "cleaner.h"

void *cleanup(void *ptr)
{
    PrrtSocket *socket = ptr;
    while(1) {
        if(socket->isSender) {

        } else {
            if(socket->packetTimeoutTable != NULL) {
                List *expired_packets = PrrtPacketTimeoutTable_expire_packets(socket->packetTimeoutTable,
                                                                              PrrtClock_get_prrt_time_us(
                                                                                      socket->clock));
                if(List_count(expired_packets) > 0) {
                    PrrtPacket *first = List_first(expired_packets);
19
                    prrtSequenceNumber_t firstSequenceNumberBase = first->sequenceNumber - first->index - SEQNO_SPACE/4;
20 21 22 23 24 25 26

                    PrrtPacket *last = List_last(expired_packets);
                    prrtSequenceNumber_t lastSequenceNumberBase = last->sequenceNumber - last->index - 1;

                    PrrtRepairBlockStore_expire_block_range(socket->repairBlockStore, firstSequenceNumberBase,
                                                            lastSequenceNumberBase);

27 28 29
                    List *list = List_create();
                    PrrtDataPacketStore_remove_range(socket->dataPacketStore, list, firstSequenceNumberBase, last->sequenceNumber);
                    List_destroy(list);
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

                    while(List_count(expired_packets) > 0) {
                        PrrtPacket* packet = (PrrtPacket*) List_shift(expired_packets);
                        PrrtPacket_destroy(packet);
                    }

                }
                List_destroy(expired_packets);
            }
        }

        usleep(1000000);
    }

    return NULL;
}