From b8d55024bee48c614003a62a716ff8af92861d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 29 May 2019 13:33:16 +0300 Subject: Protocol: updated tutorial. --- include/protocol.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index 387424f..7bfb275 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -23,8 +23,8 @@ #if 0 - How do we use this API(?), I hear you say. Well, here is a self-contained - example complete with tedious comments: +How do we use this API(?), I hear you say. Well, here is a self-contained +example complete with tedious comments, allocation of buffers and cleanup: ------------------------------------------------------------------------------- 1 | void functy_the_function(void) @@ -46,13 +46,18 @@ 19 | udp_push(packet, packet_size); /* Push packet via UDP */ 20 | udp_flush(); /* Flush to the other side*/ 21 | - 22 | tlv_destroy(&text); /* Free text tlv */ - 23 | tlv_destroy(&tlv_packet); /* Free tlv_packet */ - 24 | free(packet); /* Free packet itself */ - 25 | return; /* GTFO and save stack space */ - 26 | } + 22 | tlv_destroy(&tlv_packet); /* Free tlv_packet */ + 23 | free(packet); /* Free packet itself */ + 24 | return; /* GTFO and save stack space */ + 25 | } ------------------------------------------------------------------------------- +A few things to note: + * Calling tlv_destroy() on a tlv of type REGURAL or HEARTBEAT destorys + all sub-tlv's too. + * Tlv's get copies of data, which means the original buffer can be + freed immediately. + #endif -- cgit v1.2.3