summaryrefslogtreecommitdiffstats
path: root/src/packet.c
blob: 086e4b2a80dc184658f1bebdd417b5d0c00d5b14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <assert.h>
#include <stdlib.h>

#include "packet.h"

struct packet* packet_new(uint32_t length) {
    struct packet *p;
    assert(length);
    p = malloc(sizeof(struct packet)+length);
    assert(p);

    p->ref = 1;
    p->length = length;
    return p;
}

struct packet* packet_ref(struct packet *p) {
    assert(p && p->ref >= 1);
    p->ref++;
    return p;
}

void packet_unref(struct packet *p) {
    assert(p && p->ref >= 1);
    p->ref--;

    if (p->ref == 0)
        free(p);
}