nghttp2_rcbuf.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * nghttp2 - HTTP/2 C Library
  3. *
  4. * Copyright (c) 2016 Tatsuhiro Tsujikawa
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGHTTP2_RCBUF_H
  26. #define NGHTTP2_RCBUF_H
  27. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* HAVE_CONFIG_H */
  30. #include <nghttp2/nghttp2.h>
  31. struct nghttp2_rcbuf {
  32. /* custom memory allocator belongs to the mem parameter when
  33. creating this object. */
  34. void *mem_user_data;
  35. nghttp2_free free;
  36. /* The pointer to the underlying buffer */
  37. uint8_t *base;
  38. /* Size of buffer pointed by |base|. */
  39. size_t len;
  40. /* Reference count */
  41. int32_t ref;
  42. };
  43. /*
  44. * Allocates nghttp2_rcbuf object with |size| as initial buffer size.
  45. * When the function succeeds, the reference count becomes 1.
  46. *
  47. * This function returns 0 if it succeeds, or one of the following
  48. * negative error codes:
  49. *
  50. * NGHTTP2_ERR_NOMEM:
  51. * Out of memory.
  52. */
  53. int nghttp2_rcbuf_new(nghttp2_rcbuf **rcbuf_ptr, size_t size, nghttp2_mem *mem);
  54. /*
  55. * Like nghttp2_rcbuf_new(), but initializes the buffer with |src| of
  56. * length |srclen|. This function allocates additional byte at the
  57. * end and puts '\0' into it, so that the resulting buffer could be
  58. * used as NULL-terminated string. Still (*rcbuf_ptr)->len equals to
  59. * |srclen|.
  60. *
  61. * This function returns 0 if it succeeds, or one of the following
  62. * negative error codes:
  63. *
  64. * NGHTTP2_ERR_NOMEM:
  65. * Out of memory.
  66. */
  67. int nghttp2_rcbuf_new2(nghttp2_rcbuf **rcbuf_ptr, const uint8_t *src,
  68. size_t srclen, nghttp2_mem *mem);
  69. /*
  70. * Frees |rcbuf| itself, regardless of its reference cout.
  71. */
  72. void nghttp2_rcbuf_del(nghttp2_rcbuf *rcbuf);
  73. #endif /* NGHTTP2_RCBUF_H */