nghttp2_rcbuf.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2015-2018 Alibaba Group Holding Limited
  3. */
  4. #ifndef NGHTTP2_RCBUF_H
  5. #define NGHTTP2_RCBUF_H
  6. #ifdef HAVE_CONFIG_H
  7. #include <config.h>
  8. #endif /* HAVE_CONFIG_H */
  9. #include "nghttp2.h"
  10. struct nghttp2_rcbuf {
  11. /* custom memory allocator belongs to the mem parameter when
  12. creating this object. */
  13. void *mem_user_data;
  14. nghttp2_free free;
  15. /* The pointer to the underlying buffer */
  16. uint8_t *base;
  17. /* Size of buffer pointed by |base|. */
  18. size_t len;
  19. /* Reference count */
  20. int32_t ref;
  21. };
  22. /*
  23. * Allocates nghttp2_rcbuf object with |size| as initial buffer size.
  24. * When the function succeeds, the reference count becomes 1.
  25. *
  26. * This function returns 0 if it succeeds, or one of the following
  27. * negative error codes:
  28. *
  29. * NGHTTP2_ERR_NOMEM:
  30. * Out of memory.
  31. */
  32. int nghttp2_rcbuf_new(nghttp2_rcbuf **rcbuf_ptr, size_t size, nghttp2_mem *mem);
  33. /*
  34. * Like nghttp2_rcbuf_new(), but initializes the buffer with |src| of
  35. * length |srclen|. This function allocates additional byte at the
  36. * end and puts '\0' into it, so that the resulting buffer could be
  37. * used as NULL-terminated string. Still (*rcbuf_ptr)->len equals to
  38. * |srclen|.
  39. *
  40. * This function returns 0 if it succeeds, or one of the following
  41. * negative error codes:
  42. *
  43. * NGHTTP2_ERR_NOMEM:
  44. * Out of memory.
  45. */
  46. int nghttp2_rcbuf_new2(nghttp2_rcbuf **rcbuf_ptr, const uint8_t *src,
  47. size_t srclen, nghttp2_mem *mem);
  48. /*
  49. * Frees |rcbuf| itself, regardless of its reference cout.
  50. */
  51. void nghttp2_rcbuf_del(nghttp2_rcbuf *rcbuf);
  52. #endif /* NGHTTP2_RCBUF_H */