summaryrefslogtreecommitdiffstats
path: root/src/packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/packet.c')
-rw-r--r--src/packet.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/packet.c b/src/packet.c
new file mode 100644
index 00000000..086e4b2a
--- /dev/null
+++ b/src/packet.c
@@ -0,0 +1,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);
+}