deflatehd, inflatehd: Migrate to nghttp2_ssize API

This commit is contained in:
Tatsuhiro Tsujikawa
2024-02-15 19:07:19 +09:00
parent f029a09cef
commit 33ad4cc2b8
2 changed files with 8 additions and 7 deletions

View File

@@ -41,6 +41,7 @@
#include <jansson.h> #include <jansson.h>
#define NGHTTP2_NO_SSIZE_T
#include <nghttp2/nghttp2.h> #include <nghttp2/nghttp2.h>
#include "template.h" #include "template.h"
@@ -113,10 +114,9 @@ static void output_to_json(nghttp2_hd_deflater *deflater, const uint8_t *buf,
static void deflate_hd(nghttp2_hd_deflater *deflater, static void deflate_hd(nghttp2_hd_deflater *deflater,
const std::vector<nghttp2_nv> &nva, size_t inputlen, const std::vector<nghttp2_nv> &nva, size_t inputlen,
int seq) { int seq) {
ssize_t rv;
std::array<uint8_t, 64_k> buf; std::array<uint8_t, 64_k> buf;
rv = nghttp2_hd_deflate_hd(deflater, buf.data(), buf.size(), auto rv = nghttp2_hd_deflate_hd2(deflater, buf.data(), buf.size(),
(nghttp2_nv *)nva.data(), nva.size()); (nghttp2_nv *)nva.data(), nva.size());
if (rv < 0) { if (rv < 0) {
fprintf(stderr, "deflate failed with error code %zd at %d\n", rv, seq); fprintf(stderr, "deflate failed with error code %zd at %d\n", rv, seq);

View File

@@ -41,6 +41,7 @@
#include <jansson.h> #include <jansson.h>
#define NGHTTP2_NO_SSIZE_T
#include <nghttp2/nghttp2.h> #include <nghttp2/nghttp2.h>
#include "template.h" #include "template.h"
@@ -93,7 +94,6 @@ static void to_json(nghttp2_hd_inflater *inflater, json_t *headers,
} }
static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq) { static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq) {
ssize_t rv;
nghttp2_nv nv; nghttp2_nv nv;
int inflate_flags; int inflate_flags;
size_t old_settings_table_size = size_t old_settings_table_size =
@@ -120,8 +120,8 @@ static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq) {
seq); seq);
return -1; return -1;
} }
rv = nghttp2_hd_inflate_change_table_size(inflater, auto rv = nghttp2_hd_inflate_change_table_size(
json_integer_value(table_size)); inflater, json_integer_value(table_size));
if (rv != 0) { if (rv != 0) {
fprintf(stderr, fprintf(stderr,
"nghttp2_hd_change_table_size() failed with error %s at %d\n", "nghttp2_hd_change_table_size() failed with error %s at %d\n",
@@ -147,7 +147,8 @@ static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq) {
auto p = buf.data(); auto p = buf.data();
for (;;) { for (;;) {
inflate_flags = 0; inflate_flags = 0;
rv = nghttp2_hd_inflate_hd(inflater, &nv, &inflate_flags, p, buflen, 1); auto rv =
nghttp2_hd_inflate_hd3(inflater, &nv, &inflate_flags, p, buflen, 1);
if (rv < 0) { if (rv < 0) {
fprintf(stderr, "inflate failed with error code %zd at %d\n", rv, seq); fprintf(stderr, "inflate failed with error code %zd at %d\n", rv, seq);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);