nghttp3_gaptr.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * nghttp3
  3. *
  4. * Copyright (c) 2019 nghttp3 contributors
  5. * Copyright (c) 2017 ngtcp2 contributors
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. #ifndef NGHTTP3_GAPTR_H
  27. #define NGHTTP3_GAPTR_H
  28. #ifdef HAVE_CONFIG_H
  29. # include <config.h>
  30. #endif /* defined(HAVE_CONFIG_H) */
  31. #include <nghttp3/nghttp3.h>
  32. #include "nghttp3_mem.h"
  33. #include "nghttp3_ksl.h"
  34. #include "nghttp3_range.h"
  35. /*
  36. * nghttp3_gaptr maintains the gap in the range [0, UINT64_MAX).
  37. */
  38. typedef struct nghttp3_gaptr {
  39. /* gap maintains the range of offset which is not pushed
  40. yet. Initially, its range is [0, UINT64_MAX). "gap" is the range
  41. that is not pushed yet. */
  42. nghttp3_ksl gap;
  43. /* mem is custom memory allocator */
  44. const nghttp3_mem *mem;
  45. } nghttp3_gaptr;
  46. /*
  47. * nghttp3_gaptr_init initializes |gaptr|.
  48. */
  49. void nghttp3_gaptr_init(nghttp3_gaptr *gaptr, const nghttp3_mem *mem);
  50. /*
  51. * nghttp3_gaptr_free frees resources allocated for |gaptr|.
  52. */
  53. void nghttp3_gaptr_free(nghttp3_gaptr *gaptr);
  54. /*
  55. * nghttp3_gaptr_push pushes the range [offset, offset + datalen).
  56. *
  57. * This function returns 0 if it succeeds, or one of the following
  58. * negative error codes:
  59. *
  60. * NGHTTP3_ERR_NOMEM
  61. * Out of memory
  62. */
  63. int nghttp3_gaptr_push(nghttp3_gaptr *gaptr, uint64_t offset, uint64_t datalen);
  64. /*
  65. * nghttp3_gaptr_first_gap_offset returns the offset to the first gap.
  66. * If there is no gap, it returns UINT64_MAX.
  67. */
  68. uint64_t nghttp3_gaptr_first_gap_offset(nghttp3_gaptr *gaptr);
  69. /*
  70. * nghttp3_gaptr_get_first_gap_after returns the first gap which
  71. * includes or comes after |offset|.
  72. */
  73. nghttp3_range nghttp3_gaptr_get_first_gap_after(nghttp3_gaptr *gaptr,
  74. uint64_t offset);
  75. /*
  76. * nghttp3_gaptr_is_pushed returns nonzero if range [offset, offset +
  77. * datalen) is completely pushed into this object.
  78. */
  79. int nghttp3_gaptr_is_pushed(nghttp3_gaptr *gaptr, uint64_t offset,
  80. uint64_t datalen);
  81. /*
  82. * nghttp3_gaptr_drop_first_gap deletes the first gap entirely as if
  83. * the range is pushed. This function assumes that at least one gap
  84. * exists.
  85. */
  86. void nghttp3_gaptr_drop_first_gap(nghttp3_gaptr *gaptr);
  87. #endif /* !defined(NGHTTP3_GAPTR_H) */