mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-27 01:07:10 +03:00
coap_pdu.c: Support incrementing reference count on const coap_pdu_t parameters
const coap_pdu_t * parameters are passed into application (call-back handler) code. If the application code then calls a libcoap API with a const coap_pdu_t * parameter, it is not possible to increment the reference counter so that multiple entities can reference the same PDU and an entity's call to coap_delete_pdu() does not prematurely remove the PDU until all the entities have finished. This code allows the (const) PDU's reference counter to be incremented.
This commit is contained in:
1 parent
84778a7bb4
commit
72691daec2
2 files changed
+31
No files matched your search
@@ -1626,3 +1626,16 @@ coap_pdu_reference_lkd(coap_pdu_t *pdu) {
|
||||
}
|
||||
return pdu;
|
||||
}
|
||||
|
||||
coap_pdu_t *
|
||||
coap_const_pdu_reference_lkd(const coap_pdu_t *pdu) {
|
||||
coap_pdu_t *pdu_rw = NULL;
|
||||
|
||||
if (pdu != NULL) {
|
||||
|
||||
/* Need to do this to not get a compiler warning about const parameters */
|
||||
memcpy(&pdu_rw, &pdu, sizeof(pdu_rw));
|
||||
++pdu_rw->ref;
|
||||
}
|
||||
return pdu_rw;
|
||||
}
|
||||
Reference in new issue
Block a user