1 /* 2 * nghttp3 3 * 4 * Copyright (c) 2019 nghttp3 contributors 5 * Copyright (c) 2016 nghttp2 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_RCBUF_H 27 #define NGHTTP3_RCBUF_H 28 29 #ifdef HAVE_CONFIG_H 30 # include <config.h> 31 #endif /* HAVE_CONFIG_H */ 32 33 #include <nghttp3/nghttp3.h> 34 35 struct nghttp3_rcbuf { 36 /* mem is the memory allocator that allocates memory for this 37 object. */ 38 const nghttp3_mem *mem; 39 /* The pointer to the underlying buffer */ 40 uint8_t *base; 41 /* Size of buffer pointed by |base|. */ 42 size_t len; 43 /* Reference count */ 44 int32_t ref; 45 }; 46 47 /* 48 * Allocates nghttp3_rcbuf object with |size| as initial buffer size. 49 * When the function succeeds, the reference count becomes 1. 50 * 51 * This function returns 0 if it succeeds, or one of the following 52 * negative error codes: 53 * 54 * NGHTTP3_ERR_NOMEM: 55 * Out of memory. 56 */ 57 int nghttp3_rcbuf_new(nghttp3_rcbuf **rcbuf_ptr, size_t size, 58 const nghttp3_mem *mem); 59 60 /* 61 * Like nghttp3_rcbuf_new(), but initializes the buffer with |src| of 62 * length |srclen|. This function allocates additional byte at the 63 * end and puts '\0' into it, so that the resulting buffer could be 64 * used as NULL-terminated string. Still (*rcbuf_ptr)->len equals to 65 * |srclen|. 66 * 67 * This function returns 0 if it succeeds, or one of the following 68 * negative error codes: 69 * 70 * NGHTTP3_ERR_NOMEM: 71 * Out of memory. 72 */ 73 int nghttp3_rcbuf_new2(nghttp3_rcbuf **rcbuf_ptr, const uint8_t *src, 74 size_t srclen, const nghttp3_mem *mem); 75 76 /* 77 * Frees |rcbuf| itself, regardless of its reference cout. 78 */ 79 void nghttp3_rcbuf_del(nghttp3_rcbuf *rcbuf); 80 81 #endif /* NGHTTP3_RCBUF_H */ 82