Path: blob/master/Utilities/cmnghttp2/lib/nghttp2_rcbuf.h
3153 views
/*1* nghttp2 - HTTP/2 C Library2*3* Copyright (c) 2016 Tatsuhiro Tsujikawa4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice shall be14* included in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24#ifndef NGHTTP2_RCBUF_H25#define NGHTTP2_RCBUF_H2627#ifdef HAVE_CONFIG_H28# include <config.h>29#endif /* HAVE_CONFIG_H */3031#include <nghttp2/nghttp2.h>3233struct nghttp2_rcbuf {34/* custom memory allocator belongs to the mem parameter when35creating this object. */36void *mem_user_data;37nghttp2_free free;38/* The pointer to the underlying buffer */39uint8_t *base;40/* Size of buffer pointed by |base|. */41size_t len;42/* Reference count */43int32_t ref;44};4546/*47* Allocates nghttp2_rcbuf object with |size| as initial buffer size.48* When the function succeeds, the reference count becomes 1.49*50* This function returns 0 if it succeeds, or one of the following51* negative error codes:52*53* NGHTTP2_ERR_NOMEM:54* Out of memory.55*/56int nghttp2_rcbuf_new(nghttp2_rcbuf **rcbuf_ptr, size_t size, nghttp2_mem *mem);5758/*59* Like nghttp2_rcbuf_new(), but initializes the buffer with |src| of60* length |srclen|. This function allocates additional byte at the61* end and puts '\0' into it, so that the resulting buffer could be62* used as NULL-terminated string. Still (*rcbuf_ptr)->len equals to63* |srclen|.64*65* This function returns 0 if it succeeds, or one of the following66* negative error codes:67*68* NGHTTP2_ERR_NOMEM:69* Out of memory.70*/71int nghttp2_rcbuf_new2(nghttp2_rcbuf **rcbuf_ptr, const uint8_t *src,72size_t srclen, nghttp2_mem *mem);7374/*75* Frees |rcbuf| itself, regardless of its reference cout.76*/77void nghttp2_rcbuf_del(nghttp2_rcbuf *rcbuf);7879#endif /* NGHTTP2_RCBUF_H */808182