common_public.h 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. #ifndef MQTT_WEBSOCKETS_COMMON_PUBLIC_H
  2. #define MQTT_WEBSOCKETS_COMMON_PUBLIC_H
  3. #include <stddef.h>
  4. /* free_fnc_t in general (in whatever function or struct it is used)
  5. * decides how the related data will be handled.
  6. * - If NULL the data are copied internally (causing malloc and later free)
  7. * - If pointer provided the free function pointed will be called when data are no longer needed
  8. * to free associated memory. This is effectively transfering ownership of that pointer to the library.
  9. * This also allows caller to provide custom free function other than system one.
  10. * - If == CALLER_RESPONSIBILITY the library will not copy the data pointed to and will not call free
  11. * at the end. This is usefull to avoid copying memory (and associated malloc/free) when data are for
  12. * example static. In this case caller has to guarantee the memory pointed to will be valid for entire duration
  13. * it is needed. For example by freeing the data after PUBACK is received or by data being static.
  14. */
  15. typedef void (*free_fnc_t)(void *ptr);
  16. void _caller_responsibility(void *ptr);
  17. #define CALLER_RESPONSIBILITY ((free_fnc_t)&_caller_responsibility)
  18. struct mqtt_ng_stats {
  19. size_t tx_bytes_queued;
  20. int tx_messages_queued;
  21. int tx_messages_sent;
  22. int rx_messages_rcvd;
  23. size_t tx_buffer_used;
  24. size_t tx_buffer_free;
  25. size_t tx_buffer_size;
  26. // part of transaction buffer that containes mesages we can free alredy during the garbage colleciton step
  27. size_t tx_buffer_reclaimable;
  28. };
  29. #endif /* MQTT_WEBSOCKETS_COMMON_PUBLIC_H */