libcoap 4.3.5-develop-574332f
Loading...
Searching...
No Matches
coap_mem.c
Go to the documentation of this file.
1/* coap_mem.c -- CoAP memory handling
2 *
3 * Copyright (C) 2014--2015,2019--2026 Olaf Bergmann <bergmann@tzi.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 *
7 * This file is part of the CoAP library libcoap. Please see
8 * README for terms of use.
9 */
10
17
18#if ! (defined(WITH_LWIP) && MEMP_USE_CUSTOM_POOLS)
19#if COAP_MEMORY_TYPE_TRACK
20static int track_counts[COAP_MEM_TAG_LAST];
21static int peak_counts[COAP_MEM_TAG_LAST];
22static int fail_counts[COAP_MEM_TAG_LAST];
23#endif /* COAP_MEMORY_TYPE_TRACK */
24#endif /* ! (WITH_LWIP && MEMP_USE_CUSTOM_POOLS) */
25
26#if defined(RIOT_VERSION) && defined(MODULE_MEMARRAY)
27#include <memarray.h>
28
29#undef PACKAGE_NAME
30#undef PACKAGE_STRING
31#undef PACKAGE_TARNAME
32#undef PACKAGE_VERSION
33#include <coap3/coap_session.h>
34#undef PACKAGE_NAME
35#undef PACKAGE_STRING
36#undef PACKAGE_TARNAME
37#undef PACKAGE_VERSION
38
39#include "coap3/coap_session.h"
40#include "coap3/coap_net.h"
41#include "coap3/coap_pdu.h"
42#include "coap3/coap_resource.h"
43
48#ifndef COAP_MAX_STRING_SIZE
49#define COAP_MAX_STRING_SIZE (120U)
50#endif /* COAP_MAX_STRING_SIZE */
51
56#ifndef COAP_MAX_STRINGS
57#define COAP_MAX_STRINGS (16U)
58#endif /* COAP_MAX_STRINGS */
59
64#ifndef COAP_MAX_ENDPOINTS
65#if !COAP_DISABLE_TCP
66#define COAP_MAX_ENDPOINTS (4U)
67#else /* COAP_DISABLE_TCP */
68#define COAP_MAX_ENDPOINTS (2U)
69#endif /* COAP_DISABLE_TCP */
70#endif /* COAP_MAX_ENDPOINTS */
71
76#ifndef COAP_MAX_RESOURCES
77#define COAP_MAX_RESOURCES (8U)
78#endif /* COAP_MAX_RESOURCES */
79
84#ifndef COAP_MAX_ATTRIBUTES
85#define COAP_MAX_ATTRIBUTES \
86 ((COAP_MAX_RESOURCES) * 4U)
87#endif /* COAP_MAX_ATTRIBUTE_STRINGS */
88
95#ifndef COAP_MAX_ATTRIBUTE_STRINGS
96#define COAP_MAX_ATTRIBUTE_STRINGS (COAP_MAX_ATTRIBUTES)
97#endif /* COAP_MAX_ATTRIBUTE_STRINGS */
98
103#ifndef COAP_MAX_ATTRIBUTE_SIZE
104#define COAP_MAX_ATTRIBUTE_SIZE (16U)
105#endif /* COAP_MAX_ATTRIBUTE_SIZE */
106
111#ifndef COAP_MAX_PACKETS
112#define COAP_MAX_PACKETS (4U)
113#endif /* COAP_MAX_PACKETS */
114
119#ifndef COAP_MAX_NODES
120#define COAP_MAX_NODES (COAP_MAX_PACKETS)
121#endif /* COAP_MAX_NODES */
122
127#ifndef COAP_MAX_CONTEXTS
128#define COAP_MAX_CONTEXTS (1U)
129#endif /* COAP_MAX_CONTEXTS */
130
135#ifndef COAP_MAX_PDUS
136#define COAP_MAX_PDUS (4U)
137#endif /* COAP_MAX_PDUS */
138
143#ifndef COAP_MAX_DTLS_SESSIONS
144#define COAP_MAX_DTLS_SESSIONS (2U)
145#endif /* COAP_MAX_CONTEXTS */
146
151#ifndef COAP_MAX_SESSIONS
152#define COAP_MAX_SESSIONS (4U)
153#endif /* COAP_MAX_CONTEXTS */
154
159#ifndef COAP_MAX_OPTIONS
160#define COAP_MAX_OPTIONS (16U)
161#endif /* COAP_MAX_CONTEXTS */
162
167#ifndef COAP_MAX_OPTION_SIZE
168#define COAP_MAX_OPTION_SIZE (16U)
169#endif /* COAP_MAX_OPTION_SIZE */
170
175#ifndef COAP_MAX_CACHE_KEYS
176#define COAP_MAX_CACHE_KEYS (2U)
177#endif /* COAP_MAX_CACHE_KEYS */
178
183#ifndef COAP_MAX_CACHE_ENTRIES
184#define COAP_MAX_CACHE_ENTRIES (2U)
185#endif /* COAP_MAX_CACHE_ENTRIES */
186
191#ifndef COAP_MAX_LG_CRCVS
192#if COAP_CLIENT_SUPPORT
193#define COAP_MAX_LG_CRCVS (1U)
194#else /* ! COAP_CLIENT_SUPPORT */
195#define COAP_MAX_LG_CRCVS (0U)
196#endif /* ! COAP_CLIENT_SUPPORT */
197#endif /* COAP_MAX_LG_CRCVS */
198
203#ifndef COAP_MAX_LG_SRCVS
204#if COAP_SERVER_SUPPORT
205#define COAP_MAX_LG_SRCVS (2U)
206#else /* ! COAP_SERVER_SUPPORT */
207#define COAP_MAX_LG_SRCVS (0U)
208#endif /* ! COAP_SERVER_SUPPORT */
209#endif /* COAP_MAX_LG_SRCVS */
210
215#ifndef COAP_MAX_LG_XMITS
216#if COAP_SERVER_SUPPORT
217#define COAP_MAX_LG_XMITS (2U)
218#else /* ! COAP_SERVER_SUPPORT */
219#define COAP_MAX_LG_XMITS (1U)
220#endif /* ! COAP_SERVER_SUPPORT */
221#endif /* COAP_MAX_LG_XMITS */
222
223/* The memstr is the storage for holding coap_string_t contents. */
224struct memstr_t {
225 char buf[COAP_MAX_STRING_SIZE];
226};
227
228/* The attrstr is the storage for holding coap_string_t structures to
229 * serve as attribute names or values. As these are typically short,
230 * they are stored in a different arena than generic strings. */
231struct attrstr_t {
232 char buf[COAP_MAX_ATTRIBUTE_SIZE];
233};
234
235static struct memstr_t string_storage_data[COAP_MAX_STRINGS];
236static memarray_t string_storage;
237
238#if COAP_SERVER_SUPPORT
239static coap_endpoint_t endpoint_storage_data[COAP_MAX_ENDPOINTS];
240static memarray_t endpoint_storage;
241
242static struct attrstr_t attr_storage_data[COAP_MAX_ATTRIBUTE_STRINGS];
243static memarray_t attr_storage;
244
245static coap_attr_t resattr_storage_data[COAP_MAX_ATTRIBUTES];
246static memarray_t resattr_storage;
247#endif /* COAP_SERVER_SUPPORT */
248
249static coap_packet_t pkt_storage_data[COAP_MAX_PACKETS];
250static memarray_t pkt_storage;
251
252static coap_queue_t node_storage_data[COAP_MAX_NODES];
253static memarray_t node_storage;
254
255static coap_context_t context_storage_data[COAP_MAX_CONTEXTS];
256static memarray_t context_storage;
257
258static coap_pdu_t pdu_storage_data[COAP_MAX_PDUS];
259static memarray_t pdu_storage;
260
261/* The pdubuf is the storage for holding the (assembled) PDU data in a
262 * coap_pdu_t structure. */
263union pdubuf_t {
264 void *p; /* try to convince the compiler to word-align this structure */
266};
267
268static union pdubuf_t pdubuf_storage_data[COAP_MAX_PDUS];
269static memarray_t pdubuf_storage;
270
271#if COAP_SERVER_SUPPORT
272static coap_resource_t resource_storage_data[COAP_MAX_RESOURCES];
273static memarray_t resource_storage;
274#endif /* COAP_SERVER_SUPPORT */
275
276#if COAP_WITH_LIBTINYDTLS
277#undef PACKAGE_BUGREPORT
278#undef PACKAGE_URL
279#include <session.h>
280static session_t dtls_storage_data[COAP_MAX_DTLS_SESSIONS];
281static memarray_t dtls_storage;
282#endif /* COAP_WITH_LIBTINYDTLS */
283
284static coap_session_t session_storage_data[COAP_MAX_SESSIONS];
285static memarray_t session_storage;
286
287/* The optbuf_t is the storage for holding optlist nodes. */
288struct optbuf_t {
289 coap_optlist_t optlist;
290 char optbuf[COAP_MAX_OPTION_SIZE];
291};
292static struct optbuf_t option_storage_data[COAP_MAX_OPTIONS];
293static memarray_t option_storage;
294
295#if COAP_SERVER_SUPPORT
296static coap_cache_key_t cache_key_storage_data[COAP_MAX_CACHE_KEYS];
297static memarray_t cache_key_storage;
298
299static coap_cache_entry_t cache_entry_storage_data[COAP_MAX_CACHE_ENTRIES];
300static memarray_t cache_entry_storage;
301#endif /* COAP_SERVER_SUPPORT */
302
303#if COAP_CLIENT_SUPPORT
304static coap_lg_crcv_t cache_lg_crcv_storage_data[COAP_MAX_LG_CRCVS];
305static memarray_t cache_lg_crcv_storage;
306#endif /* COAP_CLIENT_SUPPORT */
307
308#if COAP_SERVER_SUPPORT
309static coap_lg_srcv_t cache_lg_srcv_storage_data[COAP_MAX_LG_SRCVS];
310static memarray_t cache_lg_srcv_storage;
311
312static coap_lg_xmit_t cache_lg_xmit_storage_data[COAP_MAX_LG_XMITS];
313static memarray_t cache_lg_xmit_storage;
314#endif /* COAP_SERVER_SUPPORT */
315
316#define INIT_STORAGE(Storage, Count) \
317 memarray_init(&(Storage ## _storage), (Storage ## _storage_data), sizeof(Storage ## _storage_data[0]), (Count));
318
319#define STORAGE_PTR(Storage) (&(Storage ## _storage))
320
321void
322coap_memory_init(void) {
323 INIT_STORAGE(string, COAP_MAX_STRINGS);
324#if COAP_SERVER_SUPPORT
325 INIT_STORAGE(endpoint, COAP_MAX_ENDPOINTS);
326 INIT_STORAGE(attr, COAP_MAX_ATTRIBUTE_STRINGS);
327#endif /* COAP_SERVER_SUPPORT */
328 INIT_STORAGE(pkt, COAP_MAX_PACKETS);
329 INIT_STORAGE(node, COAP_MAX_NODES);
330 INIT_STORAGE(context, COAP_MAX_CONTEXTS);
331 INIT_STORAGE(pdu, COAP_MAX_PDUS);
332 INIT_STORAGE(pdubuf, COAP_MAX_PDUS);
333#if COAP_SERVER_SUPPORT
334 INIT_STORAGE(resource, COAP_MAX_RESOURCES);
335 INIT_STORAGE(resattr, COAP_MAX_ATTRIBUTES);
336#endif /* COAP_SERVER_SUPPORT */
337#if COAP_WITH_LIBTINYDTLS
338 INIT_STORAGE(dtls, COAP_MAX_DTLS_SESSIONS);
339#endif
340 INIT_STORAGE(session, COAP_MAX_SESSIONS);
341 INIT_STORAGE(option, COAP_MAX_OPTIONS);
342#if COAP_SERVER_SUPPORT
343 INIT_STORAGE(cache_key, COAP_MAX_CACHE_KEYS);
344 INIT_STORAGE(cache_entry, COAP_MAX_CACHE_ENTRIES);
345#endif /* COAP_SERVER_SUPPORT */
346#if COAP_CLIENT_SUPPORT
347 INIT_STORAGE(cache_lg_crcv, COAP_MAX_LG_CRCVS);
348#endif /* COAP_SERVER_SUPPORT */
349#if COAP_SERVER_SUPPORT
350 INIT_STORAGE(cache_lg_srcv, COAP_MAX_LG_SRCVS);
351 INIT_STORAGE(cache_lg_xmit, COAP_MAX_LG_XMITS);
352#endif /* COAP_SERVER_SUPPORT */
353}
354
355static memarray_t *
356get_container(coap_memory_tag_t type) {
357 switch (type) {
358#if COAP_SERVER_SUPPORT
360 /* fall through */
362 return &attr_storage;
363#endif /* COAP_SERVER_SUPPORT */
364 case COAP_PACKET:
365 return &pkt_storage;
366 case COAP_NODE:
367 return &node_storage;
368 case COAP_CONTEXT:
369 return STORAGE_PTR(context);
370#if COAP_SERVER_SUPPORT
371 case COAP_ENDPOINT:
372 return &endpoint_storage;
373#endif /* COAP_SERVER_SUPPORT */
374 case COAP_PDU:
375 return &pdu_storage;
376 case COAP_PDU_BUF:
377 return &pdubuf_storage;
378#if COAP_SERVER_SUPPORT
379 case COAP_RESOURCE:
380 return &resource_storage;
382 return &resattr_storage;
383#endif /* COAP_SERVER_SUPPORT */
384#if COAP_WITH_LIBTINYDTLS
386 return &dtls_storage;
387#endif
388 case COAP_SESSION:
389 return &session_storage;
390 case COAP_OPTLIST:
391 return &option_storage;
392#if COAP_SERVER_SUPPORT
393 case COAP_CACHE_KEY:
394 return &cache_key_storage;
395 case COAP_CACHE_ENTRY:
396 return &cache_entry_storage;
397#endif /* COAP_SERVER_SUPPORT */
398#if COAP_CLIENT_SUPPORT
399 case COAP_LG_CRCV:
400 return &cache_lg_crcv_storage;
401#endif /* COAP_CLIENT_SUPPORT */
402#if COAP_SERVER_SUPPORT
403 case COAP_LG_SRCV:
404 return &cache_lg_srcv_storage;
405 case COAP_LG_XMIT:
406 return &cache_lg_xmit_storage;
407#endif /* COAP_SERVER_SUPPORT */
408 case COAP_STRING:
409 /* fall through */
410 default:
411 return &string_storage;
412 }
413}
414
415void *
416coap_malloc_type(coap_memory_tag_t type, size_t size) {
417 memarray_t *container = get_container(type);
418 void *ptr;
419 assert(container);
420
421 if (size > container->size) {
422 coap_log_warn("coap_malloc_type: Requested memory exceeds maximum object "
423 "size (type %d, size %" PRIuS ", max %" PRIdS ")\n",
424 type, size, container->size);
425 return NULL;
426 }
427
428 ptr = memarray_alloc(container);
429 if (!ptr)
430 coap_log_warn("coap_malloc_type: Failure (no free blocks) for type %d\n",
431 type);
432#if COAP_MEMORY_TYPE_TRACK
433 assert(type < COAP_MEM_TAG_LAST);
434 if (ptr) {
435 track_counts[type]++;
436 if (track_counts[type] > peak_counts[type])
437 peak_counts[type] = track_counts[type];
438 } else {
439 fail_counts[type]++;
440 }
441#endif /* COAP_MEMORY_TYPE_TRACK */
442 return ptr;
443}
444
445void
446coap_free_type(coap_memory_tag_t type, void *object) {
447#if COAP_MEMORY_TYPE_TRACK
448 assert(type < COAP_MEM_TAG_LAST);
449 if (object)
450 track_counts[type]--;
451#endif /* COAP_MEMORY_TYPE_TRACK */
452 if (object != NULL)
453 memarray_free(get_container(type), object);
454}
455
456void *
457coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
458 memarray_t *container = get_container(type);
459
460 assert(container);
461 /* The fixed container is all we have to work with */
462 if (p) {
463 if (size > container->size) {
464 coap_log_warn("coap_realloc_type: Requested memory exceeds maximum object "
465 "size (type %d, size %" PRIuS ", max %" PRIdS ")\n",
466 type, size, container->size);
467 return NULL;
468 }
469 if (size == 0) {
470 coap_free_type(type, p);
471 return NULL;
472 }
473 return p;
474 }
475 return coap_malloc_type(type, size);
476
477}
478/* End RIOT_VERSION */
479
480#elif defined(__ZEPHYR__)
481
482#include <zephyr/kernel.h>
483#include <zephyr/version.h>
484
485void
486coap_memory_init(void) {
487}
488
489void *
490coap_malloc_type(coap_memory_tag_t type, size_t size) {
491 void *ptr;
492
493 (void)type;
494 ptr = k_malloc(size);
495#if COAP_MEMORY_TYPE_TRACK
496 assert(type < COAP_MEM_TAG_LAST);
497 if (ptr) {
498 track_counts[type]++;
499 if (track_counts[type] > peak_counts[type])
500 peak_counts[type] = track_counts[type];
501 } else {
502 fail_counts[type]++;
503 }
504#endif /* COAP_MEMORY_TYPE_TRACK */
505 return ptr;
506}
507
508void *
509coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
510 void *ptr;
511
512 (void)type;
513#if KERNEL_VERSION_NUMBER >= 0x30700
514 ptr = k_realloc(p, size);
515#else /* KERNEL_VERSION_NUMBER < 0x30700 */
516 if (!p) {
517 ptr = k_malloc(size);
518 } else {
519 /* Unfortunately do not know original size of p to take a copy of it */
520 ptr = NULL;
521 }
522#endif /* KERNEL_VERSION_NUMBER < 0x30700 */
523#if COAP_MEMORY_TYPE_TRACK
524 if (ptr) {
525 assert(type < COAP_MEM_TAG_LAST);
526 if (!p)
527 track_counts[type]++;
528 if (track_counts[type] > peak_counts[type])
529 peak_counts[type] = track_counts[type];
530 } else {
531 fail_counts[type]++;
532 }
533#endif /* COAP_MEMORY_TYPE_TRACK */
534 return ptr;
535}
536
537void
538coap_free_type(coap_memory_tag_t type, void *p) {
539 (void)type;
540#if COAP_MEMORY_TYPE_TRACK
541 assert(type < COAP_MEM_TAG_LAST);
542 if (p)
543 track_counts[type]--;
544#endif /* COAP_MEMORY_TYPE_TRACK */
545 k_free(p);
546}
547/* End __ZEPHYR__ */
548
549#elif defined(WITH_LWIP) && ! MEMP_USE_CUSTOM_POOLS && ! MEM_LIBC_MALLOC
550#include <lwip/mem.h>
551
552void
553coap_memory_init(void) {
554}
555
556void *
557coap_malloc_type(coap_memory_tag_t type, size_t size) {
558 void *ptr = mem_malloc(size + sizeof(size_t));
559
560 (void)type;
561#if COAP_MEMORY_TYPE_TRACK
562 assert(type < COAP_MEM_TAG_LAST);
563 if (ptr) {
564 track_counts[type]++;
565 if (track_counts[type] > peak_counts[type])
566 peak_counts[type] = track_counts[type];
567 } else {
568 fail_counts[type]++;
569 }
570#endif /* COAP_MEMORY_TYPE_TRACK */
571 if (ptr) {
572 size_t *s_ptr = (size_t *)ptr;
573 u_char *b_ptr = (u_char *)ptr;
574
575 *s_ptr = size;
576 return b_ptr + sizeof(size_t);
577 }
578 return NULL;
579}
580
581void *
582coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
583 void *new = mem_malloc(size + sizeof(size_t));
584
585 (void)type;
586#if COAP_MEMORY_TYPE_TRACK
587 if (new) {
588 assert(type < COAP_MEM_TAG_LAST);
589 if (!p)
590 track_counts[type]++;
591 if (track_counts[type] > peak_counts[type])
592 peak_counts[type] = track_counts[type];
593 } else {
594 fail_counts[type]++;
595 }
596#endif /* COAP_MEMORY_TYPE_TRACK */
597 if (new) {
598 size_t *s_ptr = (size_t *)new;
599 u_char *b_ptr = (u_char *)new;
600
601 *s_ptr = size;
602 if (p) {
603 size_t *o_ptr = (size_t *)p;
604
605 o_ptr--;
606 memcpy(b_ptr + sizeof(size_t), p, *o_ptr);
607 }
608 return b_ptr + sizeof(size_t);
609 }
610 return NULL;
611}
612
613void
614coap_free_type(coap_memory_tag_t type, void *p) {
615 u_char *ptr = (u_char *)p;
616
617 (void)type;
618#if COAP_MEMORY_TYPE_TRACK
619 assert(type < COAP_MEM_TAG_LAST);
620 if (p)
621 track_counts[type]--;
622#endif /* COAP_MEMORY_TYPE_TRACK */
623 if (ptr) {
624 mem_free(ptr - sizeof(size_t));
625 }
626}
627/* Enf of WITH_LWIP && ! MEMP_USE_CUSTOM_POOLS && | MEM_LIBC_MALLOC */
628
629#elif defined(HAVE_MALLOC) || defined(__MINGW32__)
630#include <stdlib.h>
631
632void
633coap_memory_init(void) {
634}
635
636void *
637coap_malloc_type(coap_memory_tag_t type, size_t size) {
638 void *ptr;
639
640 (void)type;
641 ptr = malloc(size);
642#if COAP_MEMORY_TYPE_TRACK
643 assert(type < COAP_MEM_TAG_LAST);
644 if (ptr) {
645 track_counts[type]++;
646 if (track_counts[type] > peak_counts[type])
647 peak_counts[type] = track_counts[type];
648 } else {
649 fail_counts[type]++;
650 }
651#endif /* COAP_MEMORY_TYPE_TRACK */
652 return ptr;
653}
654
655void *
656coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
657 void *ptr;
658
659 (void)type;
660 ptr = realloc(p, size);
661#if COAP_MEMORY_TYPE_TRACK
662 if (ptr) {
663 assert(type < COAP_MEM_TAG_LAST);
664 if (!p)
665 track_counts[type]++;
666 if (track_counts[type] > peak_counts[type])
667 peak_counts[type] = track_counts[type];
668 } else {
669 fail_counts[type]++;
670 }
671#endif /* COAP_MEMORY_TYPE_TRACK */
672 return ptr;
673}
674
675void
676coap_free_type(coap_memory_tag_t type, void *p) {
677 (void)type;
678#if COAP_MEMORY_TYPE_TRACK
679 assert(type < COAP_MEM_TAG_LAST);
680 if (p)
681 track_counts[type]--;
682#endif /* COAP_MEMORY_TYPE_TRACK */
683 free(p);
684}
685
686/* End of HAVE_MALLOC || __MINGW32__ */
687
688#elif WITH_CONTIKI
689#include "lib/heapmem.h"
690
691void
692coap_memory_init(void) {
693}
694
695void *
696coap_malloc_type(coap_memory_tag_t type, size_t size) {
697 void *ptr = heapmem_alloc(size);
698
699#if COAP_MEMORY_TYPE_TRACK
700 assert(type < COAP_MEM_TAG_LAST);
701 if (ptr) {
702 track_counts[type]++;
703 if (track_counts[type] > peak_counts[type])
704 peak_counts[type] = track_counts[type];
705 } else {
706 fail_counts[type]++;
707 }
708#endif /* COAP_MEMORY_TYPE_TRACK */
709 return ptr;
710}
711
712void *
713coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
714 void *ptr = heapmem_realloc(p, size);
715#if COAP_MEMORY_TYPE_TRACK
716 if (ptr) {
717 assert(type < COAP_MEM_TAG_LAST);
718 if (!p)
719 track_counts[type]++;
720 if (track_counts[type] > peak_counts[type])
721 peak_counts[type] = track_counts[type];
722 } else {
723 fail_counts[type]++;
724 }
725#endif /* COAP_MEMORY_TYPE_TRACK */
726 return ptr;
727}
728
729void
730coap_free_type(coap_memory_tag_t type, void *ptr) {
731#if COAP_MEMORY_TYPE_TRACK
732 assert(type < COAP_MEM_TAG_LAST);
733 if (ptr)
734 track_counts[type]--;
735#endif /* COAP_MEMORY_TYPE_TRACK */
736 if (ptr)
737 heapmem_free(ptr);
738}
739
740#endif /* WITH_CONTIKI */
741
742#if ! (defined(WITH_LWIP) && MEMP_USE_CUSTOM_POOLS)
743#define MAKE_CASE(n) case n: name = #n; break
744void
746#if COAP_MEMORY_TYPE_TRACK
747 int i;
748
749 coap_log(level, "* Memory type counts\n");
750 for (i = 0; i < COAP_MEM_TAG_LAST; i++) {
751 const char *name = "?";
752
753
754 switch (i) {
785 default:
786 break;
787 }
788 coap_log(level, "* %-20s in-use %3d peak %3d failed %2d\n",
789 name, track_counts[i], peak_counts[i], fail_counts[i]);
790 }
791#else /* COAP_MEMORY_TYPE_TRACK */
792 (void)level;
793#endif /* COAP_MEMORY_TYPE_TRACK */
794}
795#endif /* ! (WITH_LWIP && MEMP_USE_CUSTOM_POOLS */
struct coap_lg_crcv_t coap_lg_crcv_t
struct coap_cache_key_t coap_cache_key_t
struct coap_endpoint_t coap_endpoint_t
struct coap_cache_entry_t coap_cache_entry_t
struct coap_attr_t coap_attr_t
struct coap_resource_t coap_resource_t
struct coap_lg_srcv_t coap_lg_srcv_t
#define PRIuS
#define PRIdS
Library specific build wrapper for coap_internal.h.
#define MAKE_CASE(n)
Definition coap_mem.c:743
void coap_dump_memory_type_counts(coap_log_t level)
Dumps the current usage of malloc'd memory types.
Definition coap_mem.c:745
void coap_memory_init(void)
Initializes libcoap's memory management.
coap_memory_tag_t
Type specifiers for coap_malloc_type().
Definition coap_mem.h:32
@ COAP_DTLS_SESSION
Definition coap_mem.h:44
@ COAP_SESSION
Definition coap_mem.h:45
@ COAP_CACHE_KEY
Definition coap_mem.h:47
@ COAP_DIGEST_CTX
Definition coap_mem.h:52
@ COAP_NODE
Definition coap_mem.h:37
@ COAP_OSCORE_COM
Definition coap_mem.h:55
@ COAP_DTLS_CONTEXT
Definition coap_mem.h:54
@ COAP_OSCORE_EX
Definition coap_mem.h:58
@ COAP_CACHE_ENTRY
Definition coap_mem.h:48
@ COAP_RESOURCE
Definition coap_mem.h:42
@ COAP_RESOURCEATTR
Definition coap_mem.h:43
@ COAP_COSE
Definition coap_mem.h:61
@ COAP_LG_XMIT
Definition coap_mem.h:49
@ COAP_ATTRIBUTE_VALUE
Definition coap_mem.h:35
@ COAP_ENDPOINT
Definition coap_mem.h:39
@ COAP_CONTEXT
Definition coap_mem.h:38
@ COAP_OPTLIST
Definition coap_mem.h:46
@ COAP_PDU
Definition coap_mem.h:40
@ COAP_LG_CRCV
Definition coap_mem.h:50
@ COAP_OSCORE_BUF
Definition coap_mem.h:60
@ COAP_MEM_TAG_LAST
Definition coap_mem.h:62
@ COAP_OSCORE_SEN
Definition coap_mem.h:56
@ COAP_OSCORE_REC
Definition coap_mem.h:57
@ COAP_ATTRIBUTE_NAME
Definition coap_mem.h:34
@ COAP_OSCORE_EP
Definition coap_mem.h:59
@ COAP_LG_SRCV
Definition coap_mem.h:51
@ COAP_PACKET
Definition coap_mem.h:36
@ COAP_SUBSCRIPTION
Definition coap_mem.h:53
@ COAP_STRING
Definition coap_mem.h:33
@ COAP_PDU_BUF
Definition coap_mem.h:41
void * coap_realloc_type(coap_memory_tag_t type, void *p, size_t size)
Reallocates a chunk p of bytes created by coap_malloc_type() or coap_realloc_type() and returns a poi...
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
CoAP context interface.
#define NULL
Definition coap_option.h:30
Pre-defined constants that reflect defaults for CoAP.
Generic resource handling.
Defines the application visible session information.
coap_log_t
Logging type.
Definition coap_debug.h:56
#define coap_log_warn(...)
Definition coap_debug.h:108
#define coap_log(level,...)
Logging function.
Definition coap_debug.h:290
#define COAP_DEFAULT_MAX_PDU_RX_SIZE
The CoAP stack's global state is stored in a coap_context_t object.
Structure to hold large body (many blocks) transmission information.
Representation of chained list of CoAP options to install.
structure for CoAP PDUs
Queue entry.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...