Skip to content

Commit eb306f4

Browse files
committed
lib: add nghttp2_rcbuf_is_static()
Add a `nghttp2_rcbuf_is_static()` method to tell whether a rcbuf is statically allocated. This can be useful for language bindings that wish to avoid creating duplicate strings for these buffers; concretely, I am planning to use this in the Node HTTP/2 module that is being introduced.
1 parent 788835c commit eb306f4

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

doc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(APIDOCS
4949
nghttp2_rcbuf_decref.rst
5050
nghttp2_rcbuf_get_buf.rst
5151
nghttp2_rcbuf_incref.rst
52+
nghttp2_rcbuf_is_static.rst
5253
nghttp2_select_next_protocol.rst
5354
nghttp2_session_callbacks_del.rst
5455
nghttp2_session_callbacks_new.rst

doc/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ APIDOCS= \
7474
nghttp2_rcbuf_decref.rst \
7575
nghttp2_rcbuf_get_buf.rst \
7676
nghttp2_rcbuf_incref.rst \
77+
nghttp2_rcbuf_is_static.rst \
7778
nghttp2_select_next_protocol.rst \
7879
nghttp2_session_callbacks_del.rst \
7980
nghttp2_session_callbacks_new.rst \

lib/includes/nghttp2/nghttp2.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,15 @@ NGHTTP2_EXTERN void nghttp2_rcbuf_decref(nghttp2_rcbuf *rcbuf);
469469
*/
470470
NGHTTP2_EXTERN nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf);
471471

472+
/**
473+
* @function
474+
*
475+
* Returns 1 if the underlying buffer is statically allocated,
476+
* and 0 otherwise. This can be useful for language bindings that wish to avoid
477+
* creating duplicate strings for these buffers.
478+
*/
479+
NGHTTP2_EXTERN int nghttp2_rcbuf_is_static(const nghttp2_rcbuf *rcbuf);
480+
472481
/**
473482
* @enum
474483
*

lib/nghttp2_rcbuf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,7 @@ nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf) {
9696
nghttp2_vec res = {rcbuf->base, rcbuf->len};
9797
return res;
9898
}
99+
100+
int nghttp2_rcbuf_is_static(const nghttp2_rcbuf *rcbuf) {
101+
return rcbuf->ref == -1;
102+
}

0 commit comments

Comments
 (0)