aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/transport
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-09-22 10:42:19 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-09-22 10:42:19 -0700
commit45724b35e411fef7c5da66a74c78428c11d56843 (patch)
tree9264034aca675c89444e02f72ef58e67d7043604 /src/core/transport
parent298751c1195523ef6228595043b583c3a6270e08 (diff)
indent pass to get logical source lines on one physical line
Diffstat (limited to 'src/core/transport')
-rw-r--r--src/core/transport/chttp2/alpn.c26
-rw-r--r--src/core/transport/chttp2/alpn.h6
-rw-r--r--src/core/transport/chttp2/bin_encoder.c214
-rw-r--r--src/core/transport/chttp2/bin_encoder.h8
-rw-r--r--src/core/transport/chttp2/frame.h3
-rw-r--r--src/core/transport/chttp2/frame_data.c215
-rw-r--r--src/core/transport/chttp2/frame_data.h21
-rw-r--r--src/core/transport/chttp2/frame_goaway.c218
-rw-r--r--src/core/transport/chttp2/frame_goaway.h22
-rw-r--r--src/core/transport/chttp2/frame_ping.c82
-rw-r--r--src/core/transport/chttp2/frame_ping.h13
-rw-r--r--src/core/transport/chttp2/frame_rst_stream.c78
-rw-r--r--src/core/transport/chttp2/frame_rst_stream.h13
-rw-r--r--src/core/transport/chttp2/frame_settings.c353
-rw-r--r--src/core/transport/chttp2/frame_settings.h32
-rw-r--r--src/core/transport/chttp2/frame_window_update.c107
-rw-r--r--src/core/transport/chttp2/frame_window_update.h15
-rw-r--r--src/core/transport/chttp2/hpack_parser.c2003
-rw-r--r--src/core/transport/chttp2/hpack_parser.h30
-rw-r--r--src/core/transport/chttp2/hpack_table.c424
-rw-r--r--src/core/transport/chttp2/hpack_table.h18
-rw-r--r--src/core/transport/chttp2/http2_errors.h3
-rw-r--r--src/core/transport/chttp2/huffsyms.c130
-rw-r--r--src/core/transport/chttp2/huffsyms.h3
-rw-r--r--src/core/transport/chttp2/incoming_metadata.c200
-rw-r--r--src/core/transport/chttp2/incoming_metadata.h35
-rw-r--r--src/core/transport/chttp2/internal.h246
-rw-r--r--src/core/transport/chttp2/parsing.c1154
-rw-r--r--src/core/transport/chttp2/status_conversion.c36
-rw-r--r--src/core/transport/chttp2/status_conversion.h10
-rw-r--r--src/core/transport/chttp2/stream_encoder.c925
-rw-r--r--src/core/transport/chttp2/stream_encoder.h17
-rw-r--r--src/core/transport/chttp2/stream_lists.c488
-rw-r--r--src/core/transport/chttp2/stream_map.c218
-rw-r--r--src/core/transport/chttp2/stream_map.h26
-rw-r--r--src/core/transport/chttp2/timeout_encoding.c258
-rw-r--r--src/core/transport/chttp2/timeout_encoding.h4
-rw-r--r--src/core/transport/chttp2/varint.c56
-rw-r--r--src/core/transport/chttp2/varint.h6
-rw-r--r--src/core/transport/chttp2/writing.c311
-rw-r--r--src/core/transport/chttp2_transport.c1737
-rw-r--r--src/core/transport/chttp2_transport.h9
-rw-r--r--src/core/transport/connectivity_state.c139
-rw-r--r--src/core/transport/connectivity_state.h25
-rw-r--r--src/core/transport/metadata.c867
-rw-r--r--src/core/transport/metadata.h84
-rw-r--r--src/core/transport/stream_op.c451
-rw-r--r--src/core/transport/stream_op.h82
-rw-r--r--src/core/transport/transport.c148
-rw-r--r--src/core/transport/transport.h56
-rw-r--r--src/core/transport/transport_impl.h27
-rw-r--r--src/core/transport/transport_op_string.c208
52 files changed, 6178 insertions, 5682 deletions
diff --git a/src/core/transport/chttp2/alpn.c b/src/core/transport/chttp2/alpn.c
index 69da4e6718..f008615c9a 100644
--- a/src/core/transport/chttp2/alpn.c
+++ b/src/core/transport/chttp2/alpn.c
@@ -36,21 +36,29 @@
#include <grpc/support/useful.h>
/* in order of preference */
-static const char *const supported_versions[] = {"h2"};
+static const char *const supported_versions[] = { "h2" };
-int grpc_chttp2_is_alpn_version_supported(const char *version, size_t size) {
+int
+grpc_chttp2_is_alpn_version_supported (const char *version, size_t size)
+{
size_t i;
- for (i = 0; i < GPR_ARRAY_SIZE(supported_versions); i++) {
- if (!strncmp(version, supported_versions[i], size)) return 1;
- }
+ for (i = 0; i < GPR_ARRAY_SIZE (supported_versions); i++)
+ {
+ if (!strncmp (version, supported_versions[i], size))
+ return 1;
+ }
return 0;
}
-size_t grpc_chttp2_num_alpn_versions(void) {
- return GPR_ARRAY_SIZE(supported_versions);
+size_t
+grpc_chttp2_num_alpn_versions (void)
+{
+ return GPR_ARRAY_SIZE (supported_versions);
}
-const char *grpc_chttp2_get_alpn_version_index(size_t i) {
- GPR_ASSERT(i < GPR_ARRAY_SIZE(supported_versions));
+const char *
+grpc_chttp2_get_alpn_version_index (size_t i)
+{
+ GPR_ASSERT (i < GPR_ARRAY_SIZE (supported_versions));
return supported_versions[i];
}
diff --git a/src/core/transport/chttp2/alpn.h b/src/core/transport/chttp2/alpn.h
index f38b4c3167..b45081eccf 100644
--- a/src/core/transport/chttp2/alpn.h
+++ b/src/core/transport/chttp2/alpn.h
@@ -37,13 +37,13 @@
#include <string.h>
/* Retuns 1 if the version is supported, 0 otherwise. */
-int grpc_chttp2_is_alpn_version_supported(const char *version, size_t size);
+int grpc_chttp2_is_alpn_version_supported (const char *version, size_t size);
/* Returns the number of protocol versions to advertise */
-size_t grpc_chttp2_num_alpn_versions(void);
+size_t grpc_chttp2_num_alpn_versions (void);
/* Returns the protocol version at index i (0 <= i <
* grpc_chttp2_num_alpn_versions()) */
-const char *grpc_chttp2_get_alpn_version_index(size_t i);
+const char *grpc_chttp2_get_alpn_version_index (size_t i);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_ALPN_H */
diff --git a/src/core/transport/chttp2/bin_encoder.c b/src/core/transport/chttp2/bin_encoder.c
index e21d800083..929f65ad66 100644
--- a/src/core/transport/chttp2/bin_encoder.c
+++ b/src/core/transport/chttp2/bin_encoder.c
@@ -38,51 +38,56 @@
#include "src/core/transport/chttp2/huffsyms.h"
#include <grpc/support/log.h>
-static const char alphabet[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-typedef struct {
+typedef struct
+{
gpr_uint16 bits;
gpr_uint8 length;
} b64_huff_sym;
static const b64_huff_sym huff_alphabet[64] = {
- {0x21, 6}, {0x5d, 7}, {0x5e, 7}, {0x5f, 7}, {0x60, 7}, {0x61, 7},
- {0x62, 7}, {0x63, 7}, {0x64, 7}, {0x65, 7}, {0x66, 7}, {0x67, 7},
- {0x68, 7}, {0x69, 7}, {0x6a, 7}, {0x6b, 7}, {0x6c, 7}, {0x6d, 7},
- {0x6e, 7}, {0x6f, 7}, {0x70, 7}, {0x71, 7}, {0x72, 7}, {0xfc, 8},
- {0x73, 7}, {0xfd, 8}, {0x3, 5}, {0x23, 6}, {0x4, 5}, {0x24, 6},
- {0x5, 5}, {0x25, 6}, {0x26, 6}, {0x27, 6}, {0x6, 5}, {0x74, 7},
- {0x75, 7}, {0x28, 6}, {0x29, 6}, {0x2a, 6}, {0x7, 5}, {0x2b, 6},
- {0x76, 7}, {0x2c, 6}, {0x8, 5}, {0x9, 5}, {0x2d, 6}, {0x77, 7},
- {0x78, 7}, {0x79, 7}, {0x7a, 7}, {0x7b, 7}, {0x0, 5}, {0x1, 5},
- {0x2, 5}, {0x19, 6}, {0x1a, 6}, {0x1b, 6}, {0x1c, 6}, {0x1d, 6},
- {0x1e, 6}, {0x1f, 6}, {0x7fb, 11}, {0x18, 6}};
-
-static const gpr_uint8 tail_xtra[3] = {0, 2, 3};
-
-gpr_slice grpc_chttp2_base64_encode(gpr_slice input) {
- size_t input_length = GPR_SLICE_LENGTH(input);
+ {0x21, 6}, {0x5d, 7}, {0x5e, 7}, {0x5f, 7}, {0x60, 7}, {0x61, 7},
+ {0x62, 7}, {0x63, 7}, {0x64, 7}, {0x65, 7}, {0x66, 7}, {0x67, 7},
+ {0x68, 7}, {0x69, 7}, {0x6a, 7}, {0x6b, 7}, {0x6c, 7}, {0x6d, 7},
+ {0x6e, 7}, {0x6f, 7}, {0x70, 7}, {0x71, 7}, {0x72, 7}, {0xfc, 8},
+ {0x73, 7}, {0xfd, 8}, {0x3, 5}, {0x23, 6}, {0x4, 5}, {0x24, 6},
+ {0x5, 5}, {0x25, 6}, {0x26, 6}, {0x27, 6}, {0x6, 5}, {0x74, 7},
+ {0x75, 7}, {0x28, 6}, {0x29, 6}, {0x2a, 6}, {0x7, 5}, {0x2b, 6},
+ {0x76, 7}, {0x2c, 6}, {0x8, 5}, {0x9, 5}, {0x2d, 6}, {0x77, 7},
+ {0x78, 7}, {0x79, 7}, {0x7a, 7}, {0x7b, 7}, {0x0, 5}, {0x1, 5},
+ {0x2, 5}, {0x19, 6}, {0x1a, 6}, {0x1b, 6}, {0x1c, 6}, {0x1d, 6},
+ {0x1e, 6}, {0x1f, 6}, {0x7fb, 11}, {0x18, 6}
+};
+
+static const gpr_uint8 tail_xtra[3] = { 0, 2, 3 };
+
+gpr_slice
+grpc_chttp2_base64_encode (gpr_slice input)
+{
+ size_t input_length = GPR_SLICE_LENGTH (input);
size_t input_triplets = input_length / 3;
size_t tail_case = input_length % 3;
size_t output_length = input_triplets * 4 + tail_xtra[tail_case];
- gpr_slice output = gpr_slice_malloc(output_length);
- gpr_uint8 *in = GPR_SLICE_START_PTR(input);
- char *out = (char *)GPR_SLICE_START_PTR(output);
+ gpr_slice output = gpr_slice_malloc (output_length);
+ gpr_uint8 *in = GPR_SLICE_START_PTR (input);
+ char *out = (char *) GPR_SLICE_START_PTR (output);
size_t i;
/* encode full triplets */
- for (i = 0; i < input_triplets; i++) {
- out[0] = alphabet[in[0] >> 2];
- out[1] = alphabet[((in[0] & 0x3) << 4) | (in[1] >> 4)];
- out[2] = alphabet[((in[1] & 0xf) << 2) | (in[2] >> 6)];
- out[3] = alphabet[in[2] & 0x3f];
- out += 4;
- in += 3;
- }
+ for (i = 0; i < input_triplets; i++)
+ {
+ out[0] = alphabet[in[0] >> 2];
+ out[1] = alphabet[((in[0] & 0x3) << 4) | (in[1] >> 4)];
+ out[2] = alphabet[((in[1] & 0xf) << 2) | (in[2] >> 6)];
+ out[3] = alphabet[in[2] & 0x3f];
+ out += 4;
+ in += 3;
+ }
/* encode the remaining bytes */
- switch (tail_case) {
+ switch (tail_case)
+ {
case 0:
break;
case 1:
@@ -98,14 +103,16 @@ gpr_slice grpc_chttp2_base64_encode(gpr_slice input) {
out += 3;
in += 2;
break;
- }
+ }
- GPR_ASSERT(out == (char *)GPR_SLICE_END_PTR(output));
- GPR_ASSERT(in == GPR_SLICE_END_PTR(input));
+ GPR_ASSERT (out == (char *) GPR_SLICE_END_PTR (output));
+ GPR_ASSERT (in == GPR_SLICE_END_PTR (input));
return output;
}
-gpr_slice grpc_chttp2_huffman_compress(gpr_slice input) {
+gpr_slice
+grpc_chttp2_huffman_compress (gpr_slice input)
+{
size_t nbits;
gpr_uint8 *in;
gpr_uint8 *out;
@@ -114,73 +121,85 @@ gpr_slice grpc_chttp2_huffman_compress(gpr_slice input) {
gpr_uint32 temp_length = 0;
nbits = 0;
- for (in = GPR_SLICE_START_PTR(input); in != GPR_SLICE_END_PTR(input); ++in) {
- nbits += grpc_chttp2_huffsyms[*in].length;
- }
-
- output = gpr_slice_malloc(nbits / 8 + (nbits % 8 != 0));
- out = GPR_SLICE_START_PTR(output);
- for (in = GPR_SLICE_START_PTR(input); in != GPR_SLICE_END_PTR(input); ++in) {
- int sym = *in;
- temp <<= grpc_chttp2_huffsyms[sym].length;
- temp |= grpc_chttp2_huffsyms[sym].bits;
- temp_length += grpc_chttp2_huffsyms[sym].length;
-
- while (temp_length > 8) {
- temp_length -= 8;
- *out++ = (gpr_uint8)(temp >> temp_length);
+ for (in = GPR_SLICE_START_PTR (input); in != GPR_SLICE_END_PTR (input); ++in)
+ {
+ nbits += grpc_chttp2_huffsyms[*in].length;
}
- }
- if (temp_length) {
- *out++ = (gpr_uint8)(temp << (8u - temp_length)) |
- (gpr_uint8)(0xffu >> temp_length);
- }
+ output = gpr_slice_malloc (nbits / 8 + (nbits % 8 != 0));
+ out = GPR_SLICE_START_PTR (output);
+ for (in = GPR_SLICE_START_PTR (input); in != GPR_SLICE_END_PTR (input); ++in)
+ {
+ int sym = *in;
+ temp <<= grpc_chttp2_huffsyms[sym].length;
+ temp |= grpc_chttp2_huffsyms[sym].bits;
+ temp_length += grpc_chttp2_huffsyms[sym].length;
+
+ while (temp_length > 8)
+ {
+ temp_length -= 8;
+ *out++ = (gpr_uint8) (temp >> temp_length);
+ }
+ }
- GPR_ASSERT(out == GPR_SLICE_END_PTR(output));
+ if (temp_length)
+ {
+ *out++ = (gpr_uint8) (temp << (8u - temp_length)) | (gpr_uint8) (0xffu >> temp_length);
+ }
+
+ GPR_ASSERT (out == GPR_SLICE_END_PTR (output));
return output;
}
-typedef struct {
+typedef struct
+{
gpr_uint32 temp;
gpr_uint32 temp_length;
gpr_uint8 *out;
} huff_out;
-static void enc_flush_some(huff_out *out) {
- while (out->temp_length > 8) {
- out->temp_length -= 8;
- *out->out++ = (gpr_uint8)(out->temp >> out->temp_length);
- }
+static void
+enc_flush_some (huff_out * out)
+{
+ while (out->temp_length > 8)
+ {
+ out->temp_length -= 8;
+ *out->out++ = (gpr_uint8) (out->temp >> out->temp_length);
+ }
}
-static void enc_add2(huff_out *out, gpr_uint8 a, gpr_uint8 b) {
+static void
+enc_add2 (huff_out * out, gpr_uint8 a, gpr_uint8 b)
+{
b64_huff_sym sa = huff_alphabet[a];
b64_huff_sym sb = huff_alphabet[b];
- out->temp = (out->temp << (sa.length + sb.length)) |
- ((gpr_uint32)sa.bits << sb.length) | sb.bits;
- out->temp_length += (gpr_uint32)sa.length + (gpr_uint32)sb.length;
- enc_flush_some(out);
+ out->temp = (out->temp << (sa.length + sb.length)) | ((gpr_uint32) sa.bits << sb.length) | sb.bits;
+ out->temp_length += (gpr_uint32) sa.length + (gpr_uint32) sb.length;
+ enc_flush_some (out);
}
-static void enc_add1(huff_out *out, gpr_uint8 a) {
+static void
+enc_add1 (huff_out * out, gpr_uint8 a)
+{
b64_huff_sym sa = huff_alphabet[a];
out->temp = (out->temp << sa.length) | sa.bits;
out->temp_length += sa.length;
- enc_flush_some(out);
+ enc_flush_some (out);
}
-gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) {
- size_t input_length = GPR_SLICE_LENGTH(input);
+gpr_slice
+grpc_chttp2_base64_encode_and_huffman_compress (gpr_slice input)
+{
+ size_t input_length = GPR_SLICE_LENGTH (input);
size_t input_triplets = input_length / 3;
size_t tail_case = input_length % 3;
size_t output_syms = input_triplets * 4 + tail_xtra[tail_case];
size_t max_output_bits = 11 * output_syms;
size_t max_output_length = max_output_bits / 8 + (max_output_bits % 8 != 0);
- gpr_slice output = gpr_slice_malloc(max_output_length);
- gpr_uint8 *in = GPR_SLICE_START_PTR(input);
- gpr_uint8 *start_out = GPR_SLICE_START_PTR(output);
+ gpr_slice output = gpr_slice_malloc (max_output_length);
+ gpr_uint8 *in = GPR_SLICE_START_PTR (input);
+ gpr_uint8 *start_out = GPR_SLICE_START_PTR (output);
huff_out out;
size_t i;
@@ -189,42 +208,45 @@ gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) {
out.out = start_out;
/* encode full triplets */
- for (i = 0; i < input_triplets; i++) {
- enc_add2(&out, in[0] >> 2, (gpr_uint8)((in[0] & 0x3) << 4) | (in[1] >> 4));
- enc_add2(&out, (gpr_uint8)((in[1] & 0xf) << 2) | (in[2] >> 6),
- (gpr_uint8)(in[2] & 0x3f));
- in += 3;
- }
+ for (i = 0; i < input_triplets; i++)
+ {
+ enc_add2 (&out, in[0] >> 2, (gpr_uint8) ((in[0] & 0x3) << 4) | (in[1] >> 4));
+ enc_add2 (&out, (gpr_uint8) ((in[1] & 0xf) << 2) | (in[2] >> 6), (gpr_uint8) (in[2] & 0x3f));
+ in += 3;
+ }
/* encode the remaining bytes */
- switch (tail_case) {
+ switch (tail_case)
+ {
case 0:
break;
case 1:
- enc_add2(&out, in[0] >> 2, (gpr_uint8)((in[0] & 0x3) << 4));
+ enc_add2 (&out, in[0] >> 2, (gpr_uint8) ((in[0] & 0x3) << 4));
in += 1;
break;
case 2:
- enc_add2(&out, in[0] >> 2,
- (gpr_uint8)((in[0] & 0x3) << 4) | (gpr_uint8)(in[1] >> 4));
- enc_add1(&out, (gpr_uint8)((in[1] & 0xf) << 2));
+ enc_add2 (&out, in[0] >> 2, (gpr_uint8) ((in[0] & 0x3) << 4) | (gpr_uint8) (in[1] >> 4));
+ enc_add1 (&out, (gpr_uint8) ((in[1] & 0xf) << 2));
in += 2;
break;
- }
+ }
- if (out.temp_length) {
- *out.out++ = (gpr_uint8)(out.temp << (8u - out.temp_length)) |
- (gpr_uint8)(0xffu >> out.temp_length);
- }
+ if (out.temp_length)
+ {
+ *out.out++ = (gpr_uint8) (out.temp << (8u - out.temp_length)) | (gpr_uint8) (0xffu >> out.temp_length);
+ }
- GPR_ASSERT(out.out <= GPR_SLICE_END_PTR(output));
- GPR_SLICE_SET_LENGTH(output, out.out - start_out);
+ GPR_ASSERT (out.out <= GPR_SLICE_END_PTR (output));
+ GPR_SLICE_SET_LENGTH (output, out.out - start_out);
- GPR_ASSERT(in == GPR_SLICE_END_PTR(input));
+ GPR_ASSERT (in == GPR_SLICE_END_PTR (input));
return output;
}
-int grpc_is_binary_header(const char *key, size_t length) {
- if (length < 5) return 0;
- return 0 == memcmp(key + length - 4, "-bin", 4);
+int
+grpc_is_binary_header (const char *key, size_t length)
+{
+ if (length < 5)
+ return 0;
+ return 0 == memcmp (key + length - 4, "-bin", 4);
}
diff --git a/src/core/transport/chttp2/bin_encoder.h b/src/core/transport/chttp2/bin_encoder.h
index d3e5a855dd..6e57615f7f 100644
--- a/src/core/transport/chttp2/bin_encoder.h
+++ b/src/core/transport/chttp2/bin_encoder.h
@@ -38,19 +38,19 @@
/* base64 encode a slice. Returns a new slice, does not take ownership of the
input */
-gpr_slice grpc_chttp2_base64_encode(gpr_slice input);
+gpr_slice grpc_chttp2_base64_encode (gpr_slice input);
/* Compress a slice with the static huffman encoder detailed in the hpack
standard. Returns a new slice, does not take ownership of the input */
-gpr_slice grpc_chttp2_huffman_compress(gpr_slice input);
+gpr_slice grpc_chttp2_huffman_compress (gpr_slice input);
/* equivalent to:
gpr_slice x = grpc_chttp2_base64_encode(input);
gpr_slice y = grpc_chttp2_huffman_compress(x);
gpr_slice_unref(x);
return y; */
-gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input);
+gpr_slice grpc_chttp2_base64_encode_and_huffman_compress (gpr_slice input);
-int grpc_is_binary_header(const char *key, size_t length);
+int grpc_is_binary_header (const char *key, size_t length);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_BIN_ENCODER_H */
diff --git a/src/core/transport/chttp2/frame.h b/src/core/transport/chttp2/frame.h
index 879ee036fa..84aa154967 100644
--- a/src/core/transport/chttp2/frame.h
+++ b/src/core/transport/chttp2/frame.h
@@ -39,7 +39,8 @@
/* Common definitions for frame handling in the chttp2 transport */
-typedef enum {
+typedef enum
+{
GRPC_CHTTP2_PARSE_OK,
GRPC_CHTTP2_STREAM_ERROR,
GRPC_CHTTP2_CONNECTION_ERROR
diff --git a/src/core/transport/chttp2/frame_data.c b/src/core/transport/chttp2/frame_data.c
index a58189a136..461a1e26f8 100644
--- a/src/core/transport/chttp2/frame_data.c
+++ b/src/core/transport/chttp2/frame_data.c
@@ -42,133 +42,146 @@
#include <grpc/support/useful.h>
#include "src/core/transport/transport.h"
-grpc_chttp2_parse_error grpc_chttp2_data_parser_init(
- grpc_chttp2_data_parser *parser) {
+grpc_chttp2_parse_error
+grpc_chttp2_data_parser_init (grpc_chttp2_data_parser * parser)
+{
parser->state = GRPC_CHTTP2_DATA_FH_0;
- grpc_sopb_init(&parser->incoming_sopb);
+ grpc_sopb_init (&parser->incoming_sopb);
return GRPC_CHTTP2_PARSE_OK;
}
-void grpc_chttp2_data_parser_destroy(grpc_chttp2_data_parser *parser) {
- grpc_sopb_destroy(&parser->incoming_sopb);
+void
+grpc_chttp2_data_parser_destroy (grpc_chttp2_data_parser * parser)
+{
+ grpc_sopb_destroy (&parser->incoming_sopb);
}
-grpc_chttp2_parse_error grpc_chttp2_data_parser_begin_frame(
- grpc_chttp2_data_parser *parser, gpr_uint8 flags) {
- if (flags & ~GRPC_CHTTP2_DATA_FLAG_END_STREAM) {
- gpr_log(GPR_ERROR, "unsupported data flags: 0x%02x", flags);
- return GRPC_CHTTP2_STREAM_ERROR;
- }
+grpc_chttp2_parse_error
+grpc_chttp2_data_parser_begin_frame (grpc_chttp2_data_parser * parser, gpr_uint8 flags)
+{
+ if (flags & ~GRPC_CHTTP2_DATA_FLAG_END_STREAM)
+ {
+ gpr_log (GPR_ERROR, "unsupported data flags: 0x%02x", flags);
+ return GRPC_CHTTP2_STREAM_ERROR;
+ }
- if (flags & GRPC_CHTTP2_DATA_FLAG_END_STREAM) {
- parser->is_last_frame = 1;
- } else {
- parser->is_last_frame = 0;
- }
+ if (flags & GRPC_CHTTP2_DATA_FLAG_END_STREAM)
+ {
+ parser->is_last_frame = 1;
+ }
+ else
+ {
+ parser->is_last_frame = 0;
+ }
return GRPC_CHTTP2_PARSE_OK;
}
-grpc_chttp2_parse_error grpc_chttp2_data_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list) {
- gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice);
- gpr_uint8 *const end = GPR_SLICE_END_PTR(slice);
+grpc_chttp2_parse_error
+grpc_chttp2_data_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list)
+{
+ gpr_uint8 *const beg = GPR_SLICE_START_PTR (slice);
+ gpr_uint8 *const end = GPR_SLICE_END_PTR (slice);
gpr_uint8 *cur = beg;
grpc_chttp2_data_parser *p = parser;
gpr_uint32 message_flags = 0;
- if (is_last && p->is_last_frame) {
- stream_parsing->received_close = 1;
- }
+ if (is_last && p->is_last_frame)
+ {
+ stream_parsing->received_close = 1;
+ }
- if (cur == end) {
- return GRPC_CHTTP2_PARSE_OK;
- }
+ if (cur == end)
+ {
+ return GRPC_CHTTP2_PARSE_OK;
+ }
- switch (p->state) {
- fh_0:
+ switch (p->state)
+ {
+ fh_0:
case GRPC_CHTTP2_DATA_FH_0:
p->frame_type = *cur;
- switch (p->frame_type) {
- case 0:
- p->is_frame_compressed = 0; /* GPR_FALSE */
- break;
- case 1:
- p->is_frame_compressed = 1; /* GPR_TRUE */
- break;
- default:
- gpr_log(GPR_ERROR, "Bad GRPC frame type 0x%02x", p->frame_type);
- return GRPC_CHTTP2_STREAM_ERROR;
- }
- if (++cur == end) {
- p->state = GRPC_CHTTP2_DATA_FH_1;
- return GRPC_CHTTP2_PARSE_OK;
- }
- /* fallthrough */
+ switch (p->frame_type)
+ {
+ case 0:
+ p->is_frame_compressed = 0; /* GPR_FALSE */
+ break;
+ case 1:
+ p->is_frame_compressed = 1; /* GPR_TRUE */
+ break;
+ default:
+ gpr_log (GPR_ERROR, "Bad GRPC frame type 0x%02x", p->frame_type);
+ return GRPC_CHTTP2_STREAM_ERROR;
+ }
+ if (++cur == end)
+ {
+ p->state = GRPC_CHTTP2_DATA_FH_1;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ /* fallthrough */
case GRPC_CHTTP2_DATA_FH_1:
- p->frame_size = ((gpr_uint32)*cur) << 24;
- if (++cur == end) {
- p->state = GRPC_CHTTP2_DATA_FH_2;
- return GRPC_CHTTP2_PARSE_OK;
- }
- /* fallthrough */
+ p->frame_size = ((gpr_uint32) * cur) << 24;
+ if (++cur == end)
+ {
+ p->state = GRPC_CHTTP2_DATA_FH_2;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ /* fallthrough */
case GRPC_CHTTP2_DATA_FH_2:
- p->frame_size |= ((gpr_uint32)*cur) << 16;
- if (++cur == end) {
- p->state = GRPC_CHTTP2_DATA_FH_3;
- return GRPC_CHTTP2_PARSE_OK;
- }
- /* fallthrough */
+ p->frame_size |= ((gpr_uint32) * cur) << 16;
+ if (++cur == end)
+ {
+ p->state = GRPC_CHTTP2_DATA_FH_3;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ /* fallthrough */
case GRPC_CHTTP2_DATA_FH_3:
- p->frame_size |= ((gpr_uint32)*cur) << 8;
- if (++cur == end) {
- p->state = GRPC_CHTTP2_DATA_FH_4;
- return GRPC_CHTTP2_PARSE_OK;
- }
- /* fallthrough */
+ p->frame_size |= ((gpr_uint32) * cur) << 8;
+ if (++cur == end)
+ {
+ p->state = GRPC_CHTTP2_DATA_FH_4;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ /* fallthrough */
case GRPC_CHTTP2_DATA_FH_4:
- p->frame_size |= ((gpr_uint32)*cur);
+ p->frame_size |= ((gpr_uint32) * cur);
p->state = GRPC_CHTTP2_DATA_FRAME;
++cur;
- if (p->is_frame_compressed) {
- message_flags |= GRPC_WRITE_INTERNAL_COMPRESS;
- }
- grpc_sopb_add_begin_message(&p->incoming_sopb, p->frame_size,
- message_flags);
- /* fallthrough */
+ if (p->is_frame_compressed)
+ {
+ message_flags |= GRPC_WRITE_INTERNAL_COMPRESS;
+ }
+ grpc_sopb_add_begin_message (&p->incoming_sopb, p->frame_size, message_flags);
+ /* fallthrough */
case GRPC_CHTTP2_DATA_FRAME:
- if (cur == end) {
- grpc_chttp2_list_add_parsing_seen_stream(transport_parsing,
- stream_parsing);
- return GRPC_CHTTP2_PARSE_OK;
- }
- grpc_chttp2_list_add_parsing_seen_stream(transport_parsing,
- stream_parsing);
- if ((gpr_uint32)(end - cur) == p->frame_size) {
- grpc_sopb_add_slice(
- &p->incoming_sopb,
- gpr_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)));
- p->state = GRPC_CHTTP2_DATA_FH_0;
- return GRPC_CHTTP2_PARSE_OK;
- } else if ((gpr_uint32)(end - cur) > p->frame_size) {
- grpc_sopb_add_slice(&p->incoming_sopb,
- gpr_slice_sub(slice, (size_t)(cur - beg),
- (size_t)(cur + p->frame_size - beg)));
- cur += p->frame_size;
- goto fh_0; /* loop */
- } else {
- grpc_sopb_add_slice(
- &p->incoming_sopb,
- gpr_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)));
- GPR_ASSERT(end - cur <= p->frame_size);
- p->frame_size -= (gpr_uint32)(end - cur);
- return GRPC_CHTTP2_PARSE_OK;
- }
- }
+ if (cur == end)
+ {
+ grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing);
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing);
+ if ((gpr_uint32) (end - cur) == p->frame_size)
+ {
+ grpc_sopb_add_slice (&p->incoming_sopb, gpr_slice_sub (slice, (size_t) (cur - beg), (size_t) (end - beg)));
+ p->state = GRPC_CHTTP2_DATA_FH_0;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ else if ((gpr_uint32) (end - cur) > p->frame_size)
+ {
+ grpc_sopb_add_slice (&p->incoming_sopb, gpr_slice_sub (slice, (size_t) (cur - beg), (size_t) (cur + p->frame_size - beg)));
+ cur += p->frame_size;
+ goto fh_0; /* loop */
+ }
+ else
+ {
+ grpc_sopb_add_slice (&p->incoming_sopb, gpr_slice_sub (slice, (size_t) (cur - beg), (size_t) (end - beg)));
+ GPR_ASSERT (end - cur <= p->frame_size);
+ p->frame_size -= (gpr_uint32) (end - cur);
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ }
- gpr_log(GPR_ERROR, "should never reach here");
- abort();
+ gpr_log (GPR_ERROR, "should never reach here");
+ abort ();
return GRPC_CHTTP2_CONNECTION_ERROR;
}
diff --git a/src/core/transport/chttp2/frame_data.h b/src/core/transport/chttp2/frame_data.h
index ccd56a132c..6284433b19 100644
--- a/src/core/transport/chttp2/frame_data.h
+++ b/src/core/transport/chttp2/frame_data.h
@@ -42,7 +42,8 @@
#include "src/core/transport/stream_op.h"
#include "src/core/transport/chttp2/frame.h"
-typedef enum {
+typedef enum
+{
GRPC_CHTTP2_DATA_FH_0,
GRPC_CHTTP2_DATA_FH_1,
GRPC_CHTTP2_DATA_FH_2,
@@ -51,7 +52,8 @@ typedef enum {
GRPC_CHTTP2_DATA_FRAME
} grpc_chttp2_stream_state;
-typedef struct {
+typedef struct
+{
grpc_chttp2_stream_state state;
gpr_uint8 is_last_frame;
gpr_uint8 frame_type;
@@ -62,23 +64,18 @@ typedef struct {
} grpc_chttp2_data_parser;
/* initialize per-stream state for data frame parsing */
-grpc_chttp2_parse_error grpc_chttp2_data_parser_init(
- grpc_chttp2_data_parser *parser);
+grpc_chttp2_parse_error grpc_chttp2_data_parser_init (grpc_chttp2_data_parser * parser);
-void grpc_chttp2_data_parser_destroy(grpc_chttp2_data_parser *parser);
+void grpc_chttp2_data_parser_destroy (grpc_chttp2_data_parser * parser);
/* start processing a new data frame */
-grpc_chttp2_parse_error grpc_chttp2_data_parser_begin_frame(
- grpc_chttp2_data_parser *parser, gpr_uint8 flags);
+grpc_chttp2_parse_error grpc_chttp2_data_parser_begin_frame (grpc_chttp2_data_parser * parser, gpr_uint8 flags);
/* handle a slice of a data frame - is_last indicates the last slice of a
frame */
-grpc_chttp2_parse_error grpc_chttp2_data_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list);
+grpc_chttp2_parse_error grpc_chttp2_data_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list);
/* create a slice with an empty data frame and is_last set */
-gpr_slice grpc_chttp2_data_frame_create_empty_close(gpr_uint32 id);
+gpr_slice grpc_chttp2_data_frame_create_empty_close (gpr_uint32 id);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_DATA_H */
diff --git a/src/core/transport/chttp2/frame_goaway.c b/src/core/transport/chttp2/frame_goaway.c
index d338b56611..f990e86465 100644
--- a/src/core/transport/chttp2/frame_goaway.c
+++ b/src/core/transport/chttp2/frame_goaway.c
@@ -39,137 +39,151 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser *p) {
+void
+grpc_chttp2_goaway_parser_init (grpc_chttp2_goaway_parser * p)
+{
p->debug_data = NULL;
}
-void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser *p) {
- gpr_free(p->debug_data);
+void
+grpc_chttp2_goaway_parser_destroy (grpc_chttp2_goaway_parser * p)
+{
+ gpr_free (p->debug_data);
}
-grpc_chttp2_parse_error grpc_chttp2_goaway_parser_begin_frame(
- grpc_chttp2_goaway_parser *p, gpr_uint32 length, gpr_uint8 flags) {
- if (length < 8) {
- gpr_log(GPR_ERROR, "goaway frame too short (%d bytes)", length);
- return GRPC_CHTTP2_CONNECTION_ERROR;
- }
+grpc_chttp2_parse_error
+grpc_chttp2_goaway_parser_begin_frame (grpc_chttp2_goaway_parser * p, gpr_uint32 length, gpr_uint8 flags)
+{
+ if (length < 8)
+ {
+ gpr_log (GPR_ERROR, "goaway frame too short (%d bytes)", length);
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
- gpr_free(p->debug_data);
+ gpr_free (p->debug_data);
p->debug_length = length - 8;
- p->debug_data = gpr_malloc(p->debug_length);
+ p->debug_data = gpr_malloc (p->debug_length);
p->debug_pos = 0;
p->state = GRPC_CHTTP2_GOAWAY_LSI0;
return GRPC_CHTTP2_PARSE_OK;
}
-grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list) {
- gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice);
- gpr_uint8 *const end = GPR_SLICE_END_PTR(slice);
+grpc_chttp2_parse_error
+grpc_chttp2_goaway_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list)
+{
+ gpr_uint8 *const beg = GPR_SLICE_START_PTR (slice);
+ gpr_uint8 *const end = GPR_SLICE_END_PTR (slice);
gpr_uint8 *cur = beg;
grpc_chttp2_goaway_parser *p = parser;
- switch (p->state) {
+ switch (p->state)
+ {
case GRPC_CHTTP2_GOAWAY_LSI0:
- if (cur == end) {
- p->state = GRPC_CHTTP2_GOAWAY_LSI0;
- return GRPC_CHTTP2_PARSE_OK;
- }
- p->last_stream_id = ((gpr_uint32)*cur) << 24;
+ if (cur == end)
+ {
+ p->state = GRPC_CHTTP2_GOAWAY_LSI0;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ p->last_stream_id = ((gpr_uint32) * cur) << 24;
++cur;
- /* fallthrough */
+ /* fallthrough */
case GRPC_CHTTP2_GOAWAY_LSI1:
- if (cur == end) {
- p->state = GRPC_CHTTP2_GOAWAY_LSI1;
- return GRPC_CHTTP2_PARSE_OK;
- }
- p->last_stream_id |= ((gpr_uint32)*cur) << 16;
+ if (cur == end)
+ {
+ p->state = GRPC_CHTTP2_GOAWAY_LSI1;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ p->last_stream_id |= ((gpr_uint32) * cur) << 16;
++cur;
- /* fallthrough */
+ /* fallthrough */
case GRPC_CHTTP2_GOAWAY_LSI2:
- if (cur == end) {
- p->state = GRPC_CHTTP2_GOAWAY_LSI2;
- return GRPC_CHTTP2_PARSE_OK;
- }
- p->last_stream_id |= ((gpr_uint32)*cur) << 8;
+ if (cur == end)
+ {
+ p->state = GRPC_CHTTP2_GOAWAY_LSI2;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ p->last_stream_id |= ((gpr_uint32) * cur) << 8;
++cur;
- /* fallthrough */
+ /* fallthrough */
case GRPC_CHTTP2_GOAWAY_LSI3:
- if (cur == end) {
- p->state = GRPC_CHTTP2_GOAWAY_LSI3;
- return GRPC_CHTTP2_PARSE_OK;
- }
- p->last_stream_id |= ((gpr_uint32)*cur);
+ if (cur == end)
+ {
+ p->state = GRPC_CHTTP2_GOAWAY_LSI3;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ p->last_stream_id |= ((gpr_uint32) * cur);
++cur;
- /* fallthrough */
+ /* fallthrough */
case GRPC_CHTTP2_GOAWAY_ERR0:
- if (cur == end) {
- p->state = GRPC_CHTTP2_GOAWAY_ERR0;
- return GRPC_CHTTP2_PARSE_OK;
- }
- p->error_code = ((gpr_uint32)*cur) << 24;
+ if (cur == end)
+ {
+ p->state = GRPC_CHTTP2_GOAWAY_ERR0;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ p->error_code = ((gpr_uint32) * cur) << 24;
++cur;
- /* fallthrough */
+ /* fallthrough */
case GRPC_CHTTP2_GOAWAY_ERR1:
- if (cur == end) {
- p->state = GRPC_CHTTP2_GOAWAY_ERR1;
- return GRPC_CHTTP2_PARSE_OK;
- }
- p->error_code |= ((gpr_uint32)*cur) << 16;
+ if (cur == end)
+ {
+ p->state = GRPC_CHTTP2_GOAWAY_ERR1;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ p->error_code |= ((gpr_uint32) * cur) << 16;
++cur;
- /* fallthrough */
+ /* fallthrough */
case GRPC_CHTTP2_GOAWAY_ERR2:
- if (cur == end) {
- p->state = GRPC_CHTTP2_GOAWAY_ERR2;
- return GRPC_CHTTP2_PARSE_OK;
- }
- p->error_code |= ((gpr_uint32)*cur) << 8;
+ if (cur == end)
+ {
+ p->state = GRPC_CHTTP2_GOAWAY_ERR2;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ p->error_code |= ((gpr_uint32) * cur) << 8;
++cur;
- /* fallthrough */
+ /* fallthrough */
case GRPC_CHTTP2_GOAWAY_ERR3:
- if (cur == end) {
- p->state = GRPC_CHTTP2_GOAWAY_ERR3;
- return GRPC_CHTTP2_PARSE_OK;
- }
- p->error_code |= ((gpr_uint32)*cur);
+ if (cur == end)
+ {
+ p->state = GRPC_CHTTP2_GOAWAY_ERR3;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ p->error_code |= ((gpr_uint32) * cur);
++cur;
- /* fallthrough */
+ /* fallthrough */
case GRPC_CHTTP2_GOAWAY_DEBUG:
- memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur));
- GPR_ASSERT(end - cur < GPR_UINT32_MAX - p->debug_pos);
- p->debug_pos += (gpr_uint32)(end - cur);
+ memcpy (p->debug_data + p->debug_pos, cur, (size_t) (end - cur));
+ GPR_ASSERT (end - cur < GPR_UINT32_MAX - p->debug_pos);
+ p->debug_pos += (gpr_uint32) (end - cur);
p->state = GRPC_CHTTP2_GOAWAY_DEBUG;
- if (is_last) {
- transport_parsing->goaway_received = 1;
- transport_parsing->goaway_last_stream_index = p->last_stream_id;
- gpr_slice_unref(transport_parsing->goaway_text);
- transport_parsing->goaway_error = (grpc_status_code)p->error_code;
- transport_parsing->goaway_text =
- gpr_slice_new(p->debug_data, p->debug_length, gpr_free);
- p->debug_data = NULL;
- }
+ if (is_last)
+ {
+ transport_parsing->goaway_received = 1;
+ transport_parsing->goaway_last_stream_index = p->last_stream_id;
+ gpr_slice_unref (transport_parsing->goaway_text);
+ transport_parsing->goaway_error = (grpc_status_code) p->error_code;
+ transport_parsing->goaway_text = gpr_slice_new (p->debug_data, p->debug_length, gpr_free);
+ p->debug_data = NULL;
+ }
return GRPC_CHTTP2_PARSE_OK;
- }
- gpr_log(GPR_ERROR, "Should never end up here");
- abort();
+ }
+ gpr_log (GPR_ERROR, "Should never end up here");
+ abort ();
return GRPC_CHTTP2_CONNECTION_ERROR;
}
-void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code,
- gpr_slice debug_data,
- gpr_slice_buffer *slice_buffer) {
- gpr_slice header = gpr_slice_malloc(9 + 4 + 4);
- gpr_uint8 *p = GPR_SLICE_START_PTR(header);
+void
+grpc_chttp2_goaway_append (gpr_uint32 last_stream_id, gpr_uint32 error_code, gpr_slice debug_data, gpr_slice_buffer * slice_buffer)
+{
+ gpr_slice header = gpr_slice_malloc (9 + 4 + 4);
+ gpr_uint8 *p = GPR_SLICE_START_PTR (header);
gpr_uint32 frame_length;
- GPR_ASSERT(GPR_SLICE_LENGTH(debug_data) < GPR_UINT32_MAX - 4 - 4);
- frame_length = 4 + 4 + (gpr_uint32)GPR_SLICE_LENGTH(debug_data);
+ GPR_ASSERT (GPR_SLICE_LENGTH (debug_data) < GPR_UINT32_MAX - 4 - 4);
+ frame_length = 4 + 4 + (gpr_uint32) GPR_SLICE_LENGTH (debug_data);
/* frame header: length */
- *p++ = (gpr_uint8)(frame_length >> 16);
- *p++ = (gpr_uint8)(frame_length >> 8);
- *p++ = (gpr_uint8)(frame_length);
+ *p++ = (gpr_uint8) (frame_length >> 16);
+ *p++ = (gpr_uint8) (frame_length >> 8);
+ *p++ = (gpr_uint8) (frame_length);
/* frame header: type */
*p++ = GRPC_CHTTP2_FRAME_GOAWAY;
/* frame header: flags */
@@ -180,16 +194,16 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code,
*p++ = 0;
*p++ = 0;
/* payload: last stream id */
- *p++ = (gpr_uint8)(last_stream_id >> 24);
- *p++ = (gpr_uint8)(last_stream_id >> 16);
- *p++ = (gpr_uint8)(last_stream_id >> 8);
- *p++ = (gpr_uint8)(last_stream_id);
+ *p++ = (gpr_uint8) (last_stream_id >> 24);
+ *p++ = (gpr_uint8) (last_stream_id >> 16);
+ *p++ = (gpr_uint8) (last_stream_id >> 8);
+ *p++ = (gpr_uint8) (last_stream_id);
/* payload: error code */
- *p++ = (gpr_uint8)(error_code >> 24);
- *p++ = (gpr_uint8)(error_code >> 16);
- *p++ = (gpr_uint8)(error_code >> 8);
- *p++ = (gpr_uint8)(error_code);
- GPR_ASSERT(p == GPR_SLICE_END_PTR(header));
- gpr_slice_buffer_add(slice_buffer, header);
- gpr_slice_buffer_add(slice_buffer, debug_data);
+ *p++ = (gpr_uint8) (error_code >> 24);
+ *p++ = (gpr_uint8) (error_code >> 16);
+ *p++ = (gpr_uint8) (error_code >> 8);
+ *p++ = (gpr_uint8) (error_code);
+ GPR_ASSERT (p == GPR_SLICE_END_PTR (header));
+ gpr_slice_buffer_add (slice_buffer, header);
+ gpr_slice_buffer_add (slice_buffer, debug_data);
}
diff --git a/src/core/transport/chttp2/frame_goaway.h b/src/core/transport/chttp2/frame_goaway.h
index e45d55418c..7cacec5f94 100644
--- a/src/core/transport/chttp2/frame_goaway.h
+++ b/src/core/transport/chttp2/frame_goaway.h
@@ -40,7 +40,8 @@
#include <grpc/support/slice.h>
#include <grpc/support/slice_buffer.h>
-typedef enum {
+typedef enum
+{
GRPC_CHTTP2_GOAWAY_LSI0,
GRPC_CHTTP2_GOAWAY_LSI1,
GRPC_CHTTP2_GOAWAY_LSI2,
@@ -52,7 +53,8 @@ typedef enum {
GRPC_CHTTP2_GOAWAY_DEBUG
} grpc_chttp2_goaway_parse_state;
-typedef struct {
+typedef struct
+{
grpc_chttp2_goaway_parse_state state;
gpr_uint32 last_stream_id;
gpr_uint32 error_code;
@@ -61,17 +63,11 @@ typedef struct {
gpr_uint32 debug_pos;
} grpc_chttp2_goaway_parser;
-void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser *p);
-void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser *p);
-grpc_chttp2_parse_error grpc_chttp2_goaway_parser_begin_frame(
- grpc_chttp2_goaway_parser *parser, gpr_uint32 length, gpr_uint8 flags);
-grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list);
+void grpc_chttp2_goaway_parser_init (grpc_chttp2_goaway_parser * p);
+void grpc_chttp2_goaway_parser_destroy (grpc_chttp2_goaway_parser * p);
+grpc_chttp2_parse_error grpc_chttp2_goaway_parser_begin_frame (grpc_chttp2_goaway_parser * parser, gpr_uint32 length, gpr_uint8 flags);
+grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list);
-void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code,
- gpr_slice debug_data,
- gpr_slice_buffer *slice_buffer);
+void grpc_chttp2_goaway_append (gpr_uint32 last_stream_id, gpr_uint32 error_code, gpr_slice debug_data, gpr_slice_buffer * slice_buffer);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_GOAWAY_H */
diff --git a/src/core/transport/chttp2/frame_ping.c b/src/core/transport/chttp2/frame_ping.c
index d4bf43eb37..6cd1fae1a6 100644
--- a/src/core/transport/chttp2/frame_ping.c
+++ b/src/core/transport/chttp2/frame_ping.c
@@ -39,9 +39,11 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-gpr_slice grpc_chttp2_ping_create(gpr_uint8 ack, gpr_uint8 *opaque_8bytes) {
- gpr_slice slice = gpr_slice_malloc(9 + 8);
- gpr_uint8 *p = GPR_SLICE_START_PTR(slice);
+gpr_slice
+grpc_chttp2_ping_create (gpr_uint8 ack, gpr_uint8 * opaque_8bytes)
+{
+ gpr_slice slice = gpr_slice_malloc (9 + 8);
+ gpr_uint8 *p = GPR_SLICE_START_PTR (slice);
*p++ = 0;
*p++ = 0;
@@ -52,55 +54,61 @@ gpr_slice grpc_chttp2_ping_create(gpr_uint8 ack, gpr_uint8 *opaque_8bytes) {
*p++ = 0;
*p++ = 0;
*p++ = 0;
- memcpy(p, opaque_8bytes, 8);
+ memcpy (p, opaque_8bytes, 8);
return slice;
}
-grpc_chttp2_parse_error grpc_chttp2_ping_parser_begin_frame(
- grpc_chttp2_ping_parser *parser, gpr_uint32 length, gpr_uint8 flags) {
- if (flags & 0xfe || length != 8) {
- gpr_log(GPR_ERROR, "invalid ping: length=%d, flags=%02x", length, flags);
- return GRPC_CHTTP2_CONNECTION_ERROR;
- }
+grpc_chttp2_parse_error
+grpc_chttp2_ping_parser_begin_frame (grpc_chttp2_ping_parser * parser, gpr_uint32 length, gpr_uint8 flags)
+{
+ if (flags & 0xfe || length != 8)
+ {
+ gpr_log (GPR_ERROR, "invalid ping: length=%d, flags=%02x", length, flags);
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
parser->byte = 0;
parser->is_ack = flags;
return GRPC_CHTTP2_PARSE_OK;
}
-grpc_chttp2_parse_error grpc_chttp2_ping_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list) {
- gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice);
- gpr_uint8 *const end = GPR_SLICE_END_PTR(slice);
+grpc_chttp2_parse_error
+grpc_chttp2_ping_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list)
+{
+ gpr_uint8 *const beg = GPR_SLICE_START_PTR (slice);
+ gpr_uint8 *const end = GPR_SLICE_END_PTR (slice);
gpr_uint8 *cur = beg;
grpc_chttp2_ping_parser *p = parser;
grpc_chttp2_outstanding_ping *ping;
- while (p->byte != 8 && cur != end) {
- p->opaque_8bytes[p->byte] = *cur;
- cur++;
- p->byte++;
- }
+ while (p->byte != 8 && cur != end)
+ {
+ p->opaque_8bytes[p->byte] = *cur;
+ cur++;
+ p->byte++;
+ }
- if (p->byte == 8) {
- GPR_ASSERT(is_last);
- if (p->is_ack) {
- for (ping = transport_parsing->pings.next;
- ping != &transport_parsing->pings; ping = ping->next) {
- if (0 == memcmp(p->opaque_8bytes, ping->id, 8)) {
- grpc_closure_list_add(closure_list, ping->on_recv, 1);
- }
- ping->next->prev = ping->prev;
- ping->prev->next = ping->next;
- gpr_free(ping);
- }
- } else {
- gpr_slice_buffer_add(&transport_parsing->qbuf,
- grpc_chttp2_ping_create(1, p->opaque_8bytes));
+ if (p->byte == 8)
+ {
+ GPR_ASSERT (is_last);
+ if (p->is_ack)
+ {
+ for (ping = transport_parsing->pings.next; ping != &transport_parsing->pings; ping = ping->next)
+ {
+ if (0 == memcmp (p->opaque_8bytes, ping->id, 8))
+ {
+ grpc_closure_list_add (closure_list, ping->on_recv, 1);
+ }
+ ping->next->prev = ping->prev;
+ ping->prev->next = ping->next;
+ gpr_free (ping);
+ }
+ }
+ else
+ {
+ gpr_slice_buffer_add (&transport_parsing->qbuf, grpc_chttp2_ping_create (1, p->opaque_8bytes));
+ }
}
- }
return GRPC_CHTTP2_PARSE_OK;
}
diff --git a/src/core/transport/chttp2/frame_ping.h b/src/core/transport/chttp2/frame_ping.h
index 4224002904..65a666bc18 100644
--- a/src/core/transport/chttp2/frame_ping.h
+++ b/src/core/transport/chttp2/frame_ping.h
@@ -38,19 +38,16 @@
#include <grpc/support/slice.h>
#include "src/core/transport/chttp2/frame.h"
-typedef struct {
+typedef struct
+{
gpr_uint8 byte;
gpr_uint8 is_ack;
gpr_uint8 opaque_8bytes[8];
} grpc_chttp2_ping_parser;
-gpr_slice grpc_chttp2_ping_create(gpr_uint8 ack, gpr_uint8 *opaque_8bytes);
+gpr_slice grpc_chttp2_ping_create (gpr_uint8 ack, gpr_uint8 * opaque_8bytes);
-grpc_chttp2_parse_error grpc_chttp2_ping_parser_begin_frame(
- grpc_chttp2_ping_parser *parser, gpr_uint32 length, gpr_uint8 flags);
-grpc_chttp2_parse_error grpc_chttp2_ping_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list);
+grpc_chttp2_parse_error grpc_chttp2_ping_parser_begin_frame (grpc_chttp2_ping_parser * parser, gpr_uint32 length, gpr_uint8 flags);
+grpc_chttp2_parse_error grpc_chttp2_ping_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_PING_H */
diff --git a/src/core/transport/chttp2/frame_rst_stream.c b/src/core/transport/chttp2/frame_rst_stream.c
index 4d8323c11d..c4bca3e680 100644
--- a/src/core/transport/chttp2/frame_rst_stream.c
+++ b/src/core/transport/chttp2/frame_rst_stream.c
@@ -38,63 +38,63 @@
#include "src/core/transport/chttp2/frame.h"
-gpr_slice grpc_chttp2_rst_stream_create(gpr_uint32 id, gpr_uint32 code) {
- gpr_slice slice = gpr_slice_malloc(13);
- gpr_uint8 *p = GPR_SLICE_START_PTR(slice);
+gpr_slice
+grpc_chttp2_rst_stream_create (gpr_uint32 id, gpr_uint32 code)
+{
+ gpr_slice slice = gpr_slice_malloc (13);
+ gpr_uint8 *p = GPR_SLICE_START_PTR (slice);
*p++ = 0;
*p++ = 0;
*p++ = 4;
*p++ = GRPC_CHTTP2_FRAME_RST_STREAM;
*p++ = 0;
- *p++ = (gpr_uint8)(id >> 24);
- *p++ = (gpr_uint8)(id >> 16);
- *p++ = (gpr_uint8)(id >> 8);
- *p++ = (gpr_uint8)(id);
- *p++ = (gpr_uint8)(code >> 24);
- *p++ = (gpr_uint8)(code >> 16);
- *p++ = (gpr_uint8)(code >> 8);
- *p++ = (gpr_uint8)(code);
+ *p++ = (gpr_uint8) (id >> 24);
+ *p++ = (gpr_uint8) (id >> 16);
+ *p++ = (gpr_uint8) (id >> 8);
+ *p++ = (gpr_uint8) (id);
+ *p++ = (gpr_uint8) (code >> 24);
+ *p++ = (gpr_uint8) (code >> 16);
+ *p++ = (gpr_uint8) (code >> 8);
+ *p++ = (gpr_uint8) (code);
return slice;
}
-grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_begin_frame(
- grpc_chttp2_rst_stream_parser *parser, gpr_uint32 length, gpr_uint8 flags) {
- if (length != 4) {
- gpr_log(GPR_ERROR, "invalid rst_stream: length=%d, flags=%02x", length,
- flags);
- return GRPC_CHTTP2_CONNECTION_ERROR;
- }
+grpc_chttp2_parse_error
+grpc_chttp2_rst_stream_parser_begin_frame (grpc_chttp2_rst_stream_parser * parser, gpr_uint32 length, gpr_uint8 flags)
+{
+ if (length != 4)
+ {
+ gpr_log (GPR_ERROR, "invalid rst_stream: length=%d, flags=%02x", length, flags);
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
parser->byte = 0;
return GRPC_CHTTP2_PARSE_OK;
}
-grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list) {
- gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice);
- gpr_uint8 *const end = GPR_SLICE_END_PTR(slice);
+grpc_chttp2_parse_error
+grpc_chttp2_rst_stream_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list)
+{
+ gpr_uint8 *const beg = GPR_SLICE_START_PTR (slice);
+ gpr_uint8 *const end = GPR_SLICE_END_PTR (slice);
gpr_uint8 *cur = beg;
grpc_chttp2_rst_stream_parser *p = parser;
- while (p->byte != 4 && cur != end) {
- p->reason_bytes[p->byte] = *cur;
- cur++;
- p->byte++;
- }
+ while (p->byte != 4 && cur != end)
+ {
+ p->reason_bytes[p->byte] = *cur;
+ cur++;
+ p->byte++;
+ }
- if (p->byte == 4) {
- GPR_ASSERT(is_last);
- stream_parsing->received_close = 1;
- stream_parsing->saw_rst_stream = 1;
- stream_parsing->rst_stream_reason =
- (((gpr_uint32)p->reason_bytes[0]) << 24) |
- (((gpr_uint32)p->reason_bytes[1]) << 16) |
- (((gpr_uint32)p->reason_bytes[2]) << 8) |
- (((gpr_uint32)p->reason_bytes[3]));
- }
+ if (p->byte == 4)
+ {
+ GPR_ASSERT (is_last);
+ stream_parsing->received_close = 1;
+ stream_parsing->saw_rst_stream = 1;
+ stream_parsing->rst_stream_reason = (((gpr_uint32) p->reason_bytes[0]) << 24) | (((gpr_uint32) p->reason_bytes[1]) << 16) | (((gpr_uint32) p->reason_bytes[2]) << 8) | (((gpr_uint32) p->reason_bytes[3]));
+ }
return GRPC_CHTTP2_PARSE_OK;
}
diff --git a/src/core/transport/chttp2/frame_rst_stream.h b/src/core/transport/chttp2/frame_rst_stream.h
index 5d660968ad..781f4e5743 100644
--- a/src/core/transport/chttp2/frame_rst_stream.h
+++ b/src/core/transport/chttp2/frame_rst_stream.h
@@ -38,18 +38,15 @@
#include "src/core/transport/chttp2/frame.h"
#include "src/core/iomgr/exec_ctx.h"
-typedef struct {
+typedef struct
+{
gpr_uint8 byte;
gpr_uint8 reason_bytes[4];
} grpc_chttp2_rst_stream_parser;
-gpr_slice grpc_chttp2_rst_stream_create(gpr_uint32 stream_id, gpr_uint32 code);
+gpr_slice grpc_chttp2_rst_stream_create (gpr_uint32 stream_id, gpr_uint32 code);
-grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_begin_frame(
- grpc_chttp2_rst_stream_parser *parser, gpr_uint32 length, gpr_uint8 flags);
-grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list);
+grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_begin_frame (grpc_chttp2_rst_stream_parser * parser, gpr_uint32 length, gpr_uint8 flags);
+grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_RST_STREAM_H */
diff --git a/src/core/transport/chttp2/frame_settings.c b/src/core/transport/chttp2/frame_settings.c
index 235ff5a352..7f2d5ba3fe 100644
--- a/src/core/transport/chttp2/frame_settings.c
+++ b/src/core/transport/chttp2/frame_settings.c
@@ -43,27 +43,27 @@
#include <grpc/support/useful.h>
/* HTTP/2 mandated initial connection settings */
-const grpc_chttp2_setting_parameters
- grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS] = {
- {NULL, 0, 0, 0, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
- {"HEADER_TABLE_SIZE", 4096, 0, 0xffffffff,
- GRPC_CHTTP2_CLAMP_INVALID_VALUE},
- {"ENABLE_PUSH", 1, 0, 1, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
- {"MAX_CONCURRENT_STREAMS", 0xffffffffu, 0, 0xffffffffu,
- GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
- {"INITIAL_WINDOW_SIZE", 65535, 0, 0xffffffffu,
- GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
- {"MAX_FRAME_SIZE", 16384, 16384, 16777215,
- GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
- {"MAX_HEADER_LIST_SIZE", 0xffffffffu, 0, 0xffffffffu,
- GRPC_CHTTP2_CLAMP_INVALID_VALUE},
+const grpc_chttp2_setting_parameters grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS] = {
+ {NULL, 0, 0, 0, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
+ {"HEADER_TABLE_SIZE", 4096, 0, 0xffffffff,
+ GRPC_CHTTP2_CLAMP_INVALID_VALUE},
+ {"ENABLE_PUSH", 1, 0, 1, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
+ {"MAX_CONCURRENT_STREAMS", 0xffffffffu, 0, 0xffffffffu,
+ GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
+ {"INITIAL_WINDOW_SIZE", 65535, 0, 0xffffffffu,
+ GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
+ {"MAX_FRAME_SIZE", 16384, 16384, 16777215,
+ GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
+ {"MAX_HEADER_LIST_SIZE", 0xffffffffu, 0, 0xffffffffu,
+ GRPC_CHTTP2_CLAMP_INVALID_VALUE},
};
-static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length,
- gpr_uint8 flags) {
- *out++ = (gpr_uint8)(length >> 16);
- *out++ = (gpr_uint8)(length >> 8);
- *out++ = (gpr_uint8)(length);
+static gpr_uint8 *
+fill_header (gpr_uint8 * out, gpr_uint32 length, gpr_uint8 flags)
+{
+ *out++ = (gpr_uint8) (length >> 16);
+ *out++ = (gpr_uint8) (length >> 8);
+ *out++ = (gpr_uint8) (length);
*out++ = GRPC_CHTTP2_FRAME_SETTINGS;
*out++ = flags;
*out++ = 0;
@@ -73,175 +73,194 @@ static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length,
return out;
}
-gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new,
- gpr_uint32 force_mask, size_t count) {
+gpr_slice
+grpc_chttp2_settings_create (gpr_uint32 * old, const gpr_uint32 * new, gpr_uint32 force_mask, size_t count)
+{
size_t i;
gpr_uint32 n = 0;
gpr_slice output;
gpr_uint8 *p;
- for (i = 0; i < count; i++) {
- n += (new[i] != old[i] || (force_mask & (1u << i)) != 0);
- }
-
- output = gpr_slice_malloc(9 + 6 * n);
- p = fill_header(GPR_SLICE_START_PTR(output), 6 * n, 0);
-
- for (i = 0; i < count; i++) {
- if (new[i] != old[i] || (force_mask & (1u << i)) != 0) {
- GPR_ASSERT(i);
- *p++ = (gpr_uint8)(i >> 8);
- *p++ = (gpr_uint8)(i);
- *p++ = (gpr_uint8)(new[i] >> 24);
- *p++ = (gpr_uint8)(new[i] >> 16);
- *p++ = (gpr_uint8)(new[i] >> 8);
- *p++ = (gpr_uint8)(new[i]);
- old[i] = new[i];
+ for (i = 0; i < count; i++)
+ {
+ n += (new[i] != old[i] || (force_mask & (1u << i)) != 0);
}
- }
- GPR_ASSERT(p == GPR_SLICE_END_PTR(output));
+ output = gpr_slice_malloc (9 + 6 * n);
+ p = fill_header (GPR_SLICE_START_PTR (output), 6 * n, 0);
+
+ for (i = 0; i < count; i++)
+ {
+ if (new[i] != old[i] || (force_mask & (1u << i)) != 0)
+ {
+ GPR_ASSERT (i);
+ *p++ = (gpr_uint8) (i >> 8);
+ *p++ = (gpr_uint8) (i);
+ *p++ = (gpr_uint8) (new[i] >> 24);
+ *p++ = (gpr_uint8) (new[i] >> 16);
+ *p++ = (gpr_uint8) (new[i] >> 8);
+ *p++ = (gpr_uint8) (new[i]);
+ old[i] = new[i];
+ }
+ }
+
+ GPR_ASSERT (p == GPR_SLICE_END_PTR (output));
return output;
}
-gpr_slice grpc_chttp2_settings_ack_create(void) {
- gpr_slice output = gpr_slice_malloc(9);
- fill_header(GPR_SLICE_START_PTR(output), 0, GRPC_CHTTP2_FLAG_ACK);
+gpr_slice
+grpc_chttp2_settings_ack_create (void)
+{
+ gpr_slice output = gpr_slice_malloc (9);
+ fill_header (GPR_SLICE_START_PTR (output), 0, GRPC_CHTTP2_FLAG_ACK);
return output;
}
-grpc_chttp2_parse_error grpc_chttp2_settings_parser_begin_frame(
- grpc_chttp2_settings_parser *parser, gpr_uint32 length, gpr_uint8 flags,
- gpr_uint32 *settings) {
+grpc_chttp2_parse_error
+grpc_chttp2_settings_parser_begin_frame (grpc_chttp2_settings_parser * parser, gpr_uint32 length, gpr_uint8 flags, gpr_uint32 * settings)
+{
parser->target_settings = settings;
- memcpy(parser->incoming_settings, settings,
- GRPC_CHTTP2_NUM_SETTINGS * sizeof(gpr_uint32));
+ memcpy (parser->incoming_settings, settings, GRPC_CHTTP2_NUM_SETTINGS * sizeof (gpr_uint32));
parser->is_ack = 0;
parser->state = GRPC_CHTTP2_SPS_ID0;
- if (flags == GRPC_CHTTP2_FLAG_ACK) {
- parser->is_ack = 1;
- if (length != 0) {
- gpr_log(GPR_ERROR, "non-empty settings ack frame received");
+ if (flags == GRPC_CHTTP2_FLAG_ACK)
+ {
+ parser->is_ack = 1;
+ if (length != 0)
+ {
+ gpr_log (GPR_ERROR, "non-empty settings ack frame received");
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ else if (flags != 0)
+ {
+ gpr_log (GPR_ERROR, "invalid flags on settings frame");
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
+ else if (length % 6 != 0)
+ {
+ gpr_log (GPR_ERROR, "settings frames must be a multiple of six bytes");
return GRPC_CHTTP2_CONNECTION_ERROR;
}
- return GRPC_CHTTP2_PARSE_OK;
- } else if (flags != 0) {
- gpr_log(GPR_ERROR, "invalid flags on settings frame");
- return GRPC_CHTTP2_CONNECTION_ERROR;
- } else if (length % 6 != 0) {
- gpr_log(GPR_ERROR, "settings frames must be a multiple of six bytes");
- return GRPC_CHTTP2_CONNECTION_ERROR;
- } else {
- return GRPC_CHTTP2_PARSE_OK;
- }
+ else
+ {
+ return GRPC_CHTTP2_PARSE_OK;
+ }
}
-grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
- void *p, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list) {
+grpc_chttp2_parse_error
+grpc_chttp2_settings_parser_parse (void *p, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list)
+{
grpc_chttp2_settings_parser *parser = p;
- const gpr_uint8 *cur = GPR_SLICE_START_PTR(slice);
- const gpr_uint8 *end = GPR_SLICE_END_PTR(slice);
-
- if (parser->is_ack) {
- return GRPC_CHTTP2_PARSE_OK;
- }
-
- for (;;) {
- switch (parser->state) {
- case GRPC_CHTTP2_SPS_ID0:
- if (cur == end) {
- parser->state = GRPC_CHTTP2_SPS_ID0;
- if (is_last) {
- transport_parsing->settings_updated = 1;
- memcpy(parser->target_settings, parser->incoming_settings,
- GRPC_CHTTP2_NUM_SETTINGS * sizeof(gpr_uint32));
- gpr_slice_buffer_add(&transport_parsing->qbuf,
- grpc_chttp2_settings_ack_create());
- }
- return GRPC_CHTTP2_PARSE_OK;
- }
- parser->id = (gpr_uint16)(((gpr_uint16)*cur) << 8);
- cur++;
- /* fallthrough */
- case GRPC_CHTTP2_SPS_ID1:
- if (cur == end) {
- parser->state = GRPC_CHTTP2_SPS_ID1;
- return GRPC_CHTTP2_PARSE_OK;
- }
- parser->id = (gpr_uint16)(parser->id | (*cur));
- cur++;
- /* fallthrough */
- case GRPC_CHTTP2_SPS_VAL0:
- if (cur == end) {
- parser->state = GRPC_CHTTP2_SPS_VAL0;
- return GRPC_CHTTP2_PARSE_OK;
- }
- parser->value = ((gpr_uint32)*cur) << 24;
- cur++;
- /* fallthrough */
- case GRPC_CHTTP2_SPS_VAL1:
- if (cur == end) {
- parser->state = GRPC_CHTTP2_SPS_VAL1;
- return GRPC_CHTTP2_PARSE_OK;
- }
- parser->value |= ((gpr_uint32)*cur) << 16;
- cur++;
- /* fallthrough */
- case GRPC_CHTTP2_SPS_VAL2:
- if (cur == end) {
- parser->state = GRPC_CHTTP2_SPS_VAL2;
- return GRPC_CHTTP2_PARSE_OK;
- }
- parser->value |= ((gpr_uint32)*cur) << 8;
- cur++;
- /* fallthrough */
- case GRPC_CHTTP2_SPS_VAL3:
- if (cur == end) {
- parser->state = GRPC_CHTTP2_SPS_VAL3;
- return GRPC_CHTTP2_PARSE_OK;
- } else {
- parser->state = GRPC_CHTTP2_SPS_ID0;
- }
- parser->value |= *cur;
- cur++;
-
- if (parser->id > 0 && parser->id < GRPC_CHTTP2_NUM_SETTINGS) {
- const grpc_chttp2_setting_parameters *sp =
- &grpc_chttp2_settings_parameters[parser->id];
- if (parser->value < sp->min_value || parser->value > sp->max_value) {
- switch (sp->invalid_value_behavior) {
- case GRPC_CHTTP2_CLAMP_INVALID_VALUE:
- parser->value =
- GPR_CLAMP(parser->value, sp->min_value, sp->max_value);
- break;
- case GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE:
- gpr_log(GPR_ERROR, "invalid value %u passed for %s",
- parser->value, sp->name);
- return GRPC_CHTTP2_CONNECTION_ERROR;
- }
- }
- if (parser->id == GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE &&
- parser->incoming_settings[parser->id] != parser->value) {
- transport_parsing->initial_window_update =
- (gpr_int64)parser->value -
- parser->incoming_settings[parser->id];
- gpr_log(GPR_DEBUG, "adding %d for initial_window change",
- (int)transport_parsing->initial_window_update);
- }
- parser->incoming_settings[parser->id] = parser->value;
- if (grpc_http_trace) {
- gpr_log(GPR_DEBUG, "CHTTP2:%s: got setting %d = %d",
- transport_parsing->is_client ? "CLI" : "SVR", parser->id,
- parser->value);
- }
- } else {
- gpr_log(GPR_ERROR, "CHTTP2: Ignoring unknown setting %d (value %d)",
- parser->id, parser->value);
- }
- break;
+ const gpr_uint8 *cur = GPR_SLICE_START_PTR (slice);
+ const gpr_uint8 *end = GPR_SLICE_END_PTR (slice);
+
+ if (parser->is_ack)
+ {
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+
+ for (;;)
+ {
+ switch (parser->state)
+ {
+ case GRPC_CHTTP2_SPS_ID0:
+ if (cur == end)
+ {
+ parser->state = GRPC_CHTTP2_SPS_ID0;
+ if (is_last)
+ {
+ transport_parsing->settings_updated = 1;
+ memcpy (parser->target_settings, parser->incoming_settings, GRPC_CHTTP2_NUM_SETTINGS * sizeof (gpr_uint32));
+ gpr_slice_buffer_add (&transport_parsing->qbuf, grpc_chttp2_settings_ack_create ());
+ }
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ parser->id = (gpr_uint16) (((gpr_uint16) * cur) << 8);
+ cur++;
+ /* fallthrough */
+ case GRPC_CHTTP2_SPS_ID1:
+ if (cur == end)
+ {
+ parser->state = GRPC_CHTTP2_SPS_ID1;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ parser->id = (gpr_uint16) (parser->id | (*cur));
+ cur++;
+ /* fallthrough */
+ case GRPC_CHTTP2_SPS_VAL0:
+ if (cur == end)
+ {
+ parser->state = GRPC_CHTTP2_SPS_VAL0;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ parser->value = ((gpr_uint32) * cur) << 24;
+ cur++;
+ /* fallthrough */
+ case GRPC_CHTTP2_SPS_VAL1:
+ if (cur == end)
+ {
+ parser->state = GRPC_CHTTP2_SPS_VAL1;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ parser->value |= ((gpr_uint32) * cur) << 16;
+ cur++;
+ /* fallthrough */
+ case GRPC_CHTTP2_SPS_VAL2:
+ if (cur == end)
+ {
+ parser->state = GRPC_CHTTP2_SPS_VAL2;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ parser->value |= ((gpr_uint32) * cur) << 8;
+ cur++;
+ /* fallthrough */
+ case GRPC_CHTTP2_SPS_VAL3:
+ if (cur == end)
+ {
+ parser->state = GRPC_CHTTP2_SPS_VAL3;
+ return GRPC_CHTTP2_PARSE_OK;
+ }
+ else
+ {
+ parser->state = GRPC_CHTTP2_SPS_ID0;
+ }
+ parser->value |= *cur;
+ cur++;
+
+ if (parser->id > 0 && parser->id < GRPC_CHTTP2_NUM_SETTINGS)
+ {
+ const grpc_chttp2_setting_parameters *sp = &grpc_chttp2_settings_parameters[parser->id];
+ if (parser->value < sp->min_value || parser->value > sp->max_value)
+ {
+ switch (sp->invalid_value_behavior)
+ {
+ case GRPC_CHTTP2_CLAMP_INVALID_VALUE:
+ parser->value = GPR_CLAMP (parser->value, sp->min_value, sp->max_value);
+ break;
+ case GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE:
+ gpr_log (GPR_ERROR, "invalid value %u passed for %s", parser->value, sp->name);
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
+ }
+ if (parser->id == GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE && parser->incoming_settings[parser->id] != parser->value)
+ {
+ transport_parsing->initial_window_update = (gpr_int64) parser->value - parser->incoming_settings[parser->id];
+ gpr_log (GPR_DEBUG, "adding %d for initial_window change", (int) transport_parsing->initial_window_update);
+ }
+ parser->incoming_settings[parser->id] = parser->value;
+ if (grpc_http_trace)
+ {
+ gpr_log (GPR_DEBUG, "CHTTP2:%s: got setting %d = %d", transport_parsing->is_client ? "CLI" : "SVR", parser->id, parser->value);
+ }
+ }
+ else
+ {
+ gpr_log (GPR_ERROR, "CHTTP2: Ignoring unknown setting %d (value %d)", parser->id, parser->value);
+ }
+ break;
+ }
}
- }
}
diff --git a/src/core/transport/chttp2/frame_settings.h b/src/core/transport/chttp2/frame_settings.h
index f08d527d38..36c2c1d6d4 100644
--- a/src/core/transport/chttp2/frame_settings.h
+++ b/src/core/transport/chttp2/frame_settings.h
@@ -39,7 +39,8 @@
#include "src/core/transport/chttp2/frame.h"
#include "src/core/iomgr/exec_ctx.h"
-typedef enum {
+typedef enum
+{
GRPC_CHTTP2_SPS_ID0,
GRPC_CHTTP2_SPS_ID1,
GRPC_CHTTP2_SPS_VAL0,
@@ -49,7 +50,8 @@ typedef enum {
} grpc_chttp2_settings_parse_state;
/* The things HTTP/2 defines as connection level settings */
-typedef enum {
+typedef enum
+{
GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE = 1,
GRPC_CHTTP2_SETTINGS_ENABLE_PUSH = 2,
GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 3,
@@ -59,7 +61,8 @@ typedef enum {
GRPC_CHTTP2_NUM_SETTINGS
} grpc_chttp2_setting_id;
-typedef struct {
+typedef struct
+{
grpc_chttp2_settings_parse_state state;
gpr_uint32 *target_settings;
gpr_uint8 is_ack;
@@ -68,12 +71,14 @@ typedef struct {
gpr_uint32 incoming_settings[GRPC_CHTTP2_NUM_SETTINGS];
} grpc_chttp2_settings_parser;
-typedef enum {
+typedef enum
+{
GRPC_CHTTP2_CLAMP_INVALID_VALUE,
GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE
} grpc_chttp2_invalid_value_behavior;
-typedef struct {
+typedef struct
+{
const char *name;
gpr_uint32 default_value;
gpr_uint32 min_value;
@@ -82,21 +87,14 @@ typedef struct {
} grpc_chttp2_setting_parameters;
/* HTTP/2 mandated connection setting parameters */
-extern const grpc_chttp2_setting_parameters
- grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS];
+extern const grpc_chttp2_setting_parameters grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS];
/* Create a settings frame by diffing old & new, and updating old to be new */
-gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new,
- gpr_uint32 force_mask, size_t count);
+gpr_slice grpc_chttp2_settings_create (gpr_uint32 * old, const gpr_uint32 * new, gpr_uint32 force_mask, size_t count);
/* Create an ack settings frame */
-gpr_slice grpc_chttp2_settings_ack_create(void);
+gpr_slice grpc_chttp2_settings_ack_create (void);
-grpc_chttp2_parse_error grpc_chttp2_settings_parser_begin_frame(
- grpc_chttp2_settings_parser *parser, gpr_uint32 length, gpr_uint8 flags,
- gpr_uint32 *settings);
-grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list);
+grpc_chttp2_parse_error grpc_chttp2_settings_parser_begin_frame (grpc_chttp2_settings_parser * parser, gpr_uint32 length, gpr_uint8 flags, gpr_uint32 * settings);
+grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_SETTINGS_H */
diff --git a/src/core/transport/chttp2/frame_window_update.c b/src/core/transport/chttp2/frame_window_update.c
index b0f5f8698b..e18fc1f694 100644
--- a/src/core/transport/chttp2/frame_window_update.c
+++ b/src/core/transport/chttp2/frame_window_update.c
@@ -36,80 +36,83 @@
#include <grpc/support/log.h>
-gpr_slice grpc_chttp2_window_update_create(gpr_uint32 id,
- gpr_uint32 window_update) {
- gpr_slice slice = gpr_slice_malloc(13);
- gpr_uint8 *p = GPR_SLICE_START_PTR(slice);
+gpr_slice
+grpc_chttp2_window_update_create (gpr_uint32 id, gpr_uint32 window_update)
+{
+ gpr_slice slice = gpr_slice_malloc (13);
+ gpr_uint8 *p = GPR_SLICE_START_PTR (slice);
- GPR_ASSERT(window_update);
+ GPR_ASSERT (window_update);
*p++ = 0;
*p++ = 0;
*p++ = 4;
*p++ = GRPC_CHTTP2_FRAME_WINDOW_UPDATE;
*p++ = 0;
- *p++ = (gpr_uint8)(id >> 24);
- *p++ = (gpr_uint8)(id >> 16);
- *p++ = (gpr_uint8)(id >> 8);
- *p++ = (gpr_uint8)(id);
- *p++ = (gpr_uint8)(window_update >> 24);
- *p++ = (gpr_uint8)(window_update >> 16);
- *p++ = (gpr_uint8)(window_update >> 8);
- *p++ = (gpr_uint8)(window_update);
+ *p++ = (gpr_uint8) (id >> 24);
+ *p++ = (gpr_uint8) (id >> 16);
+ *p++ = (gpr_uint8) (id >> 8);
+ *p++ = (gpr_uint8) (id);
+ *p++ = (gpr_uint8) (window_update >> 24);
+ *p++ = (gpr_uint8) (window_update >> 16);
+ *p++ = (gpr_uint8) (window_update >> 8);
+ *p++ = (gpr_uint8) (window_update);
return slice;
}
-grpc_chttp2_parse_error grpc_chttp2_window_update_parser_begin_frame(
- grpc_chttp2_window_update_parser *parser, gpr_uint32 length,
- gpr_uint8 flags) {
- if (flags || length != 4) {
- gpr_log(GPR_ERROR, "invalid window update: length=%d, flags=%02x", length,
- flags);
- return GRPC_CHTTP2_CONNECTION_ERROR;
- }
+grpc_chttp2_parse_error
+grpc_chttp2_window_update_parser_begin_frame (grpc_chttp2_window_update_parser * parser, gpr_uint32 length, gpr_uint8 flags)
+{
+ if (flags || length != 4)
+ {
+ gpr_log (GPR_ERROR, "invalid window update: length=%d, flags=%02x", length, flags);
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
parser->byte = 0;
parser->amount = 0;
return GRPC_CHTTP2_PARSE_OK;
}
-grpc_chttp2_parse_error grpc_chttp2_window_update_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list) {
- gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice);
- gpr_uint8 *const end = GPR_SLICE_END_PTR(slice);
+grpc_chttp2_parse_error
+grpc_chttp2_window_update_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list)
+{
+ gpr_uint8 *const beg = GPR_SLICE_START_PTR (slice);
+ gpr_uint8 *const end = GPR_SLICE_END_PTR (slice);
gpr_uint8 *cur = beg;
grpc_chttp2_window_update_parser *p = parser;
- while (p->byte != 4 && cur != end) {
- p->amount |= ((gpr_uint32)*cur) << (8 * (3 - p->byte));
- cur++;
- p->byte++;
- }
-
- if (p->byte == 4) {
- if (p->amount == 0 || (p->amount & 0x80000000u)) {
- gpr_log(GPR_ERROR, "invalid window update bytes: %d", p->amount);
- return GRPC_CHTTP2_CONNECTION_ERROR;
+ while (p->byte != 4 && cur != end)
+ {
+ p->amount |= ((gpr_uint32) * cur) << (8 * (3 - p->byte));
+ cur++;
+ p->byte++;
}
- GPR_ASSERT(is_last);
- if (transport_parsing->incoming_stream_id != 0) {
- if (stream_parsing != NULL) {
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("update", transport_parsing,
- stream_parsing, outgoing_window_update,
- p->amount);
- stream_parsing->outgoing_window_update += p->amount;
- grpc_chttp2_list_add_parsing_seen_stream(transport_parsing,
- stream_parsing);
- }
- } else {
- GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT("update", transport_parsing,
- outgoing_window_update, p->amount);
- transport_parsing->outgoing_window_update += p->amount;
+ if (p->byte == 4)
+ {
+ if (p->amount == 0 || (p->amount & 0x80000000u))
+ {
+ gpr_log (GPR_ERROR, "invalid window update bytes: %d", p->amount);
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
+ GPR_ASSERT (is_last);
+
+ if (transport_parsing->incoming_stream_id != 0)
+ {
+ if (stream_parsing != NULL)
+ {
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("update", transport_parsing, stream_parsing, outgoing_window_update, p->amount);
+ stream_parsing->outgoing_window_update += p->amount;
+ grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing);
+ }
+ }
+ else
+ {
+ GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("update", transport_parsing, outgoing_window_update, p->amount);
+ transport_parsing->outgoing_window_update += p->amount;
+ }
}
- }
return GRPC_CHTTP2_PARSE_OK;
}
diff --git a/src/core/transport/chttp2/frame_window_update.h b/src/core/transport/chttp2/frame_window_update.h
index b8fe9095b7..57d77b41cf 100644
--- a/src/core/transport/chttp2/frame_window_update.h
+++ b/src/core/transport/chttp2/frame_window_update.h
@@ -38,21 +38,16 @@
#include <grpc/support/slice.h>
#include "src/core/transport/chttp2/frame.h"
-typedef struct {
+typedef struct
+{
gpr_uint8 byte;
gpr_uint8 is_connection_update;
gpr_uint32 amount;
} grpc_chttp2_window_update_parser;
-gpr_slice grpc_chttp2_window_update_create(gpr_uint32 id,
- gpr_uint32 window_delta);
+gpr_slice grpc_chttp2_window_update_create (gpr_uint32 id, gpr_uint32 window_delta);
-grpc_chttp2_parse_error grpc_chttp2_window_update_parser_begin_frame(
- grpc_chttp2_window_update_parser *parser, gpr_uint32 length,
- gpr_uint8 flags);
-grpc_chttp2_parse_error grpc_chttp2_window_update_parser_parse(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list);
+grpc_chttp2_parse_error grpc_chttp2_window_update_parser_begin_frame (grpc_chttp2_window_update_parser * parser, gpr_uint32 length, gpr_uint8 flags);
+grpc_chttp2_parse_error grpc_chttp2_window_update_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_WINDOW_UPDATE_H */
diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c
index e66a918fcd..f3af6d91d2 100644
--- a/src/core/transport/chttp2/hpack_parser.c
+++ b/src/core/transport/chttp2/hpack_parser.c
@@ -45,7 +45,8 @@
#include <grpc/support/port_platform.h>
#include <grpc/support/useful.h>
-typedef enum {
+typedef enum
+{
NOT_BINARY,
B64_BYTE0,
B64_BYTE1,
@@ -68,61 +69,34 @@ typedef enum {
a set of indirect jumps, and so not waste stack space. */
/* forward declarations for parsing states */
-static int parse_begin(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end);
-static int parse_error(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end);
-
-static int parse_string_prefix(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_key_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end);
-static int parse_value_string_with_indexed_key(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur,
- const gpr_uint8 *end);
-static int parse_value_string_with_literal_key(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur,
- const gpr_uint8 *end);
-
-static int parse_value0(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end);
-static int parse_value1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end);
-static int parse_value2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end);
-static int parse_value3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end);
-static int parse_value4(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end);
-static int parse_value5up(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end);
-
-static int parse_indexed_field(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_indexed_field_x(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_lithdr_incidx(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_lithdr_incidx_x(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_lithdr_incidx_v(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_lithdr_notidx(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_lithdr_notidx_x(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_lithdr_notidx_v(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_lithdr_nvridx(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
-static int parse_max_tbl_size(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end);
-static int parse_max_tbl_size_x(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end);
+static int parse_begin (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_error (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+
+static int parse_string_prefix (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_key_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_value_string_with_indexed_key (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_value_string_with_literal_key (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+
+static int parse_value0 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_value1 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_value2 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_value3 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_value4 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_value5up (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+
+static int parse_indexed_field (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_indexed_field_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_lithdr_incidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_lithdr_incidx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_lithdr_incidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_lithdr_notidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_lithdr_notidx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_lithdr_notidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_lithdr_nvridx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_lithdr_nvridx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_lithdr_nvridx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_max_tbl_size (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
+static int parse_max_tbl_size_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end);
/* we translate the first byte of a hpack field into one of these decoding
cases, then use a lookup table to jump directly to the appropriate parser.
@@ -130,7 +104,8 @@ static int parse_max_tbl_size_x(grpc_chttp2_hpack_parser *p,
_X => the integer index is all ones, meaning we need to do varint decoding
_V => the integer index is all zeros, meaning we need to decode an additional
string value */
-typedef enum {
+typedef enum
+{
INDEXED_FIELD,
INDEXED_FIELD_X,
LITHDR_INCIDX,
@@ -150,81 +125,82 @@ typedef enum {
/* jump table of parse state functions -- order must match first_byte_type
above */
static const grpc_chttp2_hpack_parser_state first_byte_action[] = {
- parse_indexed_field, parse_indexed_field_x,
- parse_lithdr_incidx, parse_lithdr_incidx_x,
- parse_lithdr_incidx_v, parse_lithdr_notidx,
- parse_lithdr_notidx_x, parse_lithdr_notidx_v,
- parse_lithdr_nvridx, parse_lithdr_nvridx_x,
- parse_lithdr_nvridx_v, parse_max_tbl_size,
- parse_max_tbl_size_x, parse_error};
+ parse_indexed_field, parse_indexed_field_x,
+ parse_lithdr_incidx, parse_lithdr_incidx_x,
+ parse_lithdr_incidx_v, parse_lithdr_notidx,
+ parse_lithdr_notidx_x, parse_lithdr_notidx_v,
+ parse_lithdr_nvridx, parse_lithdr_nvridx_x,
+ parse_lithdr_nvridx_v, parse_max_tbl_size,
+ parse_max_tbl_size_x, parse_error
+};
/* indexes the first byte to a parse state function - generated by
gen_hpack_tables.c */
static const gpr_uint8 first_byte_lut[256] = {
- LITHDR_NOTIDX_V, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
- LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
- LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
- LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX_X,
- LITHDR_NVRIDX_V, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
- LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
- LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
- LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX_X,
- ILLEGAL, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE_X,
- LITHDR_INCIDX_V, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX_X,
- ILLEGAL, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD_X,
+ LITHDR_NOTIDX_V, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
+ LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
+ LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
+ LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX_X,
+ LITHDR_NVRIDX_V, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
+ LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
+ LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
+ LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX_X,
+ ILLEGAL, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE_X,
+ LITHDR_INCIDX_V, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX_X,
+ ILLEGAL, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD_X,
};
/* state table for huffman decoding: given a state, gives an index/16 into
@@ -233,1118 +209,1217 @@ static const gpr_uint8 first_byte_lut[256] = {
generated by gen_hpack_tables.c */
static const gpr_uint8 next_tbl[256] = {
- 0, 1, 2, 3, 4, 1, 2, 5, 6, 1, 7, 8, 1, 3, 3, 9, 10, 11, 1, 1,
- 1, 12, 1, 2, 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
- 14, 1, 15, 16, 1, 17, 1, 15, 2, 7, 3, 18, 19, 1, 1, 1, 1, 20, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 7, 21, 1, 22, 1, 1, 1, 1, 1,
- 1, 1, 1, 15, 2, 2, 2, 2, 2, 2, 23, 24, 25, 1, 1, 1, 1, 2, 2, 2,
- 26, 3, 3, 27, 10, 28, 1, 1, 1, 1, 1, 1, 2, 3, 29, 10, 30, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 31, 1, 1, 1, 1, 1, 1, 1, 2,
- 2, 2, 2, 2, 2, 2, 2, 32, 1, 1, 15, 33, 1, 34, 35, 9, 36, 1, 1, 1,
- 1, 1, 1, 1, 37, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 26, 9,
- 38, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 2, 2, 26, 3, 3, 39, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 7, 3, 3, 3, 40, 2,
- 41, 1, 1, 1, 42, 43, 1, 1, 44, 1, 1, 1, 1, 15, 2, 2, 2, 2, 2, 2,
- 3, 3, 3, 45, 46, 1, 1, 2, 2, 2, 35, 3, 3, 18, 47, 2,
+ 0, 1, 2, 3, 4, 1, 2, 5, 6, 1, 7, 8, 1, 3, 3, 9, 10, 11, 1, 1,
+ 1, 12, 1, 2, 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
+ 14, 1, 15, 16, 1, 17, 1, 15, 2, 7, 3, 18, 19, 1, 1, 1, 1, 20, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 7, 21, 1, 22, 1, 1, 1, 1, 1,
+ 1, 1, 1, 15, 2, 2, 2, 2, 2, 2, 23, 24, 25, 1, 1, 1, 1, 2, 2, 2,
+ 26, 3, 3, 27, 10, 28, 1, 1, 1, 1, 1, 1, 2, 3, 29, 10, 30, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 31, 1, 1, 1, 1, 1, 1, 1, 2,
+ 2, 2, 2, 2, 2, 2, 2, 32, 1, 1, 15, 33, 1, 34, 35, 9, 36, 1, 1, 1,
+ 1, 1, 1, 1, 37, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 26, 9,
+ 38, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 2, 2, 26, 3, 3, 39, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 7, 3, 3, 3, 40, 2,
+ 41, 1, 1, 1, 42, 43, 1, 1, 44, 1, 1, 1, 1, 15, 2, 2, 2, 2, 2, 2,
+ 3, 3, 3, 45, 46, 1, 1, 2, 2, 2, 35, 3, 3, 18, 47, 2,
};
+
/* next state, based upon current state and the current nibble: see above.
generated by gen_hpack_tables.c */
static const gpr_int16 next_sub_tbl[48 * 16] = {
- 1, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
- 218, 2, 6, 10, 13, 14, 15, 16, 17, 2, 6, 10, 13, 14, 15,
- 16, 17, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11, 24, 3,
- 7, 11, 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8,
- 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
- 199, 200, 201, 202, 203, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 9, 133, 134, 135, 136, 137, 138, 139, 140,
- 141, 142, 143, 144, 145, 146, 147, 3, 7, 11, 24, 3, 7, 11, 24,
- 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 12, 132, 4, 8, 4, 8, 4, 8,
- 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 18, 19, 20, 21, 4, 8, 4,
- 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 22, 23, 91, 25, 26,
- 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 3,
- 7, 11, 24, 3, 7, 11, 24, 0, 0, 0, 0, 0, 41, 42, 43,
- 2, 6, 10, 13, 14, 15, 16, 17, 3, 7, 11, 24, 3, 7, 11,
- 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0,
- 44, 45, 2, 6, 10, 13, 14, 15, 16, 17, 46, 47, 48, 49, 50,
- 51, 52, 57, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 53, 54, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
- 68, 69, 70, 71, 72, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 73, 75, 76, 77, 78, 79, 80, 81, 82,
- 83, 84, 85, 86, 87, 88, 89, 90, 3, 7, 11, 24, 3, 7, 11,
- 24, 3, 7, 11, 24, 0, 0, 0, 0, 3, 7, 11, 24, 3, 7,
- 11, 24, 4, 8, 4, 8, 0, 0, 0, 92, 0, 0, 0, 93, 94,
- 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 3, 7, 11, 24,
- 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4,
- 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 4,
- 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0,
- 0, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
- 131, 2, 6, 10, 13, 14, 15, 16, 17, 4, 8, 4, 8, 4, 8,
- 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 148,
- 149, 150, 151, 3, 7, 11, 24, 4, 8, 4, 8, 0, 0, 0, 0,
- 0, 0, 152, 153, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11,
- 24, 154, 155, 156, 164, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7,
- 11, 24, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 157, 158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 171, 172,
- 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
- 188, 189, 190, 191, 192, 193, 194, 195, 196, 4, 8, 4, 8, 4, 8,
- 4, 8, 4, 8, 4, 8, 4, 8, 197, 198, 4, 8, 4, 8, 4,
- 8, 4, 8, 0, 0, 0, 0, 0, 0, 219, 220, 3, 7, 11, 24,
- 4, 8, 4, 8, 4, 8, 0, 0, 221, 222, 223, 224, 3, 7, 11,
- 24, 3, 7, 11, 24, 4, 8, 4, 8, 4, 8, 225, 228, 4, 8,
- 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 226, 227, 229,
- 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
- 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 245, 246, 247, 248, 249, 250, 251, 252,
- 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 255,
+ 1, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
+ 218, 2, 6, 10, 13, 14, 15, 16, 17, 2, 6, 10, 13, 14, 15,
+ 16, 17, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11, 24, 3,
+ 7, 11, 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8,
+ 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
+ 199, 200, 201, 202, 203, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 9, 133, 134, 135, 136, 137, 138, 139, 140,
+ 141, 142, 143, 144, 145, 146, 147, 3, 7, 11, 24, 3, 7, 11, 24,
+ 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 12, 132, 4, 8, 4, 8, 4, 8,
+ 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 18, 19, 20, 21, 4, 8, 4,
+ 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 22, 23, 91, 25, 26,
+ 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 3,
+ 7, 11, 24, 3, 7, 11, 24, 0, 0, 0, 0, 0, 41, 42, 43,
+ 2, 6, 10, 13, 14, 15, 16, 17, 3, 7, 11, 24, 3, 7, 11,
+ 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0,
+ 44, 45, 2, 6, 10, 13, 14, 15, 16, 17, 46, 47, 48, 49, 50,
+ 51, 52, 57, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 53, 54, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
+ 68, 69, 70, 71, 72, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 73, 75, 76, 77, 78, 79, 80, 81, 82,
+ 83, 84, 85, 86, 87, 88, 89, 90, 3, 7, 11, 24, 3, 7, 11,
+ 24, 3, 7, 11, 24, 0, 0, 0, 0, 3, 7, 11, 24, 3, 7,
+ 11, 24, 4, 8, 4, 8, 0, 0, 0, 92, 0, 0, 0, 93, 94,
+ 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 3, 7, 11, 24,
+ 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4,
+ 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 4,
+ 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0,
+ 0, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
+ 131, 2, 6, 10, 13, 14, 15, 16, 17, 4, 8, 4, 8, 4, 8,
+ 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 148,
+ 149, 150, 151, 3, 7, 11, 24, 4, 8, 4, 8, 0, 0, 0, 0,
+ 0, 0, 152, 153, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11,
+ 24, 154, 155, 156, 164, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7,
+ 11, 24, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 157, 158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 171, 172,
+ 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
+ 188, 189, 190, 191, 192, 193, 194, 195, 196, 4, 8, 4, 8, 4, 8,
+ 4, 8, 4, 8, 4, 8, 4, 8, 197, 198, 4, 8, 4, 8, 4,
+ 8, 4, 8, 0, 0, 0, 0, 0, 0, 219, 220, 3, 7, 11, 24,
+ 4, 8, 4, 8, 4, 8, 0, 0, 221, 222, 223, 224, 3, 7, 11,
+ 24, 3, 7, 11, 24, 4, 8, 4, 8, 4, 8, 225, 228, 4, 8,
+ 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 226, 227, 229,
+ 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
+ 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 245, 246, 247, 248, 249, 250, 251, 252,
+ 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 255,
};
+
/* emission table: indexed like next_tbl, ultimately gives the byte to be
emitted, or -1 for no byte, or 256 for end of stream
generated by gen_hpack_tables.c */
static const gpr_uint16 emit_tbl[256] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 0, 8, 9, 10, 11, 12, 13,
- 14, 15, 16, 17, 18, 19, 20, 21, 22, 0, 23, 24, 25, 26, 27,
- 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
- 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0, 55, 56,
- 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 0,
- 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
- 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
- 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
- 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
- 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
- 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 0,
- 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
- 0, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188,
- 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
- 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
- 219, 220, 221, 0, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
- 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
- 248,
+ 0, 1, 2, 3, 4, 5, 6, 7, 0, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 0, 23, 24, 25, 26, 27,
+ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
+ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0, 55, 56,
+ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 0,
+ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
+ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
+ 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
+ 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
+ 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
+ 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 0,
+ 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
+ 0, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188,
+ 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
+ 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
+ 219, 220, 221, 0, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
+ 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
+ 248,
};
+
/* generated by gen_hpack_tables.c */
static const gpr_int16 emit_sub_tbl[249 * 16] = {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49,
- 49, 49, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 97,
- 97, 97, 97, 48, 48, 49, 49, 50, 50, 97, 97, 99, 99, 101, 101,
- 105, 105, 111, 111, 48, 49, 50, 97, 99, 101, 105, 111, 115, 116, -1,
- -1, -1, -1, -1, -1, 32, 32, 32, 32, 32, 32, 32, 32, 37, 37,
- 37, 37, 37, 37, 37, 37, 99, 99, 99, 99, 101, 101, 101, 101, 105,
- 105, 105, 105, 111, 111, 111, 111, 115, 115, 116, 116, 32, 37, 45, 46,
- 47, 51, 52, 53, 54, 55, 56, 57, 61, 61, 61, 61, 61, 61, 61,
- 61, 65, 65, 65, 65, 65, 65, 65, 65, 115, 115, 115, 115, 116, 116,
- 116, 116, 32, 32, 37, 37, 45, 45, 46, 46, 61, 65, 95, 98, 100,
- 102, 103, 104, 108, 109, 110, 112, 114, 117, -1, -1, 58, 58, 58, 58,
- 58, 58, 58, 58, 66, 66, 66, 66, 66, 66, 66, 66, 47, 47, 51,
- 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 61, 61,
- 65, 65, 95, 95, 98, 98, 100, 100, 102, 102, 103, 103, 104, 104, 108,
- 108, 109, 109, 110, 110, 112, 112, 114, 114, 117, 117, 58, 66, 67, 68,
- 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
- 84, 85, 86, 87, 89, 106, 107, 113, 118, 119, 120, 121, 122, -1, -1,
- -1, -1, 38, 38, 38, 38, 38, 38, 38, 38, 42, 42, 42, 42, 42,
- 42, 42, 42, 44, 44, 44, 44, 44, 44, 44, 44, 59, 59, 59, 59,
- 59, 59, 59, 59, 88, 88, 88, 88, 88, 88, 88, 88, 90, 90, 90,
- 90, 90, 90, 90, 90, 33, 33, 34, 34, 40, 40, 41, 41, 63, 63,
- 39, 43, 124, -1, -1, -1, 35, 35, 35, 35, 35, 35, 35, 35, 62,
- 62, 62, 62, 62, 62, 62, 62, 0, 0, 0, 0, 36, 36, 36, 36,
- 64, 64, 64, 64, 91, 91, 91, 91, 69, 69, 69, 69, 69, 69, 69,
- 69, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71,
- 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73,
- 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75,
- 75, 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77,
- 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 79, 79,
- 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 81,
- 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82,
- 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84,
- 84, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86,
- 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 89, 89, 89, 89, 89,
- 89, 89, 89, 106, 106, 106, 106, 106, 106, 106, 106, 107, 107, 107, 107,
- 107, 107, 107, 107, 113, 113, 113, 113, 113, 113, 113, 113, 118, 118, 118,
- 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 120, 120,
- 120, 120, 120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121, 121, 122,
- 122, 122, 122, 122, 122, 122, 122, 38, 38, 38, 38, 42, 42, 42, 42,
- 44, 44, 44, 44, 59, 59, 59, 59, 88, 88, 88, 88, 90, 90, 90,
- 90, 33, 34, 40, 41, 63, -1, -1, -1, 39, 39, 39, 39, 39, 39,
- 39, 39, 43, 43, 43, 43, 43, 43, 43, 43, 124, 124, 124, 124, 124,
- 124, 124, 124, 35, 35, 35, 35, 62, 62, 62, 62, 0, 0, 36, 36,
- 64, 64, 91, 91, 93, 93, 126, 126, 94, 125, -1, -1, 60, 60, 60,
- 60, 60, 60, 60, 60, 96, 96, 96, 96, 96, 96, 96, 96, 123, 123,
- 123, 123, 123, 123, 123, 123, -1, -1, -1, -1, -1, -1, -1, -1, 92,
- 92, 92, 92, 92, 92, 92, 92, 195, 195, 195, 195, 195, 195, 195, 195,
- 208, 208, 208, 208, 208, 208, 208, 208, 128, 128, 128, 128, 130, 130, 130,
- 130, 131, 131, 131, 131, 162, 162, 162, 162, 184, 184, 184, 184, 194, 194,
- 194, 194, 224, 224, 224, 224, 226, 226, 226, 226, 153, 153, 161, 161, 167,
- 167, 172, 172, 176, 176, 177, 177, 179, 179, 209, 209, 216, 216, 217, 217,
- 227, 227, 229, 229, 230, 230, 129, 132, 133, 134, 136, 146, 154, 156, 160,
- 163, 164, 169, 170, 173, 178, 181, 185, 186, 187, 189, 190, 196, 198, 228,
- 232, 233, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 135,
- 135, 135, 135, 135, 135, 135, 135, 137, 137, 137, 137, 137, 137, 137, 137,
- 138, 138, 138, 138, 138, 138, 138, 138, 139, 139, 139, 139, 139, 139, 139,
- 139, 140, 140, 140, 140, 140, 140, 140, 140, 141, 141, 141, 141, 141, 141,
- 141, 141, 143, 143, 143, 143, 143, 143, 143, 143, 147, 147, 147, 147, 147,
- 147, 147, 147, 149, 149, 149, 149, 149, 149, 149, 149, 150, 150, 150, 150,
- 150, 150, 150, 150, 151, 151, 151, 151, 151, 151, 151, 151, 152, 152, 152,
- 152, 152, 152, 152, 152, 155, 155, 155, 155, 155, 155, 155, 155, 157, 157,
- 157, 157, 157, 157, 157, 157, 158, 158, 158, 158, 158, 158, 158, 158, 165,
- 165, 165, 165, 165, 165, 165, 165, 166, 166, 166, 166, 166, 166, 166, 166,
- 168, 168, 168, 168, 168, 168, 168, 168, 174, 174, 174, 174, 174, 174, 174,
- 174, 175, 175, 175, 175, 175, 175, 175, 175, 180, 180, 180, 180, 180, 180,
- 180, 180, 182, 182, 182, 182, 182, 182, 182, 182, 183, 183, 183, 183, 183,
- 183, 183, 183, 188, 188, 188, 188, 188, 188, 188, 188, 191, 191, 191, 191,
- 191, 191, 191, 191, 197, 197, 197, 197, 197, 197, 197, 197, 231, 231, 231,
- 231, 231, 231, 231, 231, 239, 239, 239, 239, 239, 239, 239, 239, 9, 9,
- 9, 9, 142, 142, 142, 142, 144, 144, 144, 144, 145, 145, 145, 145, 148,
- 148, 148, 148, 159, 159, 159, 159, 171, 171, 171, 171, 206, 206, 206, 206,
- 215, 215, 215, 215, 225, 225, 225, 225, 236, 236, 236, 236, 237, 237, 237,
- 237, 199, 199, 207, 207, 234, 234, 235, 235, 192, 193, 200, 201, 202, 205,
- 210, 213, 218, 219, 238, 240, 242, 243, 255, -1, 203, 203, 203, 203, 203,
- 203, 203, 203, 204, 204, 204, 204, 204, 204, 204, 204, 211, 211, 211, 211,
- 211, 211, 211, 211, 212, 212, 212, 212, 212, 212, 212, 212, 214, 214, 214,
- 214, 214, 214, 214, 214, 221, 221, 221, 221, 221, 221, 221, 221, 222, 222,
- 222, 222, 222, 222, 222, 222, 223, 223, 223, 223, 223, 223, 223, 223, 241,
- 241, 241, 241, 241, 241, 241, 241, 244, 244, 244, 244, 244, 244, 244, 244,
- 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 246,
- 246, 247, 247, 247, 247, 247, 247, 247, 247, 248, 248, 248, 248, 248, 248,
- 248, 248, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251,
- 251, 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253,
- 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 2, 2, 2,
- 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6,
- 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 11, 11, 11, 11, 12,
- 12, 12, 12, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16,
- 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20,
- 20, 21, 21, 21, 21, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25,
- 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29,
- 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 127, 127, 127, 127,
- 220, 220, 220, 220, 249, 249, 249, 249, 10, 13, 22, 256, 93, 93, 93,
- 93, 126, 126, 126, 126, 94, 94, 125, 125, 60, 96, 123, -1, 92, 195,
- 208, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 128,
- 128, 128, 128, 128, 128, 128, 128, 130, 130, 130, 130, 130, 130, 130, 130,
- 131, 131, 131, 131, 131, 131, 131, 131, 162, 162, 162, 162, 162, 162, 162,
- 162, 184, 184, 184, 184, 184, 184, 184, 184, 194, 194, 194, 194, 194, 194,
- 194, 194, 224, 224, 224, 224, 224, 224, 224, 224, 226, 226, 226, 226, 226,
- 226, 226, 226, 153, 153, 153, 153, 161, 161, 161, 161, 167, 167, 167, 167,
- 172, 172, 172, 172, 176, 176, 176, 176, 177, 177, 177, 177, 179, 179, 179,
- 179, 209, 209, 209, 209, 216, 216, 216, 216, 217, 217, 217, 217, 227, 227,
- 227, 227, 229, 229, 229, 229, 230, 230, 230, 230, 129, 129, 132, 132, 133,
- 133, 134, 134, 136, 136, 146, 146, 154, 154, 156, 156, 160, 160, 163, 163,
- 164, 164, 169, 169, 170, 170, 173, 173, 178, 178, 181, 181, 185, 185, 186,
- 186, 187, 187, 189, 189, 190, 190, 196, 196, 198, 198, 228, 228, 232, 232,
- 233, 233, 1, 135, 137, 138, 139, 140, 141, 143, 147, 149, 150, 151, 152,
- 155, 157, 158, 165, 166, 168, 174, 175, 180, 182, 183, 188, 191, 197, 231,
- 239, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, 9, 9,
- 9, 9, 9, 9, 9, 142, 142, 142, 142, 142, 142, 142, 142, 144, 144,
- 144, 144, 144, 144, 144, 144, 145, 145, 145, 145, 145, 145, 145, 145, 148,
- 148, 148, 148, 148, 148, 148, 148, 159, 159, 159, 159, 159, 159, 159, 159,
- 171, 171, 171, 171, 171, 171, 171, 171, 206, 206, 206, 206, 206, 206, 206,
- 206, 215, 215, 215, 215, 215, 215, 215, 215, 225, 225, 225, 225, 225, 225,
- 225, 225, 236, 236, 236, 236, 236, 236, 236, 236, 237, 237, 237, 237, 237,
- 237, 237, 237, 199, 199, 199, 199, 207, 207, 207, 207, 234, 234, 234, 234,
- 235, 235, 235, 235, 192, 192, 193, 193, 200, 200, 201, 201, 202, 202, 205,
- 205, 210, 210, 213, 213, 218, 218, 219, 219, 238, 238, 240, 240, 242, 242,
- 243, 243, 255, 255, 203, 204, 211, 212, 214, 221, 222, 223, 241, 244, 245,
- 246, 247, 248, 250, 251, 252, 253, 254, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2,
- 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
- 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6,
- 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
- 8, 8, 8, 8, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
- 12, 12, 12, 12, 12, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15,
- 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17,
- 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18,
- 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20,
- 20, 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, 23, 23, 23, 23,
- 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25,
- 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27,
- 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29,
- 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31,
- 31, 31, 31, 31, 31, 31, 127, 127, 127, 127, 127, 127, 127, 127, 220,
- 220, 220, 220, 220, 220, 220, 220, 249, 249, 249, 249, 249, 249, 249, 249,
- 10, 10, 13, 13, 22, 22, 256, 256, 67, 67, 67, 67, 67, 67, 67,
- 67, 68, 68, 68, 68, 68, 68, 68, 68, 95, 95, 95, 95, 95, 95,
- 95, 95, 98, 98, 98, 98, 98, 98, 98, 98, 100, 100, 100, 100, 100,
- 100, 100, 100, 102, 102, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103,
- 103, 103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 108, 108, 108,
- 108, 108, 108, 108, 108, 109, 109, 109, 109, 109, 109, 109, 109, 110, 110,
- 110, 110, 110, 110, 110, 110, 112, 112, 112, 112, 112, 112, 112, 112, 114,
- 114, 114, 114, 114, 114, 114, 114, 117, 117, 117, 117, 117, 117, 117, 117,
- 58, 58, 58, 58, 66, 66, 66, 66, 67, 67, 67, 67, 68, 68, 68,
- 68, 69, 69, 69, 69, 70, 70, 70, 70, 71, 71, 71, 71, 72, 72,
- 72, 72, 73, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 75, 76,
- 76, 76, 76, 77, 77, 77, 77, 78, 78, 78, 78, 79, 79, 79, 79,
- 80, 80, 80, 80, 81, 81, 81, 81, 82, 82, 82, 82, 83, 83, 83,
- 83, 84, 84, 84, 84, 85, 85, 85, 85, 86, 86, 86, 86, 87, 87,
- 87, 87, 89, 89, 89, 89, 106, 106, 106, 106, 107, 107, 107, 107, 113,
- 113, 113, 113, 118, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 120,
- 121, 121, 121, 121, 122, 122, 122, 122, 38, 38, 42, 42, 44, 44, 59,
- 59, 88, 88, 90, 90, -1, -1, -1, -1, 33, 33, 33, 33, 33, 33,
- 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 40, 40, 40, 40, 40,
- 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 63, 63, 63, 63,
- 63, 63, 63, 63, 39, 39, 39, 39, 43, 43, 43, 43, 124, 124, 124,
- 124, 35, 35, 62, 62, 0, 36, 64, 91, 93, 126, -1, -1, 94, 94,
- 94, 94, 94, 94, 94, 94, 125, 125, 125, 125, 125, 125, 125, 125, 60,
- 60, 60, 60, 96, 96, 96, 96, 123, 123, 123, 123, -1, -1, -1, -1,
- 92, 92, 92, 92, 195, 195, 195, 195, 208, 208, 208, 208, 128, 128, 130,
- 130, 131, 131, 162, 162, 184, 184, 194, 194, 224, 224, 226, 226, 153, 161,
- 167, 172, 176, 177, 179, 209, 216, 217, 227, 229, 230, -1, -1, -1, -1,
- -1, -1, -1, 129, 129, 129, 129, 129, 129, 129, 129, 132, 132, 132, 132,
- 132, 132, 132, 132, 133, 133, 133, 133, 133, 133, 133, 133, 134, 134, 134,
- 134, 134, 134, 134, 134, 136, 136, 136, 136, 136, 136, 136, 136, 146, 146,
- 146, 146, 146, 146, 146, 146, 154, 154, 154, 154, 154, 154, 154, 154, 156,
- 156, 156, 156, 156, 156, 156, 156, 160, 160, 160, 160, 160, 160, 160, 160,
- 163, 163, 163, 163, 163, 163, 163, 163, 164, 164, 164, 164, 164, 164, 164,
- 164, 169, 169, 169, 169, 169, 169, 169, 169, 170, 170, 170, 170, 170, 170,
- 170, 170, 173, 173, 173, 173, 173, 173, 173, 173, 178, 178, 178, 178, 178,
- 178, 178, 178, 181, 181, 181, 181, 181, 181, 181, 181, 185, 185, 185, 185,
- 185, 185, 185, 185, 186, 186, 186, 186, 186, 186, 186, 186, 187, 187, 187,
- 187, 187, 187, 187, 187, 189, 189, 189, 189, 189, 189, 189, 189, 190, 190,
- 190, 190, 190, 190, 190, 190, 196, 196, 196, 196, 196, 196, 196, 196, 198,
- 198, 198, 198, 198, 198, 198, 198, 228, 228, 228, 228, 228, 228, 228, 228,
- 232, 232, 232, 232, 232, 232, 232, 232, 233, 233, 233, 233, 233, 233, 233,
- 233, 1, 1, 1, 1, 135, 135, 135, 135, 137, 137, 137, 137, 138, 138,
- 138, 138, 139, 139, 139, 139, 140, 140, 140, 140, 141, 141, 141, 141, 143,
- 143, 143, 143, 147, 147, 147, 147, 149, 149, 149, 149, 150, 150, 150, 150,
- 151, 151, 151, 151, 152, 152, 152, 152, 155, 155, 155, 155, 157, 157, 157,
- 157, 158, 158, 158, 158, 165, 165, 165, 165, 166, 166, 166, 166, 168, 168,
- 168, 168, 174, 174, 174, 174, 175, 175, 175, 175, 180, 180, 180, 180, 182,
- 182, 182, 182, 183, 183, 183, 183, 188, 188, 188, 188, 191, 191, 191, 191,
- 197, 197, 197, 197, 231, 231, 231, 231, 239, 239, 239, 239, 9, 9, 142,
- 142, 144, 144, 145, 145, 148, 148, 159, 159, 171, 171, 206, 206, 215, 215,
- 225, 225, 236, 236, 237, 237, 199, 207, 234, 235, 192, 192, 192, 192, 192,
- 192, 192, 192, 193, 193, 193, 193, 193, 193, 193, 193, 200, 200, 200, 200,
- 200, 200, 200, 200, 201, 201, 201, 201, 201, 201, 201, 201, 202, 202, 202,
- 202, 202, 202, 202, 202, 205, 205, 205, 205, 205, 205, 205, 205, 210, 210,
- 210, 210, 210, 210, 210, 210, 213, 213, 213, 213, 213, 213, 213, 213, 218,
- 218, 218, 218, 218, 218, 218, 218, 219, 219, 219, 219, 219, 219, 219, 219,
- 238, 238, 238, 238, 238, 238, 238, 238, 240, 240, 240, 240, 240, 240, 240,
- 240, 242, 242, 242, 242, 242, 242, 242, 242, 243, 243, 243, 243, 243, 243,
- 243, 243, 255, 255, 255, 255, 255, 255, 255, 255, 203, 203, 203, 203, 204,
- 204, 204, 204, 211, 211, 211, 211, 212, 212, 212, 212, 214, 214, 214, 214,
- 221, 221, 221, 221, 222, 222, 222, 222, 223, 223, 223, 223, 241, 241, 241,
- 241, 244, 244, 244, 244, 245, 245, 245, 245, 246, 246, 246, 246, 247, 247,
- 247, 247, 248, 248, 248, 248, 250, 250, 250, 250, 251, 251, 251, 251, 252,
- 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 2, 2, 3, 3,
- 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 11, 11, 12, 12, 14,
- 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21,
- 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30,
- 30, 31, 31, 127, 127, 220, 220, 249, 249, -1, -1, 10, 10, 10, 10,
- 10, 10, 10, 10, 13, 13, 13, 13, 13, 13, 13, 13, 22, 22, 22,
- 22, 22, 22, 22, 22, 256, 256, 256, 256, 256, 256, 256, 256, 45, 45,
- 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 47,
- 47, 47, 47, 47, 47, 47, 47, 51, 51, 51, 51, 51, 51, 51, 51,
- 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53,
- 53, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55,
- 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57,
- 57, 57, 57, 50, 50, 50, 50, 50, 50, 50, 50, 97, 97, 97, 97,
- 97, 97, 97, 97, 99, 99, 99, 99, 99, 99, 99, 99, 101, 101, 101,
- 101, 101, 101, 101, 101, 105, 105, 105, 105, 105, 105, 105, 105, 111, 111,
- 111, 111, 111, 111, 111, 111, 115, 115, 115, 115, 115, 115, 115, 115, 116,
- 116, 116, 116, 116, 116, 116, 116, 32, 32, 32, 32, 37, 37, 37, 37,
- 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 51, 51, 51,
- 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55,
- 55, 55, 56, 56, 56, 56, 57, 57, 57, 57, 61, 61, 61, 61, 65,
- 65, 65, 65, 95, 95, 95, 95, 98, 98, 98, 98, 100, 100, 100, 100,
- 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, 104, 104, 108, 108, 108,
- 108, 109, 109, 109, 109, 110, 110, 110, 110, 112, 112, 112, 112, 114, 114,
- 114, 114, 117, 117, 117, 117, 58, 58, 66, 66, 67, 67, 68, 68, 69,
- 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 76, 76,
- 77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 82, 82, 83, 83, 84,
- 84, 85, 85, 86, 86, 87, 87, 89, 89, 106, 106, 107, 107, 113, 113,
- 118, 118, 119, 119, 120, 120, 121, 121, 122, 122, 38, 42, 44, 59, 88,
- 90, -1, -1, 33, 33, 33, 33, 34, 34, 34, 34, 40, 40, 40, 40,
- 41, 41, 41, 41, 63, 63, 63, 63, 39, 39, 43, 43, 124, 124, 35,
- 62, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 36, 36,
- 36, 36, 36, 36, 36, 36, 64, 64, 64, 64, 64, 64, 64, 64, 91,
- 91, 91, 91, 91, 91, 91, 91, 93, 93, 93, 93, 93, 93, 93, 93,
- 126, 126, 126, 126, 126, 126, 126, 126, 94, 94, 94, 94, 125, 125, 125,
- 125, 60, 60, 96, 96, 123, 123, -1, -1, 92, 92, 195, 195, 208, 208,
- 128, 130, 131, 162, 184, 194, 224, 226, -1, -1, 153, 153, 153, 153, 153,
- 153, 153, 153, 161, 161, 161, 161, 161, 161, 161, 161, 167, 167, 167, 167,
- 167, 167, 167, 167, 172, 172, 172, 172, 172, 172, 172, 172, 176, 176, 176,
- 176, 176, 176, 176, 176, 177, 177, 177, 177, 177, 177, 177, 177, 179, 179,
- 179, 179, 179, 179, 179, 179, 209, 209, 209, 209, 209, 209, 209, 209, 216,
- 216, 216, 216, 216, 216, 216, 216, 217, 217, 217, 217, 217, 217, 217, 217,
- 227, 227, 227, 227, 227, 227, 227, 227, 229, 229, 229, 229, 229, 229, 229,
- 229, 230, 230, 230, 230, 230, 230, 230, 230, 129, 129, 129, 129, 132, 132,
- 132, 132, 133, 133, 133, 133, 134, 134, 134, 134, 136, 136, 136, 136, 146,
- 146, 146, 146, 154, 154, 154, 154, 156, 156, 156, 156, 160, 160, 160, 160,
- 163, 163, 163, 163, 164, 164, 164, 164, 169, 169, 169, 169, 170, 170, 170,
- 170, 173, 173, 173, 173, 178, 178, 178, 178, 181, 181, 181, 181, 185, 185,
- 185, 185, 186, 186, 186, 186, 187, 187, 187, 187, 189, 189, 189, 189, 190,
- 190, 190, 190, 196, 196, 196, 196, 198, 198, 198, 198, 228, 228, 228, 228,
- 232, 232, 232, 232, 233, 233, 233, 233, 1, 1, 135, 135, 137, 137, 138,
- 138, 139, 139, 140, 140, 141, 141, 143, 143, 147, 147, 149, 149, 150, 150,
- 151, 151, 152, 152, 155, 155, 157, 157, 158, 158, 165, 165, 166, 166, 168,
- 168, 174, 174, 175, 175, 180, 180, 182, 182, 183, 183, 188, 188, 191, 191,
- 197, 197, 231, 231, 239, 239, 9, 142, 144, 145, 148, 159, 171, 206, 215,
- 225, 236, 237, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 199, 199,
- 199, 199, 199, 199, 199, 199, 207, 207, 207, 207, 207, 207, 207, 207, 234,
- 234, 234, 234, 234, 234, 234, 234, 235, 235, 235, 235, 235, 235, 235, 235,
- 192, 192, 192, 192, 193, 193, 193, 193, 200, 200, 200, 200, 201, 201, 201,
- 201, 202, 202, 202, 202, 205, 205, 205, 205, 210, 210, 210, 210, 213, 213,
- 213, 213, 218, 218, 218, 218, 219, 219, 219, 219, 238, 238, 238, 238, 240,
- 240, 240, 240, 242, 242, 242, 242, 243, 243, 243, 243, 255, 255, 255, 255,
- 203, 203, 204, 204, 211, 211, 212, 212, 214, 214, 221, 221, 222, 222, 223,
- 223, 241, 241, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 250, 250,
- 251, 251, 252, 252, 253, 253, 254, 254, 2, 3, 4, 5, 6, 7, 8,
- 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27,
- 28, 29, 30, 31, 127, 220, 249, -1, 10, 10, 10, 10, 13, 13, 13,
- 13, 22, 22, 22, 22, 256, 256, 256, 256,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49,
+ 49, 49, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 97,
+ 97, 97, 97, 48, 48, 49, 49, 50, 50, 97, 97, 99, 99, 101, 101,
+ 105, 105, 111, 111, 48, 49, 50, 97, 99, 101, 105, 111, 115, 116, -1,
+ -1, -1, -1, -1, -1, 32, 32, 32, 32, 32, 32, 32, 32, 37, 37,
+ 37, 37, 37, 37, 37, 37, 99, 99, 99, 99, 101, 101, 101, 101, 105,
+ 105, 105, 105, 111, 111, 111, 111, 115, 115, 116, 116, 32, 37, 45, 46,
+ 47, 51, 52, 53, 54, 55, 56, 57, 61, 61, 61, 61, 61, 61, 61,
+ 61, 65, 65, 65, 65, 65, 65, 65, 65, 115, 115, 115, 115, 116, 116,
+ 116, 116, 32, 32, 37, 37, 45, 45, 46, 46, 61, 65, 95, 98, 100,
+ 102, 103, 104, 108, 109, 110, 112, 114, 117, -1, -1, 58, 58, 58, 58,
+ 58, 58, 58, 58, 66, 66, 66, 66, 66, 66, 66, 66, 47, 47, 51,
+ 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 61, 61,
+ 65, 65, 95, 95, 98, 98, 100, 100, 102, 102, 103, 103, 104, 104, 108,
+ 108, 109, 109, 110, 110, 112, 112, 114, 114, 117, 117, 58, 66, 67, 68,
+ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
+ 84, 85, 86, 87, 89, 106, 107, 113, 118, 119, 120, 121, 122, -1, -1,
+ -1, -1, 38, 38, 38, 38, 38, 38, 38, 38, 42, 42, 42, 42, 42,
+ 42, 42, 42, 44, 44, 44, 44, 44, 44, 44, 44, 59, 59, 59, 59,
+ 59, 59, 59, 59, 88, 88, 88, 88, 88, 88, 88, 88, 90, 90, 90,
+ 90, 90, 90, 90, 90, 33, 33, 34, 34, 40, 40, 41, 41, 63, 63,
+ 39, 43, 124, -1, -1, -1, 35, 35, 35, 35, 35, 35, 35, 35, 62,
+ 62, 62, 62, 62, 62, 62, 62, 0, 0, 0, 0, 36, 36, 36, 36,
+ 64, 64, 64, 64, 91, 91, 91, 91, 69, 69, 69, 69, 69, 69, 69,
+ 69, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71,
+ 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73,
+ 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75,
+ 75, 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77,
+ 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 79, 79,
+ 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 81,
+ 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82,
+ 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84,
+ 84, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86,
+ 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 89, 89, 89, 89, 89,
+ 89, 89, 89, 106, 106, 106, 106, 106, 106, 106, 106, 107, 107, 107, 107,
+ 107, 107, 107, 107, 113, 113, 113, 113, 113, 113, 113, 113, 118, 118, 118,
+ 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 120, 120,
+ 120, 120, 120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121, 121, 122,
+ 122, 122, 122, 122, 122, 122, 122, 38, 38, 38, 38, 42, 42, 42, 42,
+ 44, 44, 44, 44, 59, 59, 59, 59, 88, 88, 88, 88, 90, 90, 90,
+ 90, 33, 34, 40, 41, 63, -1, -1, -1, 39, 39, 39, 39, 39, 39,
+ 39, 39, 43, 43, 43, 43, 43, 43, 43, 43, 124, 124, 124, 124, 124,
+ 124, 124, 124, 35, 35, 35, 35, 62, 62, 62, 62, 0, 0, 36, 36,
+ 64, 64, 91, 91, 93, 93, 126, 126, 94, 125, -1, -1, 60, 60, 60,
+ 60, 60, 60, 60, 60, 96, 96, 96, 96, 96, 96, 96, 96, 123, 123,
+ 123, 123, 123, 123, 123, 123, -1, -1, -1, -1, -1, -1, -1, -1, 92,
+ 92, 92, 92, 92, 92, 92, 92, 195, 195, 195, 195, 195, 195, 195, 195,
+ 208, 208, 208, 208, 208, 208, 208, 208, 128, 128, 128, 128, 130, 130, 130,
+ 130, 131, 131, 131, 131, 162, 162, 162, 162, 184, 184, 184, 184, 194, 194,
+ 194, 194, 224, 224, 224, 224, 226, 226, 226, 226, 153, 153, 161, 161, 167,
+ 167, 172, 172, 176, 176, 177, 177, 179, 179, 209, 209, 216, 216, 217, 217,
+ 227, 227, 229, 229, 230, 230, 129, 132, 133, 134, 136, 146, 154, 156, 160,
+ 163, 164, 169, 170, 173, 178, 181, 185, 186, 187, 189, 190, 196, 198, 228,
+ 232, 233, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 135,
+ 135, 135, 135, 135, 135, 135, 135, 137, 137, 137, 137, 137, 137, 137, 137,
+ 138, 138, 138, 138, 138, 138, 138, 138, 139, 139, 139, 139, 139, 139, 139,
+ 139, 140, 140, 140, 140, 140, 140, 140, 140, 141, 141, 141, 141, 141, 141,
+ 141, 141, 143, 143, 143, 143, 143, 143, 143, 143, 147, 147, 147, 147, 147,
+ 147, 147, 147, 149, 149, 149, 149, 149, 149, 149, 149, 150, 150, 150, 150,
+ 150, 150, 150, 150, 151, 151, 151, 151, 151, 151, 151, 151, 152, 152, 152,
+ 152, 152, 152, 152, 152, 155, 155, 155, 155, 155, 155, 155, 155, 157, 157,
+ 157, 157, 157, 157, 157, 157, 158, 158, 158, 158, 158, 158, 158, 158, 165,
+ 165, 165, 165, 165, 165, 165, 165, 166, 166, 166, 166, 166, 166, 166, 166,
+ 168, 168, 168, 168, 168, 168, 168, 168, 174, 174, 174, 174, 174, 174, 174,
+ 174, 175, 175, 175, 175, 175, 175, 175, 175, 180, 180, 180, 180, 180, 180,
+ 180, 180, 182, 182, 182, 182, 182, 182, 182, 182, 183, 183, 183, 183, 183,
+ 183, 183, 183, 188, 188, 188, 188, 188, 188, 188, 188, 191, 191, 191, 191,
+ 191, 191, 191, 191, 197, 197, 197, 197, 197, 197, 197, 197, 231, 231, 231,
+ 231, 231, 231, 231, 231, 239, 239, 239, 239, 239, 239, 239, 239, 9, 9,
+ 9, 9, 142, 142, 142, 142, 144, 144, 144, 144, 145, 145, 145, 145, 148,
+ 148, 148, 148, 159, 159, 159, 159, 171, 171, 171, 171, 206, 206, 206, 206,
+ 215, 215, 215, 215, 225, 225, 225, 225, 236, 236, 236, 236, 237, 237, 237,
+ 237, 199, 199, 207, 207, 234, 234, 235, 235, 192, 193, 200, 201, 202, 205,
+ 210, 213, 218, 219, 238, 240, 242, 243, 255, -1, 203, 203, 203, 203, 203,
+ 203, 203, 203, 204, 204, 204, 204, 204, 204, 204, 204, 211, 211, 211, 211,
+ 211, 211, 211, 211, 212, 212, 212, 212, 212, 212, 212, 212, 214, 214, 214,
+ 214, 214, 214, 214, 214, 221, 221, 221, 221, 221, 221, 221, 221, 222, 222,
+ 222, 222, 222, 222, 222, 222, 223, 223, 223, 223, 223, 223, 223, 223, 241,
+ 241, 241, 241, 241, 241, 241, 241, 244, 244, 244, 244, 244, 244, 244, 244,
+ 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 246,
+ 246, 247, 247, 247, 247, 247, 247, 247, 247, 248, 248, 248, 248, 248, 248,
+ 248, 248, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251,
+ 251, 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253,
+ 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 2, 2, 2,
+ 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6,
+ 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 11, 11, 11, 11, 12,
+ 12, 12, 12, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16,
+ 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20,
+ 20, 21, 21, 21, 21, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25,
+ 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29,
+ 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 127, 127, 127, 127,
+ 220, 220, 220, 220, 249, 249, 249, 249, 10, 13, 22, 256, 93, 93, 93,
+ 93, 126, 126, 126, 126, 94, 94, 125, 125, 60, 96, 123, -1, 92, 195,
+ 208, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 128,
+ 128, 128, 128, 128, 128, 128, 128, 130, 130, 130, 130, 130, 130, 130, 130,
+ 131, 131, 131, 131, 131, 131, 131, 131, 162, 162, 162, 162, 162, 162, 162,
+ 162, 184, 184, 184, 184, 184, 184, 184, 184, 194, 194, 194, 194, 194, 194,
+ 194, 194, 224, 224, 224, 224, 224, 224, 224, 224, 226, 226, 226, 226, 226,
+ 226, 226, 226, 153, 153, 153, 153, 161, 161, 161, 161, 167, 167, 167, 167,
+ 172, 172, 172, 172, 176, 176, 176, 176, 177, 177, 177, 177, 179, 179, 179,
+ 179, 209, 209, 209, 209, 216, 216, 216, 216, 217, 217, 217, 217, 227, 227,
+ 227, 227, 229, 229, 229, 229, 230, 230, 230, 230, 129, 129, 132, 132, 133,
+ 133, 134, 134, 136, 136, 146, 146, 154, 154, 156, 156, 160, 160, 163, 163,
+ 164, 164, 169, 169, 170, 170, 173, 173, 178, 178, 181, 181, 185, 185, 186,
+ 186, 187, 187, 189, 189, 190, 190, 196, 196, 198, 198, 228, 228, 232, 232,
+ 233, 233, 1, 135, 137, 138, 139, 140, 141, 143, 147, 149, 150, 151, 152,
+ 155, 157, 158, 165, 166, 168, 174, 175, 180, 182, 183, 188, 191, 197, 231,
+ 239, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, 9, 9,
+ 9, 9, 9, 9, 9, 142, 142, 142, 142, 142, 142, 142, 142, 144, 144,
+ 144, 144, 144, 144, 144, 144, 145, 145, 145, 145, 145, 145, 145, 145, 148,
+ 148, 148, 148, 148, 148, 148, 148, 159, 159, 159, 159, 159, 159, 159, 159,
+ 171, 171, 171, 171, 171, 171, 171, 171, 206, 206, 206, 206, 206, 206, 206,
+ 206, 215, 215, 215, 215, 215, 215, 215, 215, 225, 225, 225, 225, 225, 225,
+ 225, 225, 236, 236, 236, 236, 236, 236, 236, 236, 237, 237, 237, 237, 237,
+ 237, 237, 237, 199, 199, 199, 199, 207, 207, 207, 207, 234, 234, 234, 234,
+ 235, 235, 235, 235, 192, 192, 193, 193, 200, 200, 201, 201, 202, 202, 205,
+ 205, 210, 210, 213, 213, 218, 218, 219, 219, 238, 238, 240, 240, 242, 242,
+ 243, 243, 255, 255, 203, 204, 211, 212, 214, 221, 222, 223, 241, 244, 245,
+ 246, 247, 248, 250, 251, 252, 253, 254, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2,
+ 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
+ 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6,
+ 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
+ 8, 8, 8, 8, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
+ 12, 12, 12, 12, 12, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15,
+ 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17,
+ 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18,
+ 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20,
+ 20, 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, 23, 23, 23, 23,
+ 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25,
+ 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27,
+ 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29,
+ 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31,
+ 31, 31, 31, 31, 31, 31, 127, 127, 127, 127, 127, 127, 127, 127, 220,
+ 220, 220, 220, 220, 220, 220, 220, 249, 249, 249, 249, 249, 249, 249, 249,
+ 10, 10, 13, 13, 22, 22, 256, 256, 67, 67, 67, 67, 67, 67, 67,
+ 67, 68, 68, 68, 68, 68, 68, 68, 68, 95, 95, 95, 95, 95, 95,
+ 95, 95, 98, 98, 98, 98, 98, 98, 98, 98, 100, 100, 100, 100, 100,
+ 100, 100, 100, 102, 102, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103,
+ 103, 103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 108, 108, 108,
+ 108, 108, 108, 108, 108, 109, 109, 109, 109, 109, 109, 109, 109, 110, 110,
+ 110, 110, 110, 110, 110, 110, 112, 112, 112, 112, 112, 112, 112, 112, 114,
+ 114, 114, 114, 114, 114, 114, 114, 117, 117, 117, 117, 117, 117, 117, 117,
+ 58, 58, 58, 58, 66, 66, 66, 66, 67, 67, 67, 67, 68, 68, 68,
+ 68, 69, 69, 69, 69, 70, 70, 70, 70, 71, 71, 71, 71, 72, 72,
+ 72, 72, 73, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 75, 76,
+ 76, 76, 76, 77, 77, 77, 77, 78, 78, 78, 78, 79, 79, 79, 79,
+ 80, 80, 80, 80, 81, 81, 81, 81, 82, 82, 82, 82, 83, 83, 83,
+ 83, 84, 84, 84, 84, 85, 85, 85, 85, 86, 86, 86, 86, 87, 87,
+ 87, 87, 89, 89, 89, 89, 106, 106, 106, 106, 107, 107, 107, 107, 113,
+ 113, 113, 113, 118, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 120,
+ 121, 121, 121, 121, 122, 122, 122, 122, 38, 38, 42, 42, 44, 44, 59,
+ 59, 88, 88, 90, 90, -1, -1, -1, -1, 33, 33, 33, 33, 33, 33,
+ 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 40, 40, 40, 40, 40,
+ 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 63, 63, 63, 63,
+ 63, 63, 63, 63, 39, 39, 39, 39, 43, 43, 43, 43, 124, 124, 124,
+ 124, 35, 35, 62, 62, 0, 36, 64, 91, 93, 126, -1, -1, 94, 94,
+ 94, 94, 94, 94, 94, 94, 125, 125, 125, 125, 125, 125, 125, 125, 60,
+ 60, 60, 60, 96, 96, 96, 96, 123, 123, 123, 123, -1, -1, -1, -1,
+ 92, 92, 92, 92, 195, 195, 195, 195, 208, 208, 208, 208, 128, 128, 130,
+ 130, 131, 131, 162, 162, 184, 184, 194, 194, 224, 224, 226, 226, 153, 161,
+ 167, 172, 176, 177, 179, 209, 216, 217, 227, 229, 230, -1, -1, -1, -1,
+ -1, -1, -1, 129, 129, 129, 129, 129, 129, 129, 129, 132, 132, 132, 132,
+ 132, 132, 132, 132, 133, 133, 133, 133, 133, 133, 133, 133, 134, 134, 134,
+ 134, 134, 134, 134, 134, 136, 136, 136, 136, 136, 136, 136, 136, 146, 146,
+ 146, 146, 146, 146, 146, 146, 154, 154, 154, 154, 154, 154, 154, 154, 156,
+ 156, 156, 156, 156, 156, 156, 156, 160, 160, 160, 160, 160, 160, 160, 160,
+ 163, 163, 163, 163, 163, 163, 163, 163, 164, 164, 164, 164, 164, 164, 164,
+ 164, 169, 169, 169, 169, 169, 169, 169, 169, 170, 170, 170, 170, 170, 170,
+ 170, 170, 173, 173, 173, 173, 173, 173, 173, 173, 178, 178, 178, 178, 178,
+ 178, 178, 178, 181, 181, 181, 181, 181, 181, 181, 181, 185, 185, 185, 185,
+ 185, 185, 185, 185, 186, 186, 186, 186, 186, 186, 186, 186, 187, 187, 187,
+ 187, 187, 187, 187, 187, 189, 189, 189, 189, 189, 189, 189, 189, 190, 190,
+ 190, 190, 190, 190, 190, 190, 196, 196, 196, 196, 196, 196, 196, 196, 198,
+ 198, 198, 198, 198, 198, 198, 198, 228, 228, 228, 228, 228, 228, 228, 228,
+ 232, 232, 232, 232, 232, 232, 232, 232, 233, 233, 233, 233, 233, 233, 233,
+ 233, 1, 1, 1, 1, 135, 135, 135, 135, 137, 137, 137, 137, 138, 138,
+ 138, 138, 139, 139, 139, 139, 140, 140, 140, 140, 141, 141, 141, 141, 143,
+ 143, 143, 143, 147, 147, 147, 147, 149, 149, 149, 149, 150, 150, 150, 150,
+ 151, 151, 151, 151, 152, 152, 152, 152, 155, 155, 155, 155, 157, 157, 157,
+ 157, 158, 158, 158, 158, 165, 165, 165, 165, 166, 166, 166, 166, 168, 168,
+ 168, 168, 174, 174, 174, 174, 175, 175, 175, 175, 180, 180, 180, 180, 182,
+ 182, 182, 182, 183, 183, 183, 183, 188, 188, 188, 188, 191, 191, 191, 191,
+ 197, 197, 197, 197, 231, 231, 231, 231, 239, 239, 239, 239, 9, 9, 142,
+ 142, 144, 144, 145, 145, 148, 148, 159, 159, 171, 171, 206, 206, 215, 215,
+ 225, 225, 236, 236, 237, 237, 199, 207, 234, 235, 192, 192, 192, 192, 192,
+ 192, 192, 192, 193, 193, 193, 193, 193, 193, 193, 193, 200, 200, 200, 200,
+ 200, 200, 200, 200, 201, 201, 201, 201, 201, 201, 201, 201, 202, 202, 202,
+ 202, 202, 202, 202, 202, 205, 205, 205, 205, 205, 205, 205, 205, 210, 210,
+ 210, 210, 210, 210, 210, 210, 213, 213, 213, 213, 213, 213, 213, 213, 218,
+ 218, 218, 218, 218, 218, 218, 218, 219, 219, 219, 219, 219, 219, 219, 219,
+ 238, 238, 238, 238, 238, 238, 238, 238, 240, 240, 240, 240, 240, 240, 240,
+ 240, 242, 242, 242, 242, 242, 242, 242, 242, 243, 243, 243, 243, 243, 243,
+ 243, 243, 255, 255, 255, 255, 255, 255, 255, 255, 203, 203, 203, 203, 204,
+ 204, 204, 204, 211, 211, 211, 211, 212, 212, 212, 212, 214, 214, 214, 214,
+ 221, 221, 221, 221, 222, 222, 222, 222, 223, 223, 223, 223, 241, 241, 241,
+ 241, 244, 244, 244, 244, 245, 245, 245, 245, 246, 246, 246, 246, 247, 247,
+ 247, 247, 248, 248, 248, 248, 250, 250, 250, 250, 251, 251, 251, 251, 252,
+ 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 2, 2, 3, 3,
+ 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 11, 11, 12, 12, 14,
+ 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21,
+ 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30,
+ 30, 31, 31, 127, 127, 220, 220, 249, 249, -1, -1, 10, 10, 10, 10,
+ 10, 10, 10, 10, 13, 13, 13, 13, 13, 13, 13, 13, 22, 22, 22,
+ 22, 22, 22, 22, 22, 256, 256, 256, 256, 256, 256, 256, 256, 45, 45,
+ 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 47,
+ 47, 47, 47, 47, 47, 47, 47, 51, 51, 51, 51, 51, 51, 51, 51,
+ 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53,
+ 53, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55,
+ 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57,
+ 57, 57, 57, 50, 50, 50, 50, 50, 50, 50, 50, 97, 97, 97, 97,
+ 97, 97, 97, 97, 99, 99, 99, 99, 99, 99, 99, 99, 101, 101, 101,
+ 101, 101, 101, 101, 101, 105, 105, 105, 105, 105, 105, 105, 105, 111, 111,
+ 111, 111, 111, 111, 111, 111, 115, 115, 115, 115, 115, 115, 115, 115, 116,
+ 116, 116, 116, 116, 116, 116, 116, 32, 32, 32, 32, 37, 37, 37, 37,
+ 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 51, 51, 51,
+ 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55,
+ 55, 55, 56, 56, 56, 56, 57, 57, 57, 57, 61, 61, 61, 61, 65,
+ 65, 65, 65, 95, 95, 95, 95, 98, 98, 98, 98, 100, 100, 100, 100,
+ 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, 104, 104, 108, 108, 108,
+ 108, 109, 109, 109, 109, 110, 110, 110, 110, 112, 112, 112, 112, 114, 114,
+ 114, 114, 117, 117, 117, 117, 58, 58, 66, 66, 67, 67, 68, 68, 69,
+ 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 76, 76,
+ 77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 82, 82, 83, 83, 84,
+ 84, 85, 85, 86, 86, 87, 87, 89, 89, 106, 106, 107, 107, 113, 113,
+ 118, 118, 119, 119, 120, 120, 121, 121, 122, 122, 38, 42, 44, 59, 88,
+ 90, -1, -1, 33, 33, 33, 33, 34, 34, 34, 34, 40, 40, 40, 40,
+ 41, 41, 41, 41, 63, 63, 63, 63, 39, 39, 43, 43, 124, 124, 35,
+ 62, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 36, 36,
+ 36, 36, 36, 36, 36, 36, 64, 64, 64, 64, 64, 64, 64, 64, 91,
+ 91, 91, 91, 91, 91, 91, 91, 93, 93, 93, 93, 93, 93, 93, 93,
+ 126, 126, 126, 126, 126, 126, 126, 126, 94, 94, 94, 94, 125, 125, 125,
+ 125, 60, 60, 96, 96, 123, 123, -1, -1, 92, 92, 195, 195, 208, 208,
+ 128, 130, 131, 162, 184, 194, 224, 226, -1, -1, 153, 153, 153, 153, 153,
+ 153, 153, 153, 161, 161, 161, 161, 161, 161, 161, 161, 167, 167, 167, 167,
+ 167, 167, 167, 167, 172, 172, 172, 172, 172, 172, 172, 172, 176, 176, 176,
+ 176, 176, 176, 176, 176, 177, 177, 177, 177, 177, 177, 177, 177, 179, 179,
+ 179, 179, 179, 179, 179, 179, 209, 209, 209, 209, 209, 209, 209, 209, 216,
+ 216, 216, 216, 216, 216, 216, 216, 217, 217, 217, 217, 217, 217, 217, 217,
+ 227, 227, 227, 227, 227, 227, 227, 227, 229, 229, 229, 229, 229, 229, 229,
+ 229, 230, 230, 230, 230, 230, 230, 230, 230, 129, 129, 129, 129, 132, 132,
+ 132, 132, 133, 133, 133, 133, 134, 134, 134, 134, 136, 136, 136, 136, 146,
+ 146, 146, 146, 154, 154, 154, 154, 156, 156, 156, 156, 160, 160, 160, 160,
+ 163, 163, 163, 163, 164, 164, 164, 164, 169, 169, 169, 169, 170, 170, 170,
+ 170, 173, 173, 173, 173, 178, 178, 178, 178, 181, 181, 181, 181, 185, 185,
+ 185, 185, 186, 186, 186, 186, 187, 187, 187, 187, 189, 189, 189, 189, 190,
+ 190, 190, 190, 196, 196, 196, 196, 198, 198, 198, 198, 228, 228, 228, 228,
+ 232, 232, 232, 232, 233, 233, 233, 233, 1, 1, 135, 135, 137, 137, 138,
+ 138, 139, 139, 140, 140, 141, 141, 143, 143, 147, 147, 149, 149, 150, 150,
+ 151, 151, 152, 152, 155, 155, 157, 157, 158, 158, 165, 165, 166, 166, 168,
+ 168, 174, 174, 175, 175, 180, 180, 182, 182, 183, 183, 188, 188, 191, 191,
+ 197, 197, 231, 231, 239, 239, 9, 142, 144, 145, 148, 159, 171, 206, 215,
+ 225, 236, 237, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 199, 199,
+ 199, 199, 199, 199, 199, 199, 207, 207, 207, 207, 207, 207, 207, 207, 234,
+ 234, 234, 234, 234, 234, 234, 234, 235, 235, 235, 235, 235, 235, 235, 235,
+ 192, 192, 192, 192, 193, 193, 193, 193, 200, 200, 200, 200, 201, 201, 201,
+ 201, 202, 202, 202, 202, 205, 205, 205, 205, 210, 210, 210, 210, 213, 213,
+ 213, 213, 218, 218, 218, 218, 219, 219, 219, 219, 238, 238, 238, 238, 240,
+ 240, 240, 240, 242, 242, 242, 242, 243, 243, 243, 243, 255, 255, 255, 255,
+ 203, 203, 204, 204, 211, 211, 212, 212, 214, 214, 221, 221, 222, 222, 223,
+ 223, 241, 241, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 250, 250,
+ 251, 251, 252, 252, 253, 253, 254, 254, 2, 3, 4, 5, 6, 7, 8,
+ 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27,
+ 28, 29, 30, 31, 127, 220, 249, -1, 10, 10, 10, 10, 13, 13, 13,
+ 13, 22, 22, 22, 22, 256, 256, 256, 256,
};
static const gpr_uint8 inverse_base64[256] = {
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255,
- 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
- 255, 64, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
- 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33,
- 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
- 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
- 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255,
+ 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
+ 255, 64, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33,
+ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+ 255,
};
/* emission helpers */
-static void on_hdr(grpc_chttp2_hpack_parser *p, grpc_mdelem *md,
- int add_to_table) {
- if (add_to_table) {
- GRPC_MDELEM_REF(md);
- grpc_chttp2_hptbl_add(&p->table, md);
- }
- p->on_header(p->on_header_user_data, md);
+static void
+on_hdr (grpc_chttp2_hpack_parser * p, grpc_mdelem * md, int add_to_table)
+{
+ if (add_to_table)
+ {
+ GRPC_MDELEM_REF (md);
+ grpc_chttp2_hptbl_add (&p->table, md);
+ }
+ p->on_header (p->on_header_user_data, md);
}
-static grpc_mdstr *take_string(grpc_chttp2_hpack_parser *p,
- grpc_chttp2_hpack_parser_string *str) {
- grpc_mdstr *s = grpc_mdstr_from_buffer(p->table.mdctx, (gpr_uint8 *)str->str,
- str->length);
+static grpc_mdstr *
+take_string (grpc_chttp2_hpack_parser * p, grpc_chttp2_hpack_parser_string * str)
+{
+ grpc_mdstr *s = grpc_mdstr_from_buffer (p->table.mdctx, (gpr_uint8 *) str->str,
+ str->length);
str->length = 0;
return s;
}
/* jump to the next state */
-static int parse_next(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
+static int
+parse_next (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
p->state = *p->next_state++;
- return p->state(p, cur, end);
+ return p->state (p, cur, end);
}
/* begin parsing a header: all functionality is encoded into lookup tables
above */
-static int parse_begin(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_begin;
- return 1;
- }
-
- return first_byte_action[first_byte_lut[*cur]](p, cur, end);
+static int
+parse_begin (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_begin;
+ return 1;
+ }
+
+ return first_byte_action[first_byte_lut[*cur]] (p, cur, end);
}
/* stream dependency and prioritization data: we just skip it */
-static int parse_stream_weight(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_stream_weight;
- return 1;
- }
-
- return p->after_prioritization(p, cur + 1, end);
+static int
+parse_stream_weight (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_stream_weight;
+ return 1;
+ }
+
+ return p->after_prioritization (p, cur + 1, end);
}
-static int parse_stream_dep3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_stream_dep3;
- return 1;
- }
+static int
+parse_stream_dep3 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_stream_dep3;
+ return 1;
+ }
- return parse_stream_weight(p, cur + 1, end);
+ return parse_stream_weight (p, cur + 1, end);
}
-static int parse_stream_dep2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_stream_dep2;
- return 1;
- }
+static int
+parse_stream_dep2 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_stream_dep2;
+ return 1;
+ }
- return parse_stream_dep3(p, cur + 1, end);
+ return parse_stream_dep3 (p, cur + 1, end);
}
-static int parse_stream_dep1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_stream_dep1;
- return 1;
- }
+static int
+parse_stream_dep1 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_stream_dep1;
+ return 1;
+ }
- return parse_stream_dep2(p, cur + 1, end);
+ return parse_stream_dep2 (p, cur + 1, end);
}
-static int parse_stream_dep0(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_stream_dep0;
- return 1;
- }
+static int
+parse_stream_dep0 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_stream_dep0;
+ return 1;
+ }
- return parse_stream_dep1(p, cur + 1, end);
+ return parse_stream_dep1 (p, cur + 1, end);
}
/* emit an indexed field; for now just logs it to console; jumps to
begin the next field on completion */
-static int finish_indexed_field(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
- grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
- GRPC_MDELEM_REF(md);
- on_hdr(p, md, 0);
- return parse_begin(p, cur, end);
+static int
+finish_indexed_field (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ grpc_mdelem *md = grpc_chttp2_hptbl_lookup (&p->table, p->index);
+ GRPC_MDELEM_REF (md);
+ on_hdr (p, md, 0);
+ return parse_begin (p, cur, end);
}
/* parse an indexed field with index < 127 */
-static int parse_indexed_field(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_indexed_field (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
p->index = (*cur) & 0x7f;
- return finish_indexed_field(p, cur + 1, end);
+ return finish_indexed_field (p, cur + 1, end);
}
/* parse an indexed field with index >= 127 */
-static int parse_indexed_field_x(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_indexed_field_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- finish_indexed_field};
+ finish_indexed_field
+ };
p->next_state = and_then;
p->index = 0x7f;
p->parsing.value = &p->index;
- return parse_value0(p, cur + 1, end);
+ return parse_value0 (p, cur + 1, end);
}
/* finish a literal header with incremental indexing: just log, and jump to '
begin */
-static int finish_lithdr_incidx(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
- grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
- on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx,
- GRPC_MDSTR_REF(md->key),
- take_string(p, &p->value)),
- 1);
- return parse_begin(p, cur, end);
+static int
+finish_lithdr_incidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ grpc_mdelem *md = grpc_chttp2_hptbl_lookup (&p->table, p->index);
+ on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, GRPC_MDSTR_REF (md->key), take_string (p, &p->value)), 1);
+ return parse_begin (p, cur, end);
}
/* finish a literal header with incremental indexing with no index */
-static int finish_lithdr_incidx_v(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
- on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx,
- take_string(p, &p->key),
- take_string(p, &p->value)),
- 1);
- return parse_begin(p, cur, end);
+static int
+finish_lithdr_incidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, take_string (p, &p->key), take_string (p, &p->value)), 1);
+ return parse_begin (p, cur, end);
}
/* parse a literal header with incremental indexing; index < 63 */
-static int parse_lithdr_incidx(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_lithdr_incidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- parse_value_string_with_indexed_key, finish_lithdr_incidx};
+ parse_value_string_with_indexed_key, finish_lithdr_incidx
+ };
p->next_state = and_then;
p->index = (*cur) & 0x3f;
- return parse_string_prefix(p, cur + 1, end);
+ return parse_string_prefix (p, cur + 1, end);
}
/* parse a literal header with incremental indexing; index >= 63 */
-static int parse_lithdr_incidx_x(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_lithdr_incidx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- parse_string_prefix, parse_value_string_with_indexed_key,
- finish_lithdr_incidx};
+ parse_string_prefix, parse_value_string_with_indexed_key,
+ finish_lithdr_incidx
+ };
p->next_state = and_then;
p->index = 0x3f;
p->parsing.value = &p->index;
- return parse_value0(p, cur + 1, end);
+ return parse_value0 (p, cur + 1, end);
}
/* parse a literal header with incremental indexing; index = 0 */
-static int parse_lithdr_incidx_v(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_lithdr_incidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- parse_key_string, parse_string_prefix,
- parse_value_string_with_literal_key, finish_lithdr_incidx_v};
+ parse_key_string, parse_string_prefix,
+ parse_value_string_with_literal_key, finish_lithdr_incidx_v
+ };
p->next_state = and_then;
- return parse_string_prefix(p, cur + 1, end);
+ return parse_string_prefix (p, cur + 1, end);
}
/* finish a literal header without incremental indexing */
-static int finish_lithdr_notidx(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
- grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
- on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx,
- GRPC_MDSTR_REF(md->key),
- take_string(p, &p->value)),
- 0);
- return parse_begin(p, cur, end);
+static int
+finish_lithdr_notidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ grpc_mdelem *md = grpc_chttp2_hptbl_lookup (&p->table, p->index);
+ on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, GRPC_MDSTR_REF (md->key), take_string (p, &p->value)), 0);
+ return parse_begin (p, cur, end);
}
/* finish a literal header without incremental indexing with index = 0 */
-static int finish_lithdr_notidx_v(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
- on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx,
- take_string(p, &p->key),
- take_string(p, &p->value)),
- 0);
- return parse_begin(p, cur, end);
+static int
+finish_lithdr_notidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, take_string (p, &p->key), take_string (p, &p->value)), 0);
+ return parse_begin (p, cur, end);
}
/* parse a literal header without incremental indexing; index < 15 */
-static int parse_lithdr_notidx(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_lithdr_notidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- parse_value_string_with_indexed_key, finish_lithdr_notidx};
+ parse_value_string_with_indexed_key, finish_lithdr_notidx
+ };
p->next_state = and_then;
p->index = (*cur) & 0xf;
- return parse_string_prefix(p, cur + 1, end);
+ return parse_string_prefix (p, cur + 1, end);
}
/* parse a literal header without incremental indexing; index >= 15 */
-static int parse_lithdr_notidx_x(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_lithdr_notidx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- parse_string_prefix, parse_value_string_with_indexed_key,
- finish_lithdr_notidx};
+ parse_string_prefix, parse_value_string_with_indexed_key,
+ finish_lithdr_notidx
+ };
p->next_state = and_then;
p->index = 0xf;
p->parsing.value = &p->index;
- return parse_value0(p, cur + 1, end);
+ return parse_value0 (p, cur + 1, end);
}
/* parse a literal header without incremental indexing; index == 0 */
-static int parse_lithdr_notidx_v(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_lithdr_notidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- parse_key_string, parse_string_prefix,
- parse_value_string_with_literal_key, finish_lithdr_notidx_v};
+ parse_key_string, parse_string_prefix,
+ parse_value_string_with_literal_key, finish_lithdr_notidx_v
+ };
p->next_state = and_then;
- return parse_string_prefix(p, cur + 1, end);
+ return parse_string_prefix (p, cur + 1, end);
}
/* finish a literal header that is never indexed */
-static int finish_lithdr_nvridx(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
- grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
- on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx,
- GRPC_MDSTR_REF(md->key),
- take_string(p, &p->value)),
- 0);
- return parse_begin(p, cur, end);
+static int
+finish_lithdr_nvridx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ grpc_mdelem *md = grpc_chttp2_hptbl_lookup (&p->table, p->index);
+ on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, GRPC_MDSTR_REF (md->key), take_string (p, &p->value)), 0);
+ return parse_begin (p, cur, end);
}
/* finish a literal header that is never indexed with an extra value */
-static int finish_lithdr_nvridx_v(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
- on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx,
- take_string(p, &p->key),
- take_string(p, &p->value)),
- 0);
- return parse_begin(p, cur, end);
+static int
+finish_lithdr_nvridx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, take_string (p, &p->key), take_string (p, &p->value)), 0);
+ return parse_begin (p, cur, end);
}
/* parse a literal header that is never indexed; index < 15 */
-static int parse_lithdr_nvridx(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_lithdr_nvridx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- parse_value_string_with_indexed_key, finish_lithdr_nvridx};
+ parse_value_string_with_indexed_key, finish_lithdr_nvridx
+ };
p->next_state = and_then;
p->index = (*cur) & 0xf;
- return parse_string_prefix(p, cur + 1, end);
+ return parse_string_prefix (p, cur + 1, end);
}
/* parse a literal header that is never indexed; index >= 15 */
-static int parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_lithdr_nvridx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- parse_string_prefix, parse_value_string_with_indexed_key,
- finish_lithdr_nvridx};
+ parse_string_prefix, parse_value_string_with_indexed_key,
+ finish_lithdr_nvridx
+ };
p->next_state = and_then;
p->index = 0xf;
p->parsing.value = &p->index;
- return parse_value0(p, cur + 1, end);
+ return parse_value0 (p, cur + 1, end);
}
/* parse a literal header that is never indexed; index == 0 */
-static int parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_lithdr_nvridx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- parse_key_string, parse_string_prefix,
- parse_value_string_with_literal_key, finish_lithdr_nvridx_v};
+ parse_key_string, parse_string_prefix,
+ parse_value_string_with_literal_key, finish_lithdr_nvridx_v
+ };
p->next_state = and_then;
- return parse_string_prefix(p, cur + 1, end);
+ return parse_string_prefix (p, cur + 1, end);
}
/* finish parsing a max table size change */
-static int finish_max_tbl_size(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
- gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index);
- abort(); /* not implemented */
- return parse_begin(p, cur, end);
+static int
+finish_max_tbl_size (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ gpr_log (GPR_INFO, "MAX TABLE SIZE: %d", p->index);
+ abort (); /* not implemented */
+ return parse_begin (p, cur, end);
}
/* parse a max table size change, max size < 15 */
-static int parse_max_tbl_size(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
+static int
+parse_max_tbl_size (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
p->index = (*cur) & 0xf;
- return finish_max_tbl_size(p, cur + 1, end);
+ return finish_max_tbl_size (p, cur + 1, end);
}
/* parse a max table size change, max size >= 15 */
-static int parse_max_tbl_size_x(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
+static int
+parse_max_tbl_size_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
static const grpc_chttp2_hpack_parser_state and_then[] = {
- finish_max_tbl_size};
+ finish_max_tbl_size
+ };
p->next_state = and_then;
p->index = 0xf;
p->parsing.value = &p->index;
- return parse_value0(p, cur + 1, end);
+ return parse_value0 (p, cur + 1, end);
}
/* a parse error: jam the parse state into parse_error, and return error */
-static int parse_error(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
+static int
+parse_error (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
p->state = parse_error;
return 0;
}
/* parse the 1st byte of a varint into p->parsing.value
no overflow is possible */
-static int parse_value0(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_value0;
- return 1;
- }
+static int
+parse_value0 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_value0;
+ return 1;
+ }
*p->parsing.value += (*cur) & 0x7f;
- if ((*cur) & 0x80) {
- return parse_value1(p, cur + 1, end);
- } else {
- return parse_next(p, cur + 1, end);
- }
+ if ((*cur) & 0x80)
+ {
+ return parse_value1 (p, cur + 1, end);
+ }
+ else
+ {
+ return parse_next (p, cur + 1, end);
+ }
}
/* parse the 2nd byte of a varint into p->parsing.value
no overflow is possible */
-static int parse_value1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_value1;
- return 1;
- }
-
- *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 7;
-
- if ((*cur) & 0x80) {
- return parse_value2(p, cur + 1, end);
- } else {
- return parse_next(p, cur + 1, end);
- }
+static int
+parse_value1 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_value1;
+ return 1;
+ }
+
+ *p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 7;
+
+ if ((*cur) & 0x80)
+ {
+ return parse_value2 (p, cur + 1, end);
+ }
+ else
+ {
+ return parse_next (p, cur + 1, end);
+ }
}
/* parse the 3rd byte of a varint into p->parsing.value
no overflow is possible */
-static int parse_value2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_value2;
- return 1;
- }
-
- *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 14;
-
- if ((*cur) & 0x80) {
- return parse_value3(p, cur + 1, end);
- } else {
- return parse_next(p, cur + 1, end);
- }
+static int
+parse_value2 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_value2;
+ return 1;
+ }
+
+ *p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 14;
+
+ if ((*cur) & 0x80)
+ {
+ return parse_value3 (p, cur + 1, end);
+ }
+ else
+ {
+ return parse_next (p, cur + 1, end);
+ }
}
/* parse the 4th byte of a varint into p->parsing.value
no overflow is possible */
-static int parse_value3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_value3;
- return 1;
- }
-
- *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 21;
-
- if ((*cur) & 0x80) {
- return parse_value4(p, cur + 1, end);
- } else {
- return parse_next(p, cur + 1, end);
- }
+static int
+parse_value3 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_value3;
+ return 1;
+ }
+
+ *p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 21;
+
+ if ((*cur) & 0x80)
+ {
+ return parse_value4 (p, cur + 1, end);
+ }
+ else
+ {
+ return parse_next (p, cur + 1, end);
+ }
}
/* parse the 5th byte of a varint into p->parsing.value
depending on the byte, we may overflow, and care must be taken */
-static int parse_value4(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
+static int
+parse_value4 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
gpr_uint8 c;
gpr_uint32 cur_value;
gpr_uint32 add_value;
- if (cur == end) {
- p->state = parse_value4;
- return 1;
- }
+ if (cur == end)
+ {
+ p->state = parse_value4;
+ return 1;
+ }
c = (*cur) & 0x7f;
- if (c > 0xf) {
- goto error;
- }
+ if (c > 0xf)
+ {
+ goto error;
+ }
cur_value = *p->parsing.value;
- add_value = ((gpr_uint32)c) << 28;
- if (add_value > 0xffffffffu - cur_value) {
- goto error;
- }
+ add_value = ((gpr_uint32) c) << 28;
+ if (add_value > 0xffffffffu - cur_value)
+ {
+ goto error;
+ }
*p->parsing.value = cur_value + add_value;
- if ((*cur) & 0x80) {
- return parse_value5up(p, cur + 1, end);
- } else {
- return parse_next(p, cur + 1, end);
- }
+ if ((*cur) & 0x80)
+ {
+ return parse_value5up (p, cur + 1, end);
+ }
+ else
+ {
+ return parse_next (p, cur + 1, end);
+ }
error:
- gpr_log(GPR_ERROR,
- "integer overflow in hpack integer decoding: have 0x%08x, "
- "got byte 0x%02x",
- *p->parsing.value, *cur);
- return parse_error(p, cur, end);
+ gpr_log (GPR_ERROR, "integer overflow in hpack integer decoding: have 0x%08x, " "got byte 0x%02x", *p->parsing.value, *cur);
+ return parse_error (p, cur, end);
}
/* parse any trailing bytes in a varint: it's possible to append an arbitrary
number of 0x80's and not affect the value - a zero will terminate - and
anything else will overflow */
-static int parse_value5up(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- while (cur != end && *cur == 0x80) {
- ++cur;
- }
-
- if (cur == end) {
- p->state = parse_value5up;
- return 1;
- }
-
- if (*cur == 0) {
- return parse_next(p, cur + 1, end);
- }
-
- gpr_log(GPR_ERROR,
- "integer overflow in hpack integer decoding: have 0x%08x, "
- "got byte 0x%02x sometime after byte 4");
- return parse_error(p, cur, end);
+static int
+parse_value5up (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ while (cur != end && *cur == 0x80)
+ {
+ ++cur;
+ }
+
+ if (cur == end)
+ {
+ p->state = parse_value5up;
+ return 1;
+ }
+
+ if (*cur == 0)
+ {
+ return parse_next (p, cur + 1, end);
+ }
+
+ gpr_log (GPR_ERROR, "integer overflow in hpack integer decoding: have 0x%08x, " "got byte 0x%02x sometime after byte 4");
+ return parse_error (p, cur, end);
}
/* parse a string prefix */
-static int parse_string_prefix(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur, const gpr_uint8 *end) {
- if (cur == end) {
- p->state = parse_string_prefix;
- return 1;
- }
+static int
+parse_string_prefix (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (cur == end)
+ {
+ p->state = parse_string_prefix;
+ return 1;
+ }
p->strlen = (*cur) & 0x7f;
p->huff = (*cur) >> 7;
- if (p->strlen == 0x7f) {
- p->parsing.value = &p->strlen;
- return parse_value0(p, cur + 1, end);
- } else {
- return parse_next(p, cur + 1, end);
- }
+ if (p->strlen == 0x7f)
+ {
+ p->parsing.value = &p->strlen;
+ return parse_value0 (p, cur + 1, end);
+ }
+ else
+ {
+ return parse_next (p, cur + 1, end);
+ }
}
/* append some bytes to a string */
-static void append_bytes(grpc_chttp2_hpack_parser_string *str,
- const gpr_uint8 *data, size_t length) {
- if (length + str->length > str->capacity) {
- GPR_ASSERT(str->length + length <= GPR_UINT32_MAX);
- str->capacity = (gpr_uint32)(str->length + length);
- str->str = gpr_realloc(str->str, str->capacity);
- }
- memcpy(str->str + str->length, data, length);
- GPR_ASSERT(length <= GPR_UINT32_MAX - str->length);
- str->length += (gpr_uint32)length;
+static void
+append_bytes (grpc_chttp2_hpack_parser_string * str, const gpr_uint8 * data, size_t length)
+{
+ if (length + str->length > str->capacity)
+ {
+ GPR_ASSERT (str->length + length <= GPR_UINT32_MAX);
+ str->capacity = (gpr_uint32) (str->length + length);
+ str->str = gpr_realloc (str->str, str->capacity);
+ }
+ memcpy (str->str + str->length, data, length);
+ GPR_ASSERT (length <= GPR_UINT32_MAX - str->length);
+ str->length += (gpr_uint32) length;
}
-static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
+static int
+append_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
grpc_chttp2_hpack_parser_string *str = p->parsing.str;
gpr_uint32 bits;
gpr_uint8 decoded[3];
- switch ((binary_state)p->binary) {
+ switch ((binary_state) p->binary)
+ {
case NOT_BINARY:
- append_bytes(str, cur, (size_t)(end - cur));
+ append_bytes (str, cur, (size_t) (end - cur));
return 1;
b64_byte0:
case B64_BYTE0:
- if (cur == end) {
- p->binary = B64_BYTE0;
- return 1;
- }
+ if (cur == end)
+ {
+ p->binary = B64_BYTE0;
+ return 1;
+ }
bits = inverse_base64[*cur];
++cur;
if (bits == 255)
- return 0;
+ return 0;
else if (bits == 64)
- goto b64_byte0;
+ goto b64_byte0;
p->base64_buffer = bits << 18;
- /* fallthrough */
+ /* fallthrough */
b64_byte1:
case B64_BYTE1:
- if (cur == end) {
- p->binary = B64_BYTE1;
- return 1;
- }
+ if (cur == end)
+ {
+ p->binary = B64_BYTE1;
+ return 1;
+ }
bits = inverse_base64[*cur];
++cur;
if (bits == 255)
- return 0;
+ return 0;
else if (bits == 64)
- goto b64_byte1;
+ goto b64_byte1;
p->base64_buffer |= bits << 12;
- /* fallthrough */
+ /* fallthrough */
b64_byte2:
case B64_BYTE2:
- if (cur == end) {
- p->binary = B64_BYTE2;
- return 1;
- }
+ if (cur == end)
+ {
+ p->binary = B64_BYTE2;
+ return 1;
+ }
bits = inverse_base64[*cur];
++cur;
if (bits == 255)
- return 0;
+ return 0;
else if (bits == 64)
- goto b64_byte2;
+ goto b64_byte2;
p->base64_buffer |= bits << 6;
- /* fallthrough */
+ /* fallthrough */
b64_byte3:
case B64_BYTE3:
- if (cur == end) {
- p->binary = B64_BYTE3;
- return 1;
- }
+ if (cur == end)
+ {
+ p->binary = B64_BYTE3;
+ return 1;
+ }
bits = inverse_base64[*cur];
++cur;
if (bits == 255)
- return 0;
+ return 0;
else if (bits == 64)
- goto b64_byte3;
+ goto b64_byte3;
p->base64_buffer |= bits;
bits = p->base64_buffer;
- decoded[0] = (gpr_uint8)(bits >> 16);
- decoded[1] = (gpr_uint8)(bits >> 8);
- decoded[2] = (gpr_uint8)(bits);
- append_bytes(str, decoded, 3);
+ decoded[0] = (gpr_uint8) (bits >> 16);
+ decoded[1] = (gpr_uint8) (bits >> 8);
+ decoded[2] = (gpr_uint8) (bits);
+ append_bytes (str, decoded, 3);
goto b64_byte0;
- }
- gpr_log(GPR_ERROR, "should never reach here");
- abort();
+ }
+ gpr_log (GPR_ERROR, "should never reach here");
+ abort ();
return 1;
}
/* append a null terminator to a string */
-static int finish_str(grpc_chttp2_hpack_parser *p) {
+static int
+finish_str (grpc_chttp2_hpack_parser * p)
+{
gpr_uint8 terminator = 0;
gpr_uint8 decoded[2];
gpr_uint32 bits;
grpc_chttp2_hpack_parser_string *str = p->parsing.str;
- switch ((binary_state)p->binary) {
+ switch ((binary_state) p->binary)
+ {
case NOT_BINARY:
break;
case B64_BYTE0:
break;
case B64_BYTE1:
- gpr_log(GPR_ERROR, "illegal base64 encoding");
- return 0; /* illegal encoding */
+ gpr_log (GPR_ERROR, "illegal base64 encoding");
+ return 0; /* illegal encoding */
case B64_BYTE2:
bits = p->base64_buffer;
- if (bits & 0xffff) {
- gpr_log(GPR_ERROR, "trailing bits in base64 encoding: 0x%04x",
- bits & 0xffff);
- return 0;
- }
- decoded[0] = (gpr_uint8)(bits >> 16);
- append_bytes(str, decoded, 1);
+ if (bits & 0xffff)
+ {
+ gpr_log (GPR_ERROR, "trailing bits in base64 encoding: 0x%04x", bits & 0xffff);
+ return 0;
+ }
+ decoded[0] = (gpr_uint8) (bits >> 16);
+ append_bytes (str, decoded, 1);
break;
case B64_BYTE3:
bits = p->base64_buffer;
- if (bits & 0xff) {
- gpr_log(GPR_ERROR, "trailing bits in base64 encoding: 0x%02x",
- bits & 0xff);
- return 0;
- }
- decoded[0] = (gpr_uint8)(bits >> 16);
- decoded[1] = (gpr_uint8)(bits >> 8);
- append_bytes(str, decoded, 2);
+ if (bits & 0xff)
+ {
+ gpr_log (GPR_ERROR, "trailing bits in base64 encoding: 0x%02x", bits & 0xff);
+ return 0;
+ }
+ decoded[0] = (gpr_uint8) (bits >> 16);
+ decoded[1] = (gpr_uint8) (bits >> 8);
+ append_bytes (str, decoded, 2);
break;
- }
- append_bytes(str, &terminator, 1);
- p->parsing.str->length--; /* don't actually count the null terminator */
+ }
+ append_bytes (str, &terminator, 1);
+ p->parsing.str->length--; /* don't actually count the null terminator */
return 1;
}
/* decode a nibble from a huffman encoded stream */
-static int huff_nibble(grpc_chttp2_hpack_parser *p, gpr_uint8 nibble) {
+static int
+huff_nibble (grpc_chttp2_hpack_parser * p, gpr_uint8 nibble)
+{
gpr_int16 emit = emit_sub_tbl[16 * emit_tbl[p->huff_state] + nibble];
gpr_int16 next = next_sub_tbl[16 * next_tbl[p->huff_state] + nibble];
- if (emit != -1) {
- if (emit >= 0 && emit < 256) {
- gpr_uint8 c = (gpr_uint8)emit;
- if (!append_string(p, &c, (&c) + 1)) return 0;
- } else {
- assert(emit == 256);
+ if (emit != -1)
+ {
+ if (emit >= 0 && emit < 256)
+ {
+ gpr_uint8 c = (gpr_uint8) emit;
+ if (!append_string (p, &c, (&c) + 1))
+ return 0;
+ }
+ else
+ {
+ assert (emit == 256);
+ }
}
- }
p->huff_state = next;
return 1;
}
/* decode full bytes from a huffman encoded stream */
-static int add_huff_bytes(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- for (; cur != end; ++cur) {
- if (!huff_nibble(p, *cur >> 4) || !huff_nibble(p, *cur & 0xf)) return 0;
- }
+static int
+add_huff_bytes (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ for (; cur != end; ++cur)
+ {
+ if (!huff_nibble (p, *cur >> 4) || !huff_nibble (p, *cur & 0xf))
+ return 0;
+ }
return 1;
}
/* decode some string bytes based on the current decoding mode
(huffman or not) */
-static int add_str_bytes(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- if (p->huff) {
- return add_huff_bytes(p, cur, end);
- } else {
- return append_string(p, cur, end);
- }
+static int
+add_str_bytes (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ if (p->huff)
+ {
+ return add_huff_bytes (p, cur, end);
+ }
+ else
+ {
+ return append_string (p, cur, end);
+ }
}
/* parse a string - tries to do large chunks at a time */
-static int parse_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
+static int
+parse_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
size_t remaining = p->strlen - p->strgot;
- size_t given = (size_t)(end - cur);
- if (remaining <= given) {
- return add_str_bytes(p, cur, cur + remaining) && finish_str(p) &&
- parse_next(p, cur + remaining, end);
- } else {
- if (!add_str_bytes(p, cur, cur + given)) return 0;
- GPR_ASSERT(given <= GPR_UINT32_MAX - p->strgot);
- p->strgot += (gpr_uint32)given;
- p->state = parse_string;
- return 1;
- }
+ size_t given = (size_t) (end - cur);
+ if (remaining <= given)
+ {
+ return add_str_bytes (p, cur, cur + remaining) && finish_str (p) && parse_next (p, cur + remaining, end);
+ }
+ else
+ {
+ if (!add_str_bytes (p, cur, cur + given))
+ return 0;
+ GPR_ASSERT (given <= GPR_UINT32_MAX - p->strgot);
+ p->strgot += (gpr_uint32) given;
+ p->state = parse_string;
+ return 1;
+ }
}
/* begin parsing a string - performs setup, calls parse_string */
-static int begin_parse_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end, gpr_uint8 binary,
- grpc_chttp2_hpack_parser_string *str) {
+static int
+begin_parse_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end, gpr_uint8 binary, grpc_chttp2_hpack_parser_string * str)
+{
p->strgot = 0;
str->length = 0;
p->parsing.str = str;
p->huff_state = 0;
p->binary = binary;
- return parse_string(p, cur, end);
+ return parse_string (p, cur, end);
}
/* parse the key string */
-static int parse_key_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- return begin_parse_string(p, cur, end, NOT_BINARY, &p->key);
+static int
+parse_key_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ return begin_parse_string (p, cur, end, NOT_BINARY, &p->key);
}
/* check if a key represents a binary header or not */
-typedef enum { BINARY_HEADER, PLAINTEXT_HEADER, ERROR_HEADER } is_binary_header;
+typedef enum
+{ BINARY_HEADER, PLAINTEXT_HEADER, ERROR_HEADER } is_binary_header;
-static is_binary_header is_binary_literal_header(grpc_chttp2_hpack_parser *p) {
- return grpc_is_binary_header(p->key.str, p->key.length) ? BINARY_HEADER
- : PLAINTEXT_HEADER;
+static is_binary_header
+is_binary_literal_header (grpc_chttp2_hpack_parser * p)
+{
+ return grpc_is_binary_header (p->key.str, p->key.length) ? BINARY_HEADER : PLAINTEXT_HEADER;
}
-static is_binary_header is_binary_indexed_header(grpc_chttp2_hpack_parser *p) {
- grpc_mdelem *elem = grpc_chttp2_hptbl_lookup(&p->table, p->index);
- if (!elem) return ERROR_HEADER;
- return grpc_is_binary_header(
- (const char *)GPR_SLICE_START_PTR(elem->key->slice),
- GPR_SLICE_LENGTH(elem->key->slice))
- ? BINARY_HEADER
- : PLAINTEXT_HEADER;
+static is_binary_header
+is_binary_indexed_header (grpc_chttp2_hpack_parser * p)
+{
+ grpc_mdelem *elem = grpc_chttp2_hptbl_lookup (&p->table, p->index);
+ if (!elem)
+ return ERROR_HEADER;
+ return grpc_is_binary_header ((const char *) GPR_SLICE_START_PTR (elem->key->slice), GPR_SLICE_LENGTH (elem->key->slice)) ? BINARY_HEADER : PLAINTEXT_HEADER;
}
/* parse the value string */
-static int parse_value_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
- const gpr_uint8 *end, is_binary_header type) {
- switch (type) {
+static int
+parse_value_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end, is_binary_header type)
+{
+ switch (type)
+ {
case BINARY_HEADER:
- return begin_parse_string(p, cur, end, B64_BYTE0, &p->value);
+ return begin_parse_string (p, cur, end, B64_BYTE0, &p->value);
case PLAINTEXT_HEADER:
- return begin_parse_string(p, cur, end, NOT_BINARY, &p->value);
+ return begin_parse_string (p, cur, end, NOT_BINARY, &p->value);
case ERROR_HEADER:
return 0;
- }
+ }
/* Add code to prevent return without value error */
- gpr_log(GPR_ERROR, "Should never reach beyond switch in parse_value_string");
- abort();
+ gpr_log (GPR_ERROR, "Should never reach beyond switch in parse_value_string");
+ abort ();
return 0;
}
-static int parse_value_string_with_indexed_key(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- return parse_value_string(p, cur, end, is_binary_indexed_header(p));
+static int
+parse_value_string_with_indexed_key (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ return parse_value_string (p, cur, end, is_binary_indexed_header (p));
}
-static int parse_value_string_with_literal_key(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *cur,
- const gpr_uint8 *end) {
- return parse_value_string(p, cur, end, is_binary_literal_header(p));
+static int
+parse_value_string_with_literal_key (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end)
+{
+ return parse_value_string (p, cur, end, is_binary_literal_header (p));
}
/* PUBLIC INTERFACE */
-static void on_header_not_set(void *user_data, grpc_mdelem *md) {
- char *keyhex = gpr_dump_slice(md->key->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
- char *valuehex =
- gpr_dump_slice(md->value->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
- gpr_log(GPR_ERROR, "on_header callback not set; key=%s value=%s", keyhex,
- valuehex);
- gpr_free(keyhex);
- gpr_free(valuehex);
- GRPC_MDELEM_UNREF(md);
- abort();
+static void
+on_header_not_set (void *user_data, grpc_mdelem * md)
+{
+ char *keyhex = gpr_dump_slice (md->key->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
+ char *valuehex = gpr_dump_slice (md->value->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
+ gpr_log (GPR_ERROR, "on_header callback not set; key=%s value=%s", keyhex, valuehex);
+ gpr_free (keyhex);
+ gpr_free (valuehex);
+ GRPC_MDELEM_UNREF (md);
+ abort ();
}
-void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p,
- grpc_mdctx *mdctx) {
+void
+grpc_chttp2_hpack_parser_init (grpc_chttp2_hpack_parser * p, grpc_mdctx * mdctx)
+{
p->on_header = on_header_not_set;
p->on_header_user_data = NULL;
p->state = parse_begin;
@@ -1354,58 +1429,62 @@ void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p,
p->value.str = NULL;
p->value.capacity = 0;
p->value.length = 0;
- grpc_chttp2_hptbl_init(&p->table, mdctx);
+ grpc_chttp2_hptbl_init (&p->table, mdctx);
}
-void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p) {
+void
+grpc_chttp2_hpack_parser_set_has_priority (grpc_chttp2_hpack_parser * p)
+{
p->after_prioritization = p->state;
p->state = parse_stream_dep0;
}
-void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p) {
- grpc_chttp2_hptbl_destroy(&p->table);
- gpr_free(p->key.str);
- gpr_free(p->value.str);
+void
+grpc_chttp2_hpack_parser_destroy (grpc_chttp2_hpack_parser * p)
+{
+ grpc_chttp2_hptbl_destroy (&p->table);
+ gpr_free (p->key.str);
+ gpr_free (p->value.str);
}
-int grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *beg, const gpr_uint8 *end) {
+int
+grpc_chttp2_hpack_parser_parse (grpc_chttp2_hpack_parser * p, const gpr_uint8 * beg, const gpr_uint8 * end)
+{
/* TODO(ctiller): limit the distance of end from beg, and perform multiple
- steps in the event of a large chunk of data to limit
- stack space usage when no tail call optimization is
- available */
- return p->state(p, beg, end);
+ steps in the event of a large chunk of data to limit
+ stack space usage when no tail call optimization is
+ available */
+ return p->state (p, beg, end);
}
-grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(
- void *hpack_parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list) {
+grpc_chttp2_parse_error
+grpc_chttp2_header_parser_parse (void *hpack_parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list)
+{
grpc_chttp2_hpack_parser *parser = hpack_parser;
- if (!grpc_chttp2_hpack_parser_parse(parser, GPR_SLICE_START_PTR(slice),
- GPR_SLICE_END_PTR(slice))) {
- return GRPC_CHTTP2_CONNECTION_ERROR;
- }
- if (is_last) {
- if (parser->is_boundary && parser->state != parse_begin) {
- gpr_log(GPR_ERROR,
- "end of header frame not aligned with a hpack record boundary");
+ if (!grpc_chttp2_hpack_parser_parse (parser, GPR_SLICE_START_PTR (slice), GPR_SLICE_END_PTR (slice)))
+ {
return GRPC_CHTTP2_CONNECTION_ERROR;
}
- if (parser->is_boundary) {
- grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into(
- &stream_parsing->incoming_metadata,
- &stream_parsing->data_parser.incoming_sopb);
- grpc_chttp2_list_add_parsing_seen_stream(transport_parsing,
- stream_parsing);
- }
- if (parser->is_eof) {
- stream_parsing->received_close = 1;
+ if (is_last)
+ {
+ if (parser->is_boundary && parser->state != parse_begin)
+ {
+ gpr_log (GPR_ERROR, "end of header frame not aligned with a hpack record boundary");
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
+ if (parser->is_boundary)
+ {
+ grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into (&stream_parsing->incoming_metadata, &stream_parsing->data_parser.incoming_sopb);
+ grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing);
+ }
+ if (parser->is_eof)
+ {
+ stream_parsing->received_close = 1;
+ }
+ parser->on_header = on_header_not_set;
+ parser->on_header_user_data = NULL;
+ parser->is_boundary = 0xde;
+ parser->is_eof = 0xde;
}
- parser->on_header = on_header_not_set;
- parser->on_header_user_data = NULL;
- parser->is_boundary = 0xde;
- parser->is_eof = 0xde;
- }
return GRPC_CHTTP2_PARSE_OK;
}
diff --git a/src/core/transport/chttp2/hpack_parser.h b/src/core/transport/chttp2/hpack_parser.h
index 0d6d268a06..6d21202d4d 100644
--- a/src/core/transport/chttp2/hpack_parser.h
+++ b/src/core/transport/chttp2/hpack_parser.h
@@ -44,19 +44,19 @@
typedef struct grpc_chttp2_hpack_parser grpc_chttp2_hpack_parser;
-typedef int (*grpc_chttp2_hpack_parser_state)(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *beg,
- const gpr_uint8 *end);
+typedef int (*grpc_chttp2_hpack_parser_state) (grpc_chttp2_hpack_parser * p, const gpr_uint8 * beg, const gpr_uint8 * end);
-typedef struct {
+typedef struct
+{
char *str;
gpr_uint32 length;
gpr_uint32 capacity;
} grpc_chttp2_hpack_parser_string;
-struct grpc_chttp2_hpack_parser {
+struct grpc_chttp2_hpack_parser
+{
/* user specified callback for each header output */
- void (*on_header)(void *user_data, grpc_mdelem *md);
+ void (*on_header) (void *user_data, grpc_mdelem * md);
void *on_header_user_data;
/* current parse state - or a function that implements it */
@@ -66,7 +66,8 @@ struct grpc_chttp2_hpack_parser {
/* what to do after skipping prioritization data */
grpc_chttp2_hpack_parser_state after_prioritization;
/* the value we're currently parsing */
- union {
+ union
+ {
gpr_uint32 *value;
grpc_chttp2_hpack_parser_string *str;
} parsing;
@@ -95,21 +96,16 @@ struct grpc_chttp2_hpack_parser {
grpc_chttp2_hptbl table;
};
-void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p,
- grpc_mdctx *mdctx);
-void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p);
+void grpc_chttp2_hpack_parser_init (grpc_chttp2_hpack_parser * p, grpc_mdctx * mdctx);
+void grpc_chttp2_hpack_parser_destroy (grpc_chttp2_hpack_parser * p);
-void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p);
+void grpc_chttp2_hpack_parser_set_has_priority (grpc_chttp2_hpack_parser * p);
/* returns 1 on success, 0 on error */
-int grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p,
- const gpr_uint8 *beg, const gpr_uint8 *end);
+int grpc_chttp2_hpack_parser_parse (grpc_chttp2_hpack_parser * p, const gpr_uint8 * beg, const gpr_uint8 * end);
/* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for
the transport */
-grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(
- void *hpack_parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list);
+grpc_chttp2_parse_error grpc_chttp2_header_parser_parse (void *hpack_parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_HPACK_PARSER_H */
diff --git a/src/core/transport/chttp2/hpack_table.c b/src/core/transport/chttp2/hpack_table.c
index e18778ab0b..099766c85e 100644
--- a/src/core/transport/chttp2/hpack_table.c
+++ b/src/core/transport/chttp2/hpack_table.c
@@ -39,191 +39,329 @@
#include <grpc/support/log.h>
#include "src/core/support/murmur_hash.h"
-static struct {
+static struct
+{
const char *key;
const char *value;
-} static_table[] = {
- /* 0: */ {NULL, NULL},
- /* 1: */ {":authority", ""},
- /* 2: */ {":method", "GET"},
- /* 3: */ {":method", "POST"},
- /* 4: */ {":path", "/"},
- /* 5: */ {":path", "/index.html"},
- /* 6: */ {":scheme", "http"},
- /* 7: */ {":scheme", "https"},
- /* 8: */ {":status", "200"},
- /* 9: */ {":status", "204"},
- /* 10: */ {":status", "206"},
- /* 11: */ {":status", "304"},
- /* 12: */ {":status", "400"},
- /* 13: */ {":status", "404"},
- /* 14: */ {":status", "500"},
- /* 15: */ {"accept-charset", ""},
- /* 16: */ {"accept-encoding", "gzip, deflate"},
- /* 17: */ {"accept-language", ""},
- /* 18: */ {"accept-ranges", ""},
- /* 19: */ {"accept", ""},
- /* 20: */ {"access-control-allow-origin", ""},
- /* 21: */ {"age", ""},
- /* 22: */ {"allow", ""},
- /* 23: */ {"authorization", ""},
- /* 24: */ {"cache-control", ""},
- /* 25: */ {"content-disposition", ""},
- /* 26: */ {"content-encoding", ""},
- /* 27: */ {"content-language", ""},
- /* 28: */ {"content-length", ""},
- /* 29: */ {"content-location", ""},
- /* 30: */ {"content-range", ""},
- /* 31: */ {"content-type", ""},
- /* 32: */ {"cookie", ""},
- /* 33: */ {"date", ""},
- /* 34: */ {"etag", ""},
- /* 35: */ {"expect", ""},
- /* 36: */ {"expires", ""},
- /* 37: */ {"from", ""},
- /* 38: */ {"host", ""},
- /* 39: */ {"if-match", ""},
- /* 40: */ {"if-modified-since", ""},
- /* 41: */ {"if-none-match", ""},
- /* 42: */ {"if-range", ""},
- /* 43: */ {"if-unmodified-since", ""},
- /* 44: */ {"last-modified", ""},
- /* 45: */ {"link", ""},
- /* 46: */ {"location", ""},
- /* 47: */ {"max-forwards", ""},
- /* 48: */ {"proxy-authenticate", ""},
- /* 49: */ {"proxy-authorization", ""},
- /* 50: */ {"range", ""},
- /* 51: */ {"referer", ""},
- /* 52: */ {"refresh", ""},
- /* 53: */ {"retry-after", ""},
- /* 54: */ {"server", ""},
- /* 55: */ {"set-cookie", ""},
- /* 56: */ {"strict-transport-security", ""},
- /* 57: */ {"transfer-encoding", ""},
- /* 58: */ {"user-agent", ""},
- /* 59: */ {"vary", ""},
- /* 60: */ {"via", ""},
- /* 61: */ {"www-authenticate", ""},
-};
-
-void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx) {
+} static_table[] =
+{
+ /* 0: */
+ {
+ NULL, NULL},
+ /* 1: */
+ {
+ ":authority", ""},
+ /* 2: */
+ {
+ ":method", "GET"},
+ /* 3: */
+ {
+ ":method", "POST"},
+ /* 4: */
+ {
+ ":path", "/"},
+ /* 5: */
+ {
+ ":path", "/index.html"},
+ /* 6: */
+ {
+ ":scheme", "http"},
+ /* 7: */
+ {
+ ":scheme", "https"},
+ /* 8: */
+ {
+ ":status", "200"},
+ /* 9: */
+ {
+ ":status", "204"},
+ /* 10: */
+ {
+ ":status", "206"},
+ /* 11: */
+ {
+ ":status", "304"},
+ /* 12: */
+ {
+ ":status", "400"},
+ /* 13: */
+ {
+ ":status", "404"},
+ /* 14: */
+ {
+ ":status", "500"},
+ /* 15: */
+ {
+ "accept-charset", ""},
+ /* 16: */
+ {
+ "accept-encoding", "gzip, deflate"},
+ /* 17: */
+ {
+ "accept-language", ""},
+ /* 18: */
+ {
+ "accept-ranges", ""},
+ /* 19: */
+ {
+ "accept", ""},
+ /* 20: */
+ {
+ "access-control-allow-origin", ""},
+ /* 21: */
+ {
+ "age", ""},
+ /* 22: */
+ {
+ "allow", ""},
+ /* 23: */
+ {
+ "authorization", ""},
+ /* 24: */
+ {
+ "cache-control", ""},
+ /* 25: */
+ {
+ "content-disposition", ""},
+ /* 26: */
+ {
+ "content-encoding", ""},
+ /* 27: */
+ {
+ "content-language", ""},
+ /* 28: */
+ {
+ "content-length", ""},
+ /* 29: */
+ {
+ "content-location", ""},
+ /* 30: */
+ {
+ "content-range", ""},
+ /* 31: */
+ {
+ "content-type", ""},
+ /* 32: */
+ {
+ "cookie", ""},
+ /* 33: */
+ {
+ "date", ""},
+ /* 34: */
+ {
+ "etag", ""},
+ /* 35: */
+ {
+ "expect", ""},
+ /* 36: */
+ {
+ "expires", ""},
+ /* 37: */
+ {
+ "from", ""},
+ /* 38: */
+ {
+ "host", ""},
+ /* 39: */
+ {
+ "if-match", ""},
+ /* 40: */
+ {
+ "if-modified-since", ""},
+ /* 41: */
+ {
+ "if-none-match", ""},
+ /* 42: */
+ {
+ "if-range", ""},
+ /* 43: */
+ {
+ "if-unmodified-since", ""},
+ /* 44: */
+ {
+ "last-modified", ""},
+ /* 45: */
+ {
+ "link", ""},
+ /* 46: */
+ {
+ "location", ""},
+ /* 47: */
+ {
+ "max-forwards", ""},
+ /* 48: */
+ {
+ "proxy-authenticate", ""},
+ /* 49: */
+ {
+ "proxy-authorization", ""},
+ /* 50: */
+ {
+ "range", ""},
+ /* 51: */
+ {
+ "referer", ""},
+ /* 52: */
+ {
+ "refresh", ""},
+ /* 53: */
+ {
+ "retry-after", ""},
+ /* 54: */
+ {
+ "server", ""},
+ /* 55: */
+ {
+ "set-cookie", ""},
+ /* 56: */
+ {
+ "strict-transport-security", ""},
+ /* 57: */
+ {
+ "transfer-encoding", ""},
+ /* 58: */
+ {
+ "user-agent", ""},
+ /* 59: */
+ {
+ "vary", ""},
+ /* 60: */
+ {
+ "via", ""},
+ /* 61: */
+ {
+"www-authenticate", ""},};
+
+void
+grpc_chttp2_hptbl_init (grpc_chttp2_hptbl * tbl, grpc_mdctx * mdctx)
+{
size_t i;
- memset(tbl, 0, sizeof(*tbl));
+ memset (tbl, 0, sizeof (*tbl));
tbl->mdctx = mdctx;
tbl->max_bytes = GRPC_CHTTP2_INITIAL_HPACK_TABLE_SIZE;
- for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) {
- tbl->static_ents[i - 1] = grpc_mdelem_from_strings(
- mdctx, static_table[i].key, static_table[i].value);
- }
+ for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++)
+ {
+ tbl->static_ents[i - 1] = grpc_mdelem_from_strings (mdctx, static_table[i].key, static_table[i].value);
+ }
}
-void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl *tbl) {
+void
+grpc_chttp2_hptbl_destroy (grpc_chttp2_hptbl * tbl)
+{
size_t i;
- for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) {
- GRPC_MDELEM_UNREF(tbl->static_ents[i]);
- }
- for (i = 0; i < tbl->num_ents; i++) {
- GRPC_MDELEM_UNREF(
- tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT]);
- }
+ for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++)
+ {
+ GRPC_MDELEM_UNREF (tbl->static_ents[i]);
+ }
+ for (i = 0; i < tbl->num_ents; i++)
+ {
+ GRPC_MDELEM_UNREF (tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT]);
+ }
}
-grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
- gpr_uint32 index) {
+grpc_mdelem *
+grpc_chttp2_hptbl_lookup (const grpc_chttp2_hptbl * tbl, gpr_uint32 index)
+{
/* Static table comes first, just return an entry from it */
- if (index <= GRPC_CHTTP2_LAST_STATIC_ENTRY) {
- return tbl->static_ents[index - 1];
- }
+ if (index <= GRPC_CHTTP2_LAST_STATIC_ENTRY)
+ {
+ return tbl->static_ents[index - 1];
+ }
/* Otherwise, find the value in the list of valid entries */
index -= (GRPC_CHTTP2_LAST_STATIC_ENTRY + 1);
- if (index < tbl->num_ents) {
- gpr_uint32 offset = (tbl->num_ents - 1u - index + tbl->first_ent) %
- GRPC_CHTTP2_MAX_TABLE_COUNT;
- return tbl->ents[offset];
- }
+ if (index < tbl->num_ents)
+ {
+ gpr_uint32 offset = (tbl->num_ents - 1u - index + tbl->first_ent) % GRPC_CHTTP2_MAX_TABLE_COUNT;
+ return tbl->ents[offset];
+ }
/* Invalid entry: return error */
return NULL;
}
/* Evict one element from the table */
-static void evict1(grpc_chttp2_hptbl *tbl) {
+static void
+evict1 (grpc_chttp2_hptbl * tbl)
+{
grpc_mdelem *first_ent = tbl->ents[tbl->first_ent];
- size_t elem_bytes = GPR_SLICE_LENGTH(first_ent->key->slice) +
- GPR_SLICE_LENGTH(first_ent->value->slice) +
- GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
- GPR_ASSERT(elem_bytes <= tbl->mem_used);
- tbl->mem_used = (gpr_uint16)(tbl->mem_used - elem_bytes);
- tbl->first_ent =
- (gpr_uint16)((tbl->first_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT);
+ size_t elem_bytes = GPR_SLICE_LENGTH (first_ent->key->slice) + GPR_SLICE_LENGTH (first_ent->value->slice) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
+ GPR_ASSERT (elem_bytes <= tbl->mem_used);
+ tbl->mem_used = (gpr_uint16) (tbl->mem_used - elem_bytes);
+ tbl->first_ent = (gpr_uint16) ((tbl->first_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT);
tbl->num_ents--;
- GRPC_MDELEM_UNREF(first_ent);
+ GRPC_MDELEM_UNREF (first_ent);
}
-void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
+void
+grpc_chttp2_hptbl_add (grpc_chttp2_hptbl * tbl, grpc_mdelem * md)
+{
/* determine how many bytes of buffer this entry represents */
- size_t elem_bytes = GPR_SLICE_LENGTH(md->key->slice) +
- GPR_SLICE_LENGTH(md->value->slice) +
- GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
+ size_t elem_bytes = GPR_SLICE_LENGTH (md->key->slice) + GPR_SLICE_LENGTH (md->value->slice) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
/* we can't add elements bigger than the max table size */
- if (elem_bytes > tbl->max_bytes) {
- /* HPACK draft 10 section 4.4 states:
- * If the size of the new entry is less than or equal to the maximum
- * size, that entry is added to the table. It is not an error to
- * attempt to add an entry that is larger than the maximum size; an
- * attempt to add an entry larger than the entire table causes
- * the table
- * to be emptied of all existing entries, and results in an
- * empty table.
- */
- while (tbl->num_ents) {
- evict1(tbl);
+ if (elem_bytes > tbl->max_bytes)
+ {
+ /* HPACK draft 10 section 4.4 states:
+ * If the size of the new entry is less than or equal to the maximum
+ * size, that entry is added to the table. It is not an error to
+ * attempt to add an entry that is larger than the maximum size; an
+ * attempt to add an entry larger than the entire table causes
+ * the table
+ * to be emptied of all existing entries, and results in an
+ * empty table.
+ */
+ while (tbl->num_ents)
+ {
+ evict1 (tbl);
+ }
+ return;
}
- return;
- }
/* evict entries to ensure no overflow */
- while (elem_bytes > (size_t)tbl->max_bytes - tbl->mem_used) {
- evict1(tbl);
- }
+ while (elem_bytes > (size_t) tbl->max_bytes - tbl->mem_used)
+ {
+ evict1 (tbl);
+ }
/* copy the finalized entry in */
tbl->ents[tbl->last_ent] = md;
/* update accounting values */
- tbl->last_ent =
- (gpr_uint16)((tbl->last_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT);
+ tbl->last_ent = (gpr_uint16) ((tbl->last_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT);
tbl->num_ents++;
- tbl->mem_used = (gpr_uint16)(tbl->mem_used + elem_bytes);
+ tbl->mem_used = (gpr_uint16) (tbl->mem_used + elem_bytes);
}
-grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find(
- const grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
- grpc_chttp2_hptbl_find_result r = {0, 0};
+grpc_chttp2_hptbl_find_result
+grpc_chttp2_hptbl_find (const grpc_chttp2_hptbl * tbl, grpc_mdelem * md)
+{
+ grpc_chttp2_hptbl_find_result r = { 0, 0 };
gpr_uint16 i;
/* See if the string is in the static table */
- for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) {
- grpc_mdelem *ent = tbl->static_ents[i];
- if (md->key != ent->key) continue;
- r.index = (gpr_uint16)(i + 1);
- r.has_value = md->value == ent->value;
- if (r.has_value) return r;
- }
+ for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++)
+ {
+ grpc_mdelem *ent = tbl->static_ents[i];
+ if (md->key != ent->key)
+ continue;
+ r.index = (gpr_uint16) (i + 1);
+ r.has_value = md->value == ent->value;
+ if (r.has_value)
+ return r;
+ }
/* Scan the dynamic table */
- for (i = 0; i < tbl->num_ents; i++) {
- gpr_uint16 idx =
- (gpr_uint16)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY);
- grpc_mdelem *ent =
- tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT];
- if (md->key != ent->key) continue;
- r.index = idx;
- r.has_value = md->value == ent->value;
- if (r.has_value) return r;
- }
+ for (i = 0; i < tbl->num_ents; i++)
+ {
+ gpr_uint16 idx = (gpr_uint16) (tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY);
+ grpc_mdelem *ent = tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT];
+ if (md->key != ent->key)
+ continue;
+ r.index = idx;
+ r.has_value = md->value == ent->value;
+ if (r.has_value)
+ return r;
+ }
return r;
}
diff --git a/src/core/transport/chttp2/hpack_table.h b/src/core/transport/chttp2/hpack_table.h
index 4f882e2e03..5c58a35186 100644
--- a/src/core/transport/chttp2/hpack_table.h
+++ b/src/core/transport/chttp2/hpack_table.h
@@ -56,7 +56,8 @@
GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD)
/* hpack decoder table */
-typedef struct {
+typedef struct
+{
grpc_mdctx *mdctx;
/* the first used entry in ents */
gpr_uint16 first_ent;
@@ -77,21 +78,20 @@ typedef struct {
} grpc_chttp2_hptbl;
/* initialize a hpack table */
-void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx);
-void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl *tbl);
+void grpc_chttp2_hptbl_init (grpc_chttp2_hptbl * tbl, grpc_mdctx * mdctx);
+void grpc_chttp2_hptbl_destroy (grpc_chttp2_hptbl * tbl);
/* lookup a table entry based on its hpack index */
-grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
- gpr_uint32 index);
+grpc_mdelem *grpc_chttp2_hptbl_lookup (const grpc_chttp2_hptbl * tbl, gpr_uint32 index);
/* add a table entry to the index */
-void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md);
+void grpc_chttp2_hptbl_add (grpc_chttp2_hptbl * tbl, grpc_mdelem * md);
/* Find a key/value pair in the table... returns the index in the table of the
most similar entry, or 0 if the value was not found */
-typedef struct {
+typedef struct
+{
gpr_uint16 index;
gpr_uint8 has_value;
} grpc_chttp2_hptbl_find_result;
-grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find(
- const grpc_chttp2_hptbl *tbl, grpc_mdelem *md);
+grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find (const grpc_chttp2_hptbl * tbl, grpc_mdelem * md);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_HPACK_TABLE_H */
diff --git a/src/core/transport/chttp2/http2_errors.h b/src/core/transport/chttp2/http2_errors.h
index a4f309e056..8385d6ba44 100644
--- a/src/core/transport/chttp2/http2_errors.h
+++ b/src/core/transport/chttp2/http2_errors.h
@@ -35,7 +35,8 @@
#define GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_HTTP2_ERRORS_H
/* error codes for RST_STREAM from http2 draft 14 section 7 */
-typedef enum {
+typedef enum
+{
GRPC_CHTTP2_NO_ERROR = 0x0,
GRPC_CHTTP2_PROTOCOL_ERROR = 0x1,
GRPC_CHTTP2_INTERNAL_ERROR = 0x2,
diff --git a/src/core/transport/chttp2/huffsyms.c b/src/core/transport/chttp2/huffsyms.c
index 6f5cf6a2a9..058c6ee61e 100644
--- a/src/core/transport/chttp2/huffsyms.c
+++ b/src/core/transport/chttp2/huffsyms.c
@@ -37,69 +37,69 @@
command:
:%s/.* \([0-9a-f]\+\) \[ *\([0-9]\+\)\]/{0x\1, \2},/g */
const grpc_chttp2_huffsym grpc_chttp2_huffsyms[GRPC_CHTTP2_NUM_HUFFSYMS] = {
- {0x1ff8, 13}, {0x7fffd8, 23}, {0xfffffe2, 28}, {0xfffffe3, 28},
- {0xfffffe4, 28}, {0xfffffe5, 28}, {0xfffffe6, 28}, {0xfffffe7, 28},
- {0xfffffe8, 28}, {0xffffea, 24}, {0x3ffffffc, 30}, {0xfffffe9, 28},
- {0xfffffea, 28}, {0x3ffffffd, 30}, {0xfffffeb, 28}, {0xfffffec, 28},
- {0xfffffed, 28}, {0xfffffee, 28}, {0xfffffef, 28}, {0xffffff0, 28},
- {0xffffff1, 28}, {0xffffff2, 28}, {0x3ffffffe, 30}, {0xffffff3, 28},
- {0xffffff4, 28}, {0xffffff5, 28}, {0xffffff6, 28}, {0xffffff7, 28},
- {0xffffff8, 28}, {0xffffff9, 28}, {0xffffffa, 28}, {0xffffffb, 28},
- {0x14, 6}, {0x3f8, 10}, {0x3f9, 10}, {0xffa, 12},
- {0x1ff9, 13}, {0x15, 6}, {0xf8, 8}, {0x7fa, 11},
- {0x3fa, 10}, {0x3fb, 10}, {0xf9, 8}, {0x7fb, 11},
- {0xfa, 8}, {0x16, 6}, {0x17, 6}, {0x18, 6},
- {0x0, 5}, {0x1, 5}, {0x2, 5}, {0x19, 6},
- {0x1a, 6}, {0x1b, 6}, {0x1c, 6}, {0x1d, 6},
- {0x1e, 6}, {0x1f, 6}, {0x5c, 7}, {0xfb, 8},
- {0x7ffc, 15}, {0x20, 6}, {0xffb, 12}, {0x3fc, 10},
- {0x1ffa, 13}, {0x21, 6}, {0x5d, 7}, {0x5e, 7},
- {0x5f, 7}, {0x60, 7}, {0x61, 7}, {0x62, 7},
- {0x63, 7}, {0x64, 7}, {0x65, 7}, {0x66, 7},
- {0x67, 7}, {0x68, 7}, {0x69, 7}, {0x6a, 7},
- {0x6b, 7}, {0x6c, 7}, {0x6d, 7}, {0x6e, 7},
- {0x6f, 7}, {0x70, 7}, {0x71, 7}, {0x72, 7},
- {0xfc, 8}, {0x73, 7}, {0xfd, 8}, {0x1ffb, 13},
- {0x7fff0, 19}, {0x1ffc, 13}, {0x3ffc, 14}, {0x22, 6},
- {0x7ffd, 15}, {0x3, 5}, {0x23, 6}, {0x4, 5},
- {0x24, 6}, {0x5, 5}, {0x25, 6}, {0x26, 6},
- {0x27, 6}, {0x6, 5}, {0x74, 7}, {0x75, 7},
- {0x28, 6}, {0x29, 6}, {0x2a, 6}, {0x7, 5},
- {0x2b, 6}, {0x76, 7}, {0x2c, 6}, {0x8, 5},
- {0x9, 5}, {0x2d, 6}, {0x77, 7}, {0x78, 7},
- {0x79, 7}, {0x7a, 7}, {0x7b, 7}, {0x7ffe, 15},
- {0x7fc, 11}, {0x3ffd, 14}, {0x1ffd, 13}, {0xffffffc, 28},
- {0xfffe6, 20}, {0x3fffd2, 22}, {0xfffe7, 20}, {0xfffe8, 20},
- {0x3fffd3, 22}, {0x3fffd4, 22}, {0x3fffd5, 22}, {0x7fffd9, 23},
- {0x3fffd6, 22}, {0x7fffda, 23}, {0x7fffdb, 23}, {0x7fffdc, 23},
- {0x7fffdd, 23}, {0x7fffde, 23}, {0xffffeb, 24}, {0x7fffdf, 23},
- {0xffffec, 24}, {0xffffed, 24}, {0x3fffd7, 22}, {0x7fffe0, 23},
- {0xffffee, 24}, {0x7fffe1, 23}, {0x7fffe2, 23}, {0x7fffe3, 23},
- {0x7fffe4, 23}, {0x1fffdc, 21}, {0x3fffd8, 22}, {0x7fffe5, 23},
- {0x3fffd9, 22}, {0x7fffe6, 23}, {0x7fffe7, 23}, {0xffffef, 24},
- {0x3fffda, 22}, {0x1fffdd, 21}, {0xfffe9, 20}, {0x3fffdb, 22},
- {0x3fffdc, 22}, {0x7fffe8, 23}, {0x7fffe9, 23}, {0x1fffde, 21},
- {0x7fffea, 23}, {0x3fffdd, 22}, {0x3fffde, 22}, {0xfffff0, 24},
- {0x1fffdf, 21}, {0x3fffdf, 22}, {0x7fffeb, 23}, {0x7fffec, 23},
- {0x1fffe0, 21}, {0x1fffe1, 21}, {0x3fffe0, 22}, {0x1fffe2, 21},
- {0x7fffed, 23}, {0x3fffe1, 22}, {0x7fffee, 23}, {0x7fffef, 23},
- {0xfffea, 20}, {0x3fffe2, 22}, {0x3fffe3, 22}, {0x3fffe4, 22},
- {0x7ffff0, 23}, {0x3fffe5, 22}, {0x3fffe6, 22}, {0x7ffff1, 23},
- {0x3ffffe0, 26}, {0x3ffffe1, 26}, {0xfffeb, 20}, {0x7fff1, 19},
- {0x3fffe7, 22}, {0x7ffff2, 23}, {0x3fffe8, 22}, {0x1ffffec, 25},
- {0x3ffffe2, 26}, {0x3ffffe3, 26}, {0x3ffffe4, 26}, {0x7ffffde, 27},
- {0x7ffffdf, 27}, {0x3ffffe5, 26}, {0xfffff1, 24}, {0x1ffffed, 25},
- {0x7fff2, 19}, {0x1fffe3, 21}, {0x3ffffe6, 26}, {0x7ffffe0, 27},
- {0x7ffffe1, 27}, {0x3ffffe7, 26}, {0x7ffffe2, 27}, {0xfffff2, 24},
- {0x1fffe4, 21}, {0x1fffe5, 21}, {0x3ffffe8, 26}, {0x3ffffe9, 26},
- {0xffffffd, 28}, {0x7ffffe3, 27}, {0x7ffffe4, 27}, {0x7ffffe5, 27},
- {0xfffec, 20}, {0xfffff3, 24}, {0xfffed, 20}, {0x1fffe6, 21},
- {0x3fffe9, 22}, {0x1fffe7, 21}, {0x1fffe8, 21}, {0x7ffff3, 23},
- {0x3fffea, 22}, {0x3fffeb, 22}, {0x1ffffee, 25}, {0x1ffffef, 25},
- {0xfffff4, 24}, {0xfffff5, 24}, {0x3ffffea, 26}, {0x7ffff4, 23},
- {0x3ffffeb, 26}, {0x7ffffe6, 27}, {0x3ffffec, 26}, {0x3ffffed, 26},
- {0x7ffffe7, 27}, {0x7ffffe8, 27}, {0x7ffffe9, 27}, {0x7ffffea, 27},
- {0x7ffffeb, 27}, {0xffffffe, 28}, {0x7ffffec, 27}, {0x7ffffed, 27},
- {0x7ffffee, 27}, {0x7ffffef, 27}, {0x7fffff0, 27}, {0x3ffffee, 26},
- {0x3fffffff, 30},
+ {0x1ff8, 13}, {0x7fffd8, 23}, {0xfffffe2, 28}, {0xfffffe3, 28},
+ {0xfffffe4, 28}, {0xfffffe5, 28}, {0xfffffe6, 28}, {0xfffffe7, 28},
+ {0xfffffe8, 28}, {0xffffea, 24}, {0x3ffffffc, 30}, {0xfffffe9, 28},
+ {0xfffffea, 28}, {0x3ffffffd, 30}, {0xfffffeb, 28}, {0xfffffec, 28},
+ {0xfffffed, 28}, {0xfffffee, 28}, {0xfffffef, 28}, {0xffffff0, 28},
+ {0xffffff1, 28}, {0xffffff2, 28}, {0x3ffffffe, 30}, {0xffffff3, 28},
+ {0xffffff4, 28}, {0xffffff5, 28}, {0xffffff6, 28}, {0xffffff7, 28},
+ {0xffffff8, 28}, {0xffffff9, 28}, {0xffffffa, 28}, {0xffffffb, 28},
+ {0x14, 6}, {0x3f8, 10}, {0x3f9, 10}, {0xffa, 12},
+ {0x1ff9, 13}, {0x15, 6}, {0xf8, 8}, {0x7fa, 11},
+ {0x3fa, 10}, {0x3fb, 10}, {0xf9, 8}, {0x7fb, 11},
+ {0xfa, 8}, {0x16, 6}, {0x17, 6}, {0x18, 6},
+ {0x0, 5}, {0x1, 5}, {0x2, 5}, {0x19, 6},
+ {0x1a, 6}, {0x1b, 6}, {0x1c, 6}, {0x1d, 6},
+ {0x1e, 6}, {0x1f, 6}, {0x5c, 7}, {0xfb, 8},
+ {0x7ffc, 15}, {0x20, 6}, {0xffb, 12}, {0x3fc, 10},
+ {0x1ffa, 13}, {0x21, 6}, {0x5d, 7}, {0x5e, 7},
+ {0x5f, 7}, {0x60, 7}, {0x61, 7}, {0x62, 7},
+ {0x63, 7}, {0x64, 7}, {0x65, 7}, {0x66, 7},
+ {0x67, 7}, {0x68, 7}, {0x69, 7}, {0x6a, 7},
+ {0x6b, 7}, {0x6c, 7}, {0x6d, 7}, {0x6e, 7},
+ {0x6f, 7}, {0x70, 7}, {0x71, 7}, {0x72, 7},
+ {0xfc, 8}, {0x73, 7}, {0xfd, 8}, {0x1ffb, 13},
+ {0x7fff0, 19}, {0x1ffc, 13}, {0x3ffc, 14}, {0x22, 6},
+ {0x7ffd, 15}, {0x3, 5}, {0x23, 6}, {0x4, 5},
+ {0x24, 6}, {0x5, 5}, {0x25, 6}, {0x26, 6},
+ {0x27, 6}, {0x6, 5}, {0x74, 7}, {0x75, 7},
+ {0x28, 6}, {0x29, 6}, {0x2a, 6}, {0x7, 5},
+ {0x2b, 6}, {0x76, 7}, {0x2c, 6}, {0x8, 5},
+ {0x9, 5}, {0x2d, 6}, {0x77, 7}, {0x78, 7},
+ {0x79, 7}, {0x7a, 7}, {0x7b, 7}, {0x7ffe, 15},
+ {0x7fc, 11}, {0x3ffd, 14}, {0x1ffd, 13}, {0xffffffc, 28},
+ {0xfffe6, 20}, {0x3fffd2, 22}, {0xfffe7, 20}, {0xfffe8, 20},
+ {0x3fffd3, 22}, {0x3fffd4, 22}, {0x3fffd5, 22}, {0x7fffd9, 23},
+ {0x3fffd6, 22}, {0x7fffda, 23}, {0x7fffdb, 23}, {0x7fffdc, 23},
+ {0x7fffdd, 23}, {0x7fffde, 23}, {0xffffeb, 24}, {0x7fffdf, 23},
+ {0xffffec, 24}, {0xffffed, 24}, {0x3fffd7, 22}, {0x7fffe0, 23},
+ {0xffffee, 24}, {0x7fffe1, 23}, {0x7fffe2, 23}, {0x7fffe3, 23},
+ {0x7fffe4, 23}, {0x1fffdc, 21}, {0x3fffd8, 22}, {0x7fffe5, 23},
+ {0x3fffd9, 22}, {0x7fffe6, 23}, {0x7fffe7, 23}, {0xffffef, 24},
+ {0x3fffda, 22}, {0x1fffdd, 21}, {0xfffe9, 20}, {0x3fffdb, 22},
+ {0x3fffdc, 22}, {0x7fffe8, 23}, {0x7fffe9, 23}, {0x1fffde, 21},
+ {0x7fffea, 23}, {0x3fffdd, 22}, {0x3fffde, 22}, {0xfffff0, 24},
+ {0x1fffdf, 21}, {0x3fffdf, 22}, {0x7fffeb, 23}, {0x7fffec, 23},
+ {0x1fffe0, 21}, {0x1fffe1, 21}, {0x3fffe0, 22}, {0x1fffe2, 21},
+ {0x7fffed, 23}, {0x3fffe1, 22}, {0x7fffee, 23}, {0x7fffef, 23},
+ {0xfffea, 20}, {0x3fffe2, 22}, {0x3fffe3, 22}, {0x3fffe4, 22},
+ {0x7ffff0, 23}, {0x3fffe5, 22}, {0x3fffe6, 22}, {0x7ffff1, 23},
+ {0x3ffffe0, 26}, {0x3ffffe1, 26}, {0xfffeb, 20}, {0x7fff1, 19},
+ {0x3fffe7, 22}, {0x7ffff2, 23}, {0x3fffe8, 22}, {0x1ffffec, 25},
+ {0x3ffffe2, 26}, {0x3ffffe3, 26}, {0x3ffffe4, 26}, {0x7ffffde, 27},
+ {0x7ffffdf, 27}, {0x3ffffe5, 26}, {0xfffff1, 24}, {0x1ffffed, 25},
+ {0x7fff2, 19}, {0x1fffe3, 21}, {0x3ffffe6, 26}, {0x7ffffe0, 27},
+ {0x7ffffe1, 27}, {0x3ffffe7, 26}, {0x7ffffe2, 27}, {0xfffff2, 24},
+ {0x1fffe4, 21}, {0x1fffe5, 21}, {0x3ffffe8, 26}, {0x3ffffe9, 26},
+ {0xffffffd, 28}, {0x7ffffe3, 27}, {0x7ffffe4, 27}, {0x7ffffe5, 27},
+ {0xfffec, 20}, {0xfffff3, 24}, {0xfffed, 20}, {0x1fffe6, 21},
+ {0x3fffe9, 22}, {0x1fffe7, 21}, {0x1fffe8, 21}, {0x7ffff3, 23},
+ {0x3fffea, 22}, {0x3fffeb, 22}, {0x1ffffee, 25}, {0x1ffffef, 25},
+ {0xfffff4, 24}, {0xfffff5, 24}, {0x3ffffea, 26}, {0x7ffff4, 23},
+ {0x3ffffeb, 26}, {0x7ffffe6, 27}, {0x3ffffec, 26}, {0x3ffffed, 26},
+ {0x7ffffe7, 27}, {0x7ffffe8, 27}, {0x7ffffe9, 27}, {0x7ffffea, 27},
+ {0x7ffffeb, 27}, {0xffffffe, 28}, {0x7ffffec, 27}, {0x7ffffed, 27},
+ {0x7ffffee, 27}, {0x7ffffef, 27}, {0x7fffff0, 27}, {0x3ffffee, 26},
+ {0x3fffffff, 30},
};
diff --git a/src/core/transport/chttp2/huffsyms.h b/src/core/transport/chttp2/huffsyms.h
index a3cdba8235..04f062dd5e 100644
--- a/src/core/transport/chttp2/huffsyms.h
+++ b/src/core/transport/chttp2/huffsyms.h
@@ -38,7 +38,8 @@
#define GRPC_CHTTP2_NUM_HUFFSYMS 257
-typedef struct {
+typedef struct
+{
unsigned bits;
unsigned length;
} grpc_chttp2_huffsym;
diff --git a/src/core/transport/chttp2/incoming_metadata.c b/src/core/transport/chttp2/incoming_metadata.c
index d216c42113..93eee0be3f 100644
--- a/src/core/transport/chttp2/incoming_metadata.c
+++ b/src/core/transport/chttp2/incoming_metadata.c
@@ -40,43 +40,50 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-void grpc_chttp2_incoming_metadata_buffer_init(
- grpc_chttp2_incoming_metadata_buffer *buffer) {
- buffer->deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
+void
+grpc_chttp2_incoming_metadata_buffer_init (grpc_chttp2_incoming_metadata_buffer * buffer)
+{
+ buffer->deadline = gpr_inf_future (GPR_CLOCK_REALTIME);
}
-void grpc_chttp2_incoming_metadata_buffer_destroy(
- grpc_chttp2_incoming_metadata_buffer *buffer) {
+void
+grpc_chttp2_incoming_metadata_buffer_destroy (grpc_chttp2_incoming_metadata_buffer * buffer)
+{
size_t i;
- for (i = 0; i < buffer->count; i++) {
- GRPC_MDELEM_UNREF(buffer->elems[i].md);
- }
- gpr_free(buffer->elems);
+ for (i = 0; i < buffer->count; i++)
+ {
+ GRPC_MDELEM_UNREF (buffer->elems[i].md);
+ }
+ gpr_free (buffer->elems);
}
-void grpc_chttp2_incoming_metadata_buffer_add(
- grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem) {
- if (buffer->capacity == buffer->count) {
- buffer->capacity = GPR_MAX(8, 2 * buffer->capacity);
- buffer->elems =
- gpr_realloc(buffer->elems, sizeof(*buffer->elems) * buffer->capacity);
- }
+void
+grpc_chttp2_incoming_metadata_buffer_add (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_mdelem * elem)
+{
+ if (buffer->capacity == buffer->count)
+ {
+ buffer->capacity = GPR_MAX (8, 2 * buffer->capacity);
+ buffer->elems = gpr_realloc (buffer->elems, sizeof (*buffer->elems) * buffer->capacity);
+ }
buffer->elems[buffer->count++].md = elem;
}
-void grpc_chttp2_incoming_metadata_buffer_set_deadline(
- grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline) {
+void
+grpc_chttp2_incoming_metadata_buffer_set_deadline (grpc_chttp2_incoming_metadata_buffer * buffer, gpr_timespec deadline)
+{
buffer->deadline = deadline;
}
-void grpc_chttp2_incoming_metadata_live_op_buffer_end(
- grpc_chttp2_incoming_metadata_live_op_buffer *buffer) {
- gpr_free(buffer->elems);
+void
+grpc_chttp2_incoming_metadata_live_op_buffer_end (grpc_chttp2_incoming_metadata_live_op_buffer * buffer)
+{
+ gpr_free (buffer->elems);
buffer->elems = NULL;
}
-void grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into(
- grpc_chttp2_incoming_metadata_buffer *buffer, grpc_stream_op_buffer *sopb) {
+void
+grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_stream_op_buffer * sopb)
+{
grpc_metadata_batch b;
b.list.head = NULL;
@@ -84,52 +91,56 @@ void grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into(
we can reconstitute the list.
We can't do list building here as later incoming metadata may reallocate
the underlying array. */
- b.list.tail = (void *)(gpr_intptr)buffer->count;
+ b.list.tail = (void *) (gpr_intptr) buffer->count;
b.garbage.head = b.garbage.tail = NULL;
b.deadline = buffer->deadline;
- buffer->deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
+ buffer->deadline = gpr_inf_future (GPR_CLOCK_REALTIME);
- grpc_sopb_add_metadata(sopb, b);
+ grpc_sopb_add_metadata (sopb, b);
}
-void grpc_chttp2_incoming_metadata_buffer_swap(
- grpc_chttp2_incoming_metadata_buffer *a,
- grpc_chttp2_incoming_metadata_buffer *b) {
- GPR_SWAP(grpc_chttp2_incoming_metadata_buffer, *a, *b);
+void
+grpc_chttp2_incoming_metadata_buffer_swap (grpc_chttp2_incoming_metadata_buffer * a, grpc_chttp2_incoming_metadata_buffer * b)
+{
+ GPR_SWAP (grpc_chttp2_incoming_metadata_buffer, *a, *b);
}
-void grpc_incoming_metadata_buffer_move_to_referencing_sopb(
- grpc_chttp2_incoming_metadata_buffer *src,
- grpc_chttp2_incoming_metadata_buffer *dst, grpc_stream_op_buffer *sopb) {
+void
+grpc_incoming_metadata_buffer_move_to_referencing_sopb (grpc_chttp2_incoming_metadata_buffer * src, grpc_chttp2_incoming_metadata_buffer * dst, grpc_stream_op_buffer * sopb)
+{
size_t delta;
size_t i;
- dst->deadline = gpr_time_min(src->deadline, dst->deadline);
-
- if (src->count == 0) {
- return;
- }
- if (dst->count == 0) {
- grpc_chttp2_incoming_metadata_buffer_swap(src, dst);
- return;
- }
+ dst->deadline = gpr_time_min (src->deadline, dst->deadline);
+
+ if (src->count == 0)
+ {
+ return;
+ }
+ if (dst->count == 0)
+ {
+ grpc_chttp2_incoming_metadata_buffer_swap (src, dst);
+ return;
+ }
delta = dst->count;
- if (dst->capacity < src->count + dst->count) {
- dst->capacity = GPR_MAX(dst->capacity * 2, src->count + dst->count);
- dst->elems = gpr_realloc(dst->elems, dst->capacity * sizeof(*dst->elems));
- }
- memcpy(dst->elems + dst->count, src->elems, src->count * sizeof(*src->elems));
+ if (dst->capacity < src->count + dst->count)
+ {
+ dst->capacity = GPR_MAX (dst->capacity * 2, src->count + dst->count);
+ dst->elems = gpr_realloc (dst->elems, dst->capacity * sizeof (*dst->elems));
+ }
+ memcpy (dst->elems + dst->count, src->elems, src->count * sizeof (*src->elems));
dst->count += src->count;
- for (i = 0; i < sopb->nops; i++) {
- if (sopb->ops[i].type != GRPC_OP_METADATA) continue;
- sopb->ops[i].data.metadata.list.tail =
- (void *)(delta + (gpr_uintptr)sopb->ops[i].data.metadata.list.tail);
- }
+ for (i = 0; i < sopb->nops; i++)
+ {
+ if (sopb->ops[i].type != GRPC_OP_METADATA)
+ continue;
+ sopb->ops[i].data.metadata.list.tail = (void *) (delta + (gpr_uintptr) sopb->ops[i].data.metadata.list.tail);
+ }
src->count = 0;
}
-void grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op(
- grpc_chttp2_incoming_metadata_buffer *buffer, grpc_stream_op_buffer *sopb,
- grpc_chttp2_incoming_metadata_live_op_buffer *live_op_buffer) {
+void
+grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_stream_op_buffer * sopb, grpc_chttp2_incoming_metadata_live_op_buffer * live_op_buffer)
+{
grpc_stream_op *ops = sopb->ops;
size_t nops = sopb->nops;
size_t i;
@@ -141,42 +152,49 @@ void grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op(
/* rework the array of metadata into a linked list, making use
of the breadcrumbs we left in metadata batches during
add_metadata_batch */
- for (i = 0; i < nops; i++) {
- grpc_stream_op *op = &ops[i];
- if (op->type != GRPC_OP_METADATA) continue;
- found_metadata = 1;
- /* we left a breadcrumb indicating where the end of this list is,
- and since we add sequentially, we know from the end of the last
- segment where this segment begins */
- last_mdidx = (size_t)(gpr_intptr)(op->data.metadata.list.tail);
- GPR_ASSERT(last_mdidx > mdidx);
- GPR_ASSERT(last_mdidx <= buffer->count);
- /* turn the array into a doubly linked list */
- op->data.metadata.list.head = &buffer->elems[mdidx];
- op->data.metadata.list.tail = &buffer->elems[last_mdidx - 1];
- for (j = mdidx + 1; j < last_mdidx; j++) {
- buffer->elems[j].prev = &buffer->elems[j - 1];
- buffer->elems[j - 1].next = &buffer->elems[j];
+ for (i = 0; i < nops; i++)
+ {
+ grpc_stream_op *op = &ops[i];
+ if (op->type != GRPC_OP_METADATA)
+ continue;
+ found_metadata = 1;
+ /* we left a breadcrumb indicating where the end of this list is,
+ and since we add sequentially, we know from the end of the last
+ segment where this segment begins */
+ last_mdidx = (size_t) (gpr_intptr) (op->data.metadata.list.tail);
+ GPR_ASSERT (last_mdidx > mdidx);
+ GPR_ASSERT (last_mdidx <= buffer->count);
+ /* turn the array into a doubly linked list */
+ op->data.metadata.list.head = &buffer->elems[mdidx];
+ op->data.metadata.list.tail = &buffer->elems[last_mdidx - 1];
+ for (j = mdidx + 1; j < last_mdidx; j++)
+ {
+ buffer->elems[j].prev = &buffer->elems[j - 1];
+ buffer->elems[j - 1].next = &buffer->elems[j];
+ }
+ buffer->elems[mdidx].prev = NULL;
+ buffer->elems[last_mdidx - 1].next = NULL;
+ /* track where we're up to */
+ mdidx = last_mdidx;
}
- buffer->elems[mdidx].prev = NULL;
- buffer->elems[last_mdidx - 1].next = NULL;
- /* track where we're up to */
- mdidx = last_mdidx;
- }
- if (found_metadata) {
- live_op_buffer->elems = buffer->elems;
- if (mdidx != buffer->count) {
- /* we have a partially read metadata batch still in incoming_metadata */
- size_t new_count = buffer->count - mdidx;
- size_t copy_bytes = sizeof(*buffer->elems) * new_count;
- GPR_ASSERT(mdidx < buffer->count);
- buffer->elems = gpr_malloc(copy_bytes);
- memcpy(live_op_buffer->elems + mdidx, buffer->elems, copy_bytes);
- buffer->count = buffer->capacity = new_count;
- } else {
- buffer->elems = NULL;
- buffer->count = 0;
- buffer->capacity = 0;
+ if (found_metadata)
+ {
+ live_op_buffer->elems = buffer->elems;
+ if (mdidx != buffer->count)
+ {
+ /* we have a partially read metadata batch still in incoming_metadata */
+ size_t new_count = buffer->count - mdidx;
+ size_t copy_bytes = sizeof (*buffer->elems) * new_count;
+ GPR_ASSERT (mdidx < buffer->count);
+ buffer->elems = gpr_malloc (copy_bytes);
+ memcpy (live_op_buffer->elems + mdidx, buffer->elems, copy_bytes);
+ buffer->count = buffer->capacity = new_count;
+ }
+ else
+ {
+ buffer->elems = NULL;
+ buffer->count = 0;
+ buffer->capacity = 0;
+ }
}
- }
}
diff --git a/src/core/transport/chttp2/incoming_metadata.h b/src/core/transport/chttp2/incoming_metadata.h
index 2f1de411ba..7ca0f722c3 100644
--- a/src/core/transport/chttp2/incoming_metadata.h
+++ b/src/core/transport/chttp2/incoming_metadata.h
@@ -36,45 +36,36 @@
#include "src/core/transport/transport.h"
-typedef struct {
+typedef struct
+{
grpc_linked_mdelem *elems;
size_t count;
size_t capacity;
gpr_timespec deadline;
} grpc_chttp2_incoming_metadata_buffer;
-typedef struct {
+typedef struct
+{
grpc_linked_mdelem *elems;
} grpc_chttp2_incoming_metadata_live_op_buffer;
/** assumes everything initially zeroed */
-void grpc_chttp2_incoming_metadata_buffer_init(
- grpc_chttp2_incoming_metadata_buffer *buffer);
-void grpc_chttp2_incoming_metadata_buffer_destroy(
- grpc_chttp2_incoming_metadata_buffer *buffer);
-void grpc_chttp2_incoming_metadata_buffer_reset(
- grpc_chttp2_incoming_metadata_buffer *buffer);
+void grpc_chttp2_incoming_metadata_buffer_init (grpc_chttp2_incoming_metadata_buffer * buffer);
+void grpc_chttp2_incoming_metadata_buffer_destroy (grpc_chttp2_incoming_metadata_buffer * buffer);
+void grpc_chttp2_incoming_metadata_buffer_reset (grpc_chttp2_incoming_metadata_buffer * buffer);
-void grpc_chttp2_incoming_metadata_buffer_add(
- grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem);
-void grpc_chttp2_incoming_metadata_buffer_set_deadline(
- grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline);
+void grpc_chttp2_incoming_metadata_buffer_add (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_mdelem * elem);
+void grpc_chttp2_incoming_metadata_buffer_set_deadline (grpc_chttp2_incoming_metadata_buffer * buffer, gpr_timespec deadline);
/** extend sopb with a metadata batch; this must be post-processed by
grpc_chttp2_incoming_metadata_buffer_postprocess_sopb before being handed
out of the transport */
-void grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into(
- grpc_chttp2_incoming_metadata_buffer *buffer, grpc_stream_op_buffer *sopb);
+void grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_stream_op_buffer * sopb);
-void grpc_incoming_metadata_buffer_move_to_referencing_sopb(
- grpc_chttp2_incoming_metadata_buffer *src,
- grpc_chttp2_incoming_metadata_buffer *dst, grpc_stream_op_buffer *sopb);
+void grpc_incoming_metadata_buffer_move_to_referencing_sopb (grpc_chttp2_incoming_metadata_buffer * src, grpc_chttp2_incoming_metadata_buffer * dst, grpc_stream_op_buffer * sopb);
-void grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op(
- grpc_chttp2_incoming_metadata_buffer *buffer, grpc_stream_op_buffer *sopb,
- grpc_chttp2_incoming_metadata_live_op_buffer *live_op_buffer);
+void grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_stream_op_buffer * sopb, grpc_chttp2_incoming_metadata_live_op_buffer * live_op_buffer);
-void grpc_chttp2_incoming_metadata_live_op_buffer_end(
- grpc_chttp2_incoming_metadata_live_op_buffer *live_op_buffer);
+void grpc_chttp2_incoming_metadata_live_op_buffer_end (grpc_chttp2_incoming_metadata_live_op_buffer * live_op_buffer);
#endif /* GRPC_INTERNAL_CORE_CHTTP2_INCOMING_METADATA_H */
diff --git a/src/core/transport/chttp2/internal.h b/src/core/transport/chttp2/internal.h
index 14a6c909ee..1ef9c1af87 100644
--- a/src/core/transport/chttp2/internal.h
+++ b/src/core/transport/chttp2/internal.h
@@ -54,7 +54,8 @@ typedef struct grpc_chttp2_stream grpc_chttp2_stream;
/* streams are kept in various linked lists depending on what things need to
happen to them... this enum labels each list */
-typedef enum {
+typedef enum
+{
GRPC_CHTTP2_LIST_ALL_STREAMS,
GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED,
GRPC_CHTTP2_LIST_WRITABLE,
@@ -67,11 +68,12 @@ typedef enum {
/** streams that are waiting to start because there are too many concurrent
streams on the connection */
GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY,
- STREAM_LIST_COUNT /* must be last */
+ STREAM_LIST_COUNT /* must be last */
} grpc_chttp2_stream_list_id;
/* deframer state for the overall http2 stream of bytes */
-typedef enum {
+typedef enum
+{
/* prefix: one entry per http2 connection prefix byte */
GRPC_DTS_CLIENT_PREFIX_0 = 0,
GRPC_DTS_CLIENT_PREFIX_1,
@@ -113,7 +115,8 @@ typedef enum {
GRPC_DTS_FRAME
} grpc_chttp2_deframe_transport_state;
-typedef enum {
+typedef enum
+{
GRPC_WRITE_STATE_OPEN,
GRPC_WRITE_STATE_QUEUED_CLOSE,
GRPC_WRITE_STATE_SENT_CLOSE
@@ -123,24 +126,28 @@ typedef enum {
#define GRPC_CHTTP2_WRITING_DATA 1
#define GRPC_CHTTP2_WRITING_WINDOW 2
-typedef enum {
+typedef enum
+{
GRPC_DONT_SEND_CLOSED = 0,
GRPC_SEND_CLOSED,
GRPC_SEND_CLOSED_WITH_RST_STREAM
} grpc_chttp2_send_closed;
-typedef struct {
+typedef struct
+{
grpc_chttp2_stream *head;
grpc_chttp2_stream *tail;
} grpc_chttp2_stream_list;
-typedef struct {
+typedef struct
+{
grpc_chttp2_stream *next;
grpc_chttp2_stream *prev;
} grpc_chttp2_stream_link;
/* We keep several sets of connection wide parameters */
-typedef enum {
+typedef enum
+{
/* The settings our peer has asked for (and we have acked) */
GRPC_PEER_SETTINGS = 0,
/* The settings we'd like to have */
@@ -153,14 +160,16 @@ typedef enum {
} grpc_chttp2_setting_set;
/* Outstanding ping request data */
-typedef struct grpc_chttp2_outstanding_ping {
+typedef struct grpc_chttp2_outstanding_ping
+{
gpr_uint8 id[8];
grpc_closure *on_recv;
struct grpc_chttp2_outstanding_ping *next;
struct grpc_chttp2_outstanding_ping *prev;
} grpc_chttp2_outstanding_ping;
-typedef struct {
+typedef struct
+{
/** data to write next write */
gpr_slice_buffer qbuf;
@@ -204,7 +213,8 @@ typedef struct {
gpr_uint32 concurrent_stream_count;
} grpc_chttp2_transport_global;
-typedef struct {
+typedef struct
+{
/** data to write now */
gpr_slice_buffer outbuf;
/** hpack encoding */
@@ -215,7 +225,8 @@ typedef struct {
grpc_closure done_cb;
} grpc_chttp2_transport_writing;
-struct grpc_chttp2_transport_parsing {
+struct grpc_chttp2_transport_parsing
+{
/** is this transport a client? (boolean) */
gpr_uint8 is_client;
@@ -236,7 +247,8 @@ struct grpc_chttp2_transport_parsing {
/** parser for headers */
grpc_chttp2_hpack_parser hpack_parser;
/** simple one shot parsers */
- union {
+ union
+ {
grpc_chttp2_window_update_parser window_update;
grpc_chttp2_settings_parser settings;
grpc_chttp2_ping_parser ping;
@@ -265,10 +277,7 @@ struct grpc_chttp2_transport_parsing {
/* active parser */
void *parser_data;
grpc_chttp2_stream_parsing *incoming_stream;
- grpc_chttp2_parse_error (*parser)(
- void *parser_user_data, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list);
+ grpc_chttp2_parse_error (*parser) (void *parser_user_data, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list);
/* received settings */
gpr_uint32 settings[GRPC_CHTTP2_NUM_SETTINGS];
@@ -284,8 +293,9 @@ struct grpc_chttp2_transport_parsing {
grpc_chttp2_outstanding_ping pings;
};
-struct grpc_chttp2_transport {
- grpc_transport base; /* must be first */
+struct grpc_chttp2_transport
+{
+ grpc_transport base; /* must be first */
grpc_endpoint *ep;
grpc_mdctx *metadata_context;
gpr_refcount refs;
@@ -343,10 +353,10 @@ struct grpc_chttp2_transport {
publish the accepted server stream */
grpc_chttp2_stream **accepting_stream;
- struct {
+ struct
+ {
/* accept stream callback */
- void (*accept_stream)(void *user_data, grpc_transport *transport,
- const void *server_data);
+ void (*accept_stream) (void *user_data, grpc_transport * transport, const void *server_data);
void *accept_stream_user_data;
/** connectivity tracking */
@@ -354,7 +364,8 @@ struct grpc_chttp2_transport {
} channel_callback;
};
-typedef struct {
+typedef struct
+{
/** HTTP2 stream id for this stream, or zero if one has not been assigned */
gpr_uint32 id;
@@ -410,7 +421,8 @@ typedef struct {
grpc_chttp2_incoming_metadata_live_op_buffer outstanding_metadata;
} grpc_chttp2_stream_global;
-typedef struct {
+typedef struct
+{
/** HTTP2 stream id for this stream, or zero if one has not been assigned */
gpr_uint32 id;
/** sops that have passed flow control to be written */
@@ -421,7 +433,8 @@ typedef struct {
gpr_uint32 announce_window;
} grpc_chttp2_stream_writing;
-struct grpc_chttp2_stream_parsing {
+struct grpc_chttp2_stream_parsing
+{
/** HTTP2 stream id for this stream, or zero if one has not been assigned */
gpr_uint32 id;
/** has this stream received a close */
@@ -443,7 +456,8 @@ struct grpc_chttp2_stream_parsing {
grpc_chttp2_incoming_metadata_buffer incoming_metadata;
};
-struct grpc_chttp2_stream {
+struct grpc_chttp2_stream
+{
grpc_chttp2_stream_global global;
grpc_chttp2_stream_writing writing;
grpc_chttp2_stream_parsing parsing;
@@ -465,140 +479,71 @@ struct grpc_chttp2_stream {
/** Someone is unlocking the transport mutex: check to see if writes
are required, and schedule them if so */
-int grpc_chttp2_unlocking_check_writes(grpc_chttp2_transport_global *global,
- grpc_chttp2_transport_writing *writing);
-void grpc_chttp2_perform_writes(
- grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint,
- grpc_closure_list *closure_list);
-void grpc_chttp2_terminate_writing(void *transport_writing, int success,
- grpc_closure_list *closure_list);
-void grpc_chttp2_cleanup_writing(grpc_chttp2_transport_global *global,
- grpc_chttp2_transport_writing *writing,
- grpc_closure_list *closure_list);
-
-void grpc_chttp2_prepare_to_read(grpc_chttp2_transport_global *global,
- grpc_chttp2_transport_parsing *parsing);
+int grpc_chttp2_unlocking_check_writes (grpc_chttp2_transport_global * global, grpc_chttp2_transport_writing * writing);
+void grpc_chttp2_perform_writes (grpc_chttp2_transport_writing * transport_writing, grpc_endpoint * endpoint, grpc_closure_list * closure_list);
+void grpc_chttp2_terminate_writing (void *transport_writing, int success, grpc_closure_list * closure_list);
+void grpc_chttp2_cleanup_writing (grpc_chttp2_transport_global * global, grpc_chttp2_transport_writing * writing, grpc_closure_list * closure_list);
+
+void grpc_chttp2_prepare_to_read (grpc_chttp2_transport_global * global, grpc_chttp2_transport_parsing * parsing);
/** Process one slice of incoming data; return 1 if the connection is still
viable after reading, or 0 if the connection should be torn down */
-int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing,
- gpr_slice slice, grpc_closure_list *closure_list);
-void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *global,
- grpc_chttp2_transport_parsing *parsing,
- grpc_closure_list *closure_list);
+int grpc_chttp2_perform_read (grpc_chttp2_transport_parsing * transport_parsing, gpr_slice slice, grpc_closure_list * closure_list);
+void grpc_chttp2_publish_reads (grpc_chttp2_transport_global * global, grpc_chttp2_transport_parsing * parsing, grpc_closure_list * closure_list);
/** Get a writable stream
returns non-zero if there was a stream available */
-void grpc_chttp2_list_add_writable_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global);
-void grpc_chttp2_list_add_first_writable_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global);
-int grpc_chttp2_list_pop_writable_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_writing *transport_writing,
- grpc_chttp2_stream_global **stream_global,
- grpc_chttp2_stream_writing **stream_writing);
-void grpc_chttp2_list_remove_writable_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global);
-
-void grpc_chttp2_list_add_incoming_window_updated(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global);
-int grpc_chttp2_list_pop_incoming_window_updated(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_global **stream_global,
- grpc_chttp2_stream_parsing **stream_parsing);
-void grpc_chttp2_list_remove_incoming_window_updated(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global);
-
-void grpc_chttp2_list_add_writing_stream(
- grpc_chttp2_transport_writing *transport_writing,
- grpc_chttp2_stream_writing *stream_writing);
-int grpc_chttp2_list_have_writing_streams(
- grpc_chttp2_transport_writing *transport_writing);
-int grpc_chttp2_list_pop_writing_stream(
- grpc_chttp2_transport_writing *transport_writing,
- grpc_chttp2_stream_writing **stream_writing);
-
-void grpc_chttp2_list_add_written_stream(
- grpc_chttp2_transport_writing *transport_writing,
- grpc_chttp2_stream_writing *stream_writing);
-int grpc_chttp2_list_pop_written_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_writing *transport_writing,
- grpc_chttp2_stream_global **stream_global,
- grpc_chttp2_stream_writing **stream_writing);
-
-void grpc_chttp2_list_add_parsing_seen_stream(
- grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing);
-int grpc_chttp2_list_pop_parsing_seen_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_global **stream_global,
- grpc_chttp2_stream_parsing **stream_parsing);
-
-void grpc_chttp2_list_add_waiting_for_concurrency(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global);
-int grpc_chttp2_list_pop_waiting_for_concurrency(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global **stream_global);
-
-void grpc_chttp2_list_add_closed_waiting_for_parsing(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global);
-int grpc_chttp2_list_pop_closed_waiting_for_parsing(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global **stream_global);
-
-void grpc_chttp2_list_add_cancelled_waiting_for_writing(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global);
-int grpc_chttp2_list_pop_cancelled_waiting_for_writing(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global **stream_global);
-
-void grpc_chttp2_list_add_read_write_state_changed(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global);
-int grpc_chttp2_list_pop_read_write_state_changed(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global **stream_global);
-
-grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream(
- grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id);
-grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream(
- grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id);
-
-void grpc_chttp2_add_incoming_goaway(
- grpc_chttp2_transport_global *transport_global, gpr_uint32 goaway_error,
- gpr_slice goaway_text, grpc_closure_list *closure_list);
-
-void grpc_chttp2_register_stream(grpc_chttp2_transport *t,
- grpc_chttp2_stream *s);
+void grpc_chttp2_list_add_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global);
+void grpc_chttp2_list_add_first_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global);
+int grpc_chttp2_list_pop_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_writing ** stream_writing);
+void grpc_chttp2_list_remove_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global);
+
+void grpc_chttp2_list_add_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global);
+int grpc_chttp2_list_pop_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_parsing ** stream_parsing);
+void grpc_chttp2_list_remove_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global);
+
+void grpc_chttp2_list_add_writing_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing * stream_writing);
+int grpc_chttp2_list_have_writing_streams (grpc_chttp2_transport_writing * transport_writing);
+int grpc_chttp2_list_pop_writing_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing ** stream_writing);
+
+void grpc_chttp2_list_add_written_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing * stream_writing);
+int grpc_chttp2_list_pop_written_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_writing ** stream_writing);
+
+void grpc_chttp2_list_add_parsing_seen_stream (grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing);
+int grpc_chttp2_list_pop_parsing_seen_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_parsing ** stream_parsing);
+
+void grpc_chttp2_list_add_waiting_for_concurrency (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global);
+int grpc_chttp2_list_pop_waiting_for_concurrency (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global);
+
+void grpc_chttp2_list_add_closed_waiting_for_parsing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global);
+int grpc_chttp2_list_pop_closed_waiting_for_parsing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global);
+
+void grpc_chttp2_list_add_cancelled_waiting_for_writing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global);
+int grpc_chttp2_list_pop_cancelled_waiting_for_writing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global);
+
+void grpc_chttp2_list_add_read_write_state_changed (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global);
+int grpc_chttp2_list_pop_read_write_state_changed (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global);
+
+grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream (grpc_chttp2_transport_parsing * transport_parsing, gpr_uint32 id);
+grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream (grpc_chttp2_transport_parsing * transport_parsing, gpr_uint32 id);
+
+void grpc_chttp2_add_incoming_goaway (grpc_chttp2_transport_global * transport_global, gpr_uint32 goaway_error, gpr_slice goaway_text, grpc_closure_list * closure_list);
+
+void grpc_chttp2_register_stream (grpc_chttp2_transport * t, grpc_chttp2_stream * s);
/* returns 1 if this is the last stream, 0 otherwise */
-int grpc_chttp2_unregister_stream(grpc_chttp2_transport *t,
- grpc_chttp2_stream *s) GRPC_MUST_USE_RESULT;
-int grpc_chttp2_has_streams(grpc_chttp2_transport *t);
-void grpc_chttp2_for_all_streams(
- grpc_chttp2_transport_global *transport_global, void *user_data,
- void (*cb)(grpc_chttp2_transport_global *transport_global, void *user_data,
- grpc_chttp2_stream_global *stream_global));
+int
+grpc_chttp2_unregister_stream (grpc_chttp2_transport * t, grpc_chttp2_stream * s)
+ GRPC_MUST_USE_RESULT;
+ int grpc_chttp2_has_streams (grpc_chttp2_transport * t);
+ void grpc_chttp2_for_all_streams (grpc_chttp2_transport_global * transport_global, void *user_data, void (*cb) (grpc_chttp2_transport_global * transport_global, void *user_data, grpc_chttp2_stream_global * stream_global));
-void grpc_chttp2_parsing_become_skip_parser(
- grpc_chttp2_transport_parsing *transport_parsing);
+ void grpc_chttp2_parsing_become_skip_parser (grpc_chttp2_transport_parsing * transport_parsing);
#define GRPC_CHTTP2_CLIENT_CONNECT_STRING "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
#define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN \
(sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1)
-extern int grpc_http_trace;
-extern int grpc_flowctl_trace;
+ extern int grpc_http_trace;
+ extern int grpc_flowctl_trace;
#define GRPC_CHTTP2_IF_TRACING(stmt) \
if (!(grpc_http_trace)) \
@@ -623,9 +568,6 @@ extern int grpc_flowctl_trace;
(gpr_int64)(context->var), (gpr_int64)(delta)); \
}
-void grpc_chttp2_flowctl_trace(const char *file, int line, const char *reason,
- const char *context, const char *var,
- int is_client, gpr_uint32 stream_id,
- gpr_int64 current_value, gpr_int64 delta);
+ void grpc_chttp2_flowctl_trace (const char *file, int line, const char *reason, const char *context, const char *var, int is_client, gpr_uint32 stream_id, gpr_int64 current_value, gpr_int64 delta);
#endif
diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c
index f6ce35f9ac..944066eab3 100644
--- a/src/core/transport/chttp2/parsing.c
+++ b/src/core/transport/chttp2/parsing.c
@@ -42,58 +42,46 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-static int init_frame_parser(grpc_chttp2_transport_parsing *transport_parsing);
-static int init_header_frame_parser(
- grpc_chttp2_transport_parsing *transport_parsing, int is_continuation);
-static int init_data_frame_parser(
- grpc_chttp2_transport_parsing *transport_parsing);
-static int init_rst_stream_parser(
- grpc_chttp2_transport_parsing *transport_parsing);
-static int init_settings_frame_parser(
- grpc_chttp2_transport_parsing *transport_parsing);
-static int init_window_update_frame_parser(
- grpc_chttp2_transport_parsing *transport_parsing);
-static int init_ping_parser(grpc_chttp2_transport_parsing *transport_parsing);
-static int init_goaway_parser(grpc_chttp2_transport_parsing *transport_parsing);
-static int init_skip_frame_parser(
- grpc_chttp2_transport_parsing *transport_parsing, int is_header);
-
-static int parse_frame_slice(grpc_chttp2_transport_parsing *transport_parsing,
- gpr_slice slice, int is_last,
- grpc_closure_list *closure_list);
-
-void grpc_chttp2_prepare_to_read(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_parsing *transport_parsing) {
+static int init_frame_parser (grpc_chttp2_transport_parsing * transport_parsing);
+static int init_header_frame_parser (grpc_chttp2_transport_parsing * transport_parsing, int is_continuation);
+static int init_data_frame_parser (grpc_chttp2_transport_parsing * transport_parsing);
+static int init_rst_stream_parser (grpc_chttp2_transport_parsing * transport_parsing);
+static int init_settings_frame_parser (grpc_chttp2_transport_parsing * transport_parsing);
+static int init_window_update_frame_parser (grpc_chttp2_transport_parsing * transport_parsing);
+static int init_ping_parser (grpc_chttp2_transport_parsing * transport_parsing);
+static int init_goaway_parser (grpc_chttp2_transport_parsing * transport_parsing);
+static int init_skip_frame_parser (grpc_chttp2_transport_parsing * transport_parsing, int is_header);
+
+static int parse_frame_slice (grpc_chttp2_transport_parsing * transport_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list);
+
+void
+grpc_chttp2_prepare_to_read (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing)
+{
grpc_chttp2_stream_global *stream_global;
grpc_chttp2_stream_parsing *stream_parsing;
transport_parsing->next_stream_id = transport_global->next_stream_id;
/* update the parsing view of incoming window */
- if (transport_parsing->incoming_window != transport_global->incoming_window) {
- GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(
- "parse", transport_parsing, incoming_window,
- (gpr_int64)transport_global->incoming_window -
- (gpr_int64)transport_parsing->incoming_window);
- transport_parsing->incoming_window = transport_global->incoming_window;
- }
- while (grpc_chttp2_list_pop_incoming_window_updated(
- transport_global, transport_parsing, &stream_global, &stream_parsing)) {
- stream_parsing->id = stream_global->id;
- if (stream_parsing->incoming_window != stream_global->incoming_window) {
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "parse", transport_parsing, stream_parsing, incoming_window,
- (gpr_int64)stream_global->incoming_window -
- (gpr_int64)stream_parsing->incoming_window);
- stream_parsing->incoming_window = stream_global->incoming_window;
- }
- }
+ if (transport_parsing->incoming_window != transport_global->incoming_window)
+ {
+ GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("parse", transport_parsing, incoming_window, (gpr_int64) transport_global->incoming_window - (gpr_int64) transport_parsing->incoming_window);
+ transport_parsing->incoming_window = transport_global->incoming_window;
+ }
+ while (grpc_chttp2_list_pop_incoming_window_updated (transport_global, transport_parsing, &stream_global, &stream_parsing))
+ {
+ stream_parsing->id = stream_global->id;
+ if (stream_parsing->incoming_window != stream_global->incoming_window)
+ {
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parse", transport_parsing, stream_parsing, incoming_window, (gpr_int64) stream_global->incoming_window - (gpr_int64) stream_parsing->incoming_window);
+ stream_parsing->incoming_window = stream_global->incoming_window;
+ }
+ }
}
-void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_parsing *transport_parsing,
- grpc_closure_list *closure_list) {
+void
+grpc_chttp2_publish_reads (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing, grpc_closure_list * closure_list)
+{
grpc_chttp2_stream_global *stream_global;
grpc_chttp2_stream_parsing *stream_parsing;
@@ -105,145 +93,126 @@ void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *transport_global,
ID. So,
since we don't have server pushed streams, client should send
GOAWAY last-grpc_chttp2_stream-id=0 in this case. */
- if (!transport_parsing->is_client) {
- transport_global->last_incoming_stream_id =
- transport_parsing->incoming_stream_id;
- }
+ if (!transport_parsing->is_client)
+ {
+ transport_global->last_incoming_stream_id = transport_parsing->incoming_stream_id;
+ }
/* copy parsing qbuf to global qbuf */
- gpr_slice_buffer_move_into(&transport_parsing->qbuf, &transport_global->qbuf);
+ gpr_slice_buffer_move_into (&transport_parsing->qbuf, &transport_global->qbuf);
/* update global settings */
- if (transport_parsing->settings_updated) {
- memcpy(transport_global->settings[GRPC_PEER_SETTINGS],
- transport_parsing->settings, sizeof(transport_parsing->settings));
- transport_parsing->settings_updated = 0;
- }
+ if (transport_parsing->settings_updated)
+ {
+ memcpy (transport_global->settings[GRPC_PEER_SETTINGS], transport_parsing->settings, sizeof (transport_parsing->settings));
+ transport_parsing->settings_updated = 0;
+ }
/* update settings based on ack if received */
- if (transport_parsing->settings_ack_received) {
- memcpy(transport_global->settings[GRPC_ACKED_SETTINGS],
- transport_global->settings[GRPC_SENT_SETTINGS],
- GRPC_CHTTP2_NUM_SETTINGS * sizeof(gpr_uint32));
- transport_parsing->settings_ack_received = 0;
- }
+ if (transport_parsing->settings_ack_received)
+ {
+ memcpy (transport_global->settings[GRPC_ACKED_SETTINGS], transport_global->settings[GRPC_SENT_SETTINGS], GRPC_CHTTP2_NUM_SETTINGS * sizeof (gpr_uint32));
+ transport_parsing->settings_ack_received = 0;
+ }
/* move goaway to the global state if we received one (it will be
published later */
- if (transport_parsing->goaway_received) {
- grpc_chttp2_add_incoming_goaway(
- transport_global, (gpr_uint32)transport_parsing->goaway_error,
- transport_parsing->goaway_text, closure_list);
- transport_parsing->goaway_text = gpr_empty_slice();
- transport_parsing->goaway_received = 0;
- }
+ if (transport_parsing->goaway_received)
+ {
+ grpc_chttp2_add_incoming_goaway (transport_global, (gpr_uint32) transport_parsing->goaway_error, transport_parsing->goaway_text, closure_list);
+ transport_parsing->goaway_text = gpr_empty_slice ();
+ transport_parsing->goaway_received = 0;
+ }
/* propagate flow control tokens to global state */
- if (transport_parsing->outgoing_window_update) {
- GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(
- "parsed", transport_global, outgoing_window,
- transport_parsing->outgoing_window_update);
- GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(
- "parsed", transport_parsing, outgoing_window_update,
- -(gpr_int64)transport_parsing->outgoing_window_update);
- transport_global->outgoing_window +=
- transport_parsing->outgoing_window_update;
- transport_parsing->outgoing_window_update = 0;
- }
-
- if (transport_parsing->incoming_window_delta) {
- GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(
- "parsed", transport_global, incoming_window,
- -(gpr_int64)transport_parsing->incoming_window_delta);
- GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(
- "parsed", transport_parsing, incoming_window_delta,
- -(gpr_int64)transport_parsing->incoming_window_delta);
- transport_global->incoming_window -=
- transport_parsing->incoming_window_delta;
- transport_parsing->incoming_window_delta = 0;
- }
+ if (transport_parsing->outgoing_window_update)
+ {
+ GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("parsed", transport_global, outgoing_window, transport_parsing->outgoing_window_update);
+ GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("parsed", transport_parsing, outgoing_window_update, -(gpr_int64) transport_parsing->outgoing_window_update);
+ transport_global->outgoing_window += transport_parsing->outgoing_window_update;
+ transport_parsing->outgoing_window_update = 0;
+ }
+
+ if (transport_parsing->incoming_window_delta)
+ {
+ GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("parsed", transport_global, incoming_window, -(gpr_int64) transport_parsing->incoming_window_delta);
+ GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("parsed", transport_parsing, incoming_window_delta, -(gpr_int64) transport_parsing->incoming_window_delta);
+ transport_global->incoming_window -= transport_parsing->incoming_window_delta;
+ transport_parsing->incoming_window_delta = 0;
+ }
/* for each stream that saw an update, fixup global state */
- while (grpc_chttp2_list_pop_parsing_seen_stream(
- transport_global, transport_parsing, &stream_global, &stream_parsing)) {
- /* update incoming flow control window */
- if (stream_parsing->incoming_window_delta) {
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "parsed", transport_parsing, stream_global, incoming_window,
- -(gpr_int64)stream_parsing->incoming_window_delta);
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "parsed", transport_parsing, stream_parsing, incoming_window_delta,
- -(gpr_int64)stream_parsing->incoming_window_delta);
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "parsed", transport_parsing, stream_global, max_recv_bytes,
- -(gpr_int64)stream_parsing->incoming_window_delta);
- stream_global->incoming_window -= stream_parsing->incoming_window_delta;
- GPR_ASSERT(stream_global->max_recv_bytes >=
- stream_parsing->incoming_window_delta);
- stream_global->max_recv_bytes -= stream_parsing->incoming_window_delta;
- stream_parsing->incoming_window_delta = 0;
- grpc_chttp2_list_add_writable_stream(transport_global, stream_global);
- }
-
- /* update outgoing flow control window */
- if (stream_parsing->outgoing_window_update) {
- int was_zero = stream_global->outgoing_window <= 0;
- int is_zero;
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("parsed", transport_parsing,
- stream_global, outgoing_window,
- stream_parsing->outgoing_window_update);
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "parsed", transport_parsing, stream_parsing, outgoing_window_update,
- -(gpr_int64)stream_parsing->outgoing_window_update);
- GPR_ASSERT(stream_parsing->outgoing_window_update <= GPR_UINT32_MAX);
- stream_global->outgoing_window +=
- (gpr_uint32)stream_parsing->outgoing_window_update;
- stream_parsing->outgoing_window_update = 0;
- is_zero = stream_global->outgoing_window <= 0;
- if (was_zero && !is_zero) {
- grpc_chttp2_list_add_writable_stream(transport_global, stream_global);
- }
- }
-
- /* updating closed status */
- if (stream_parsing->received_close) {
- stream_global->read_closed = 1;
- grpc_chttp2_list_add_read_write_state_changed(transport_global,
- stream_global);
- }
- if (stream_parsing->saw_rst_stream) {
- stream_global->cancelled = 1;
- stream_global->cancelled_status = grpc_chttp2_http2_error_to_grpc_status(
- (grpc_chttp2_error_code)stream_parsing->rst_stream_reason);
- if (stream_parsing->rst_stream_reason == GRPC_CHTTP2_NO_ERROR) {
- stream_global->published_cancelled = 1;
- }
- grpc_chttp2_list_add_read_write_state_changed(transport_global,
- stream_global);
- }
-
- /* publish incoming stream ops */
- if (stream_parsing->data_parser.incoming_sopb.nops > 0) {
- grpc_incoming_metadata_buffer_move_to_referencing_sopb(
- &stream_parsing->incoming_metadata, &stream_global->incoming_metadata,
- &stream_parsing->data_parser.incoming_sopb);
- grpc_sopb_move_to(&stream_parsing->data_parser.incoming_sopb,
- &stream_global->incoming_sopb);
- grpc_chttp2_list_add_read_write_state_changed(transport_global,
- stream_global);
- }
- }
+ while (grpc_chttp2_list_pop_parsing_seen_stream (transport_global, transport_parsing, &stream_global, &stream_parsing))
+ {
+ /* update incoming flow control window */
+ if (stream_parsing->incoming_window_delta)
+ {
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parsed", transport_parsing, stream_global, incoming_window, -(gpr_int64) stream_parsing->incoming_window_delta);
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parsed", transport_parsing, stream_parsing, incoming_window_delta, -(gpr_int64) stream_parsing->incoming_window_delta);
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parsed", transport_parsing, stream_global, max_recv_bytes, -(gpr_int64) stream_parsing->incoming_window_delta);
+ stream_global->incoming_window -= stream_parsing->incoming_window_delta;
+ GPR_ASSERT (stream_global->max_recv_bytes >= stream_parsing->incoming_window_delta);
+ stream_global->max_recv_bytes -= stream_parsing->incoming_window_delta;
+ stream_parsing->incoming_window_delta = 0;
+ grpc_chttp2_list_add_writable_stream (transport_global, stream_global);
+ }
+
+ /* update outgoing flow control window */
+ if (stream_parsing->outgoing_window_update)
+ {
+ int was_zero = stream_global->outgoing_window <= 0;
+ int is_zero;
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parsed", transport_parsing, stream_global, outgoing_window, stream_parsing->outgoing_window_update);
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parsed", transport_parsing, stream_parsing, outgoing_window_update, -(gpr_int64) stream_parsing->outgoing_window_update);
+ GPR_ASSERT (stream_parsing->outgoing_window_update <= GPR_UINT32_MAX);
+ stream_global->outgoing_window += (gpr_uint32) stream_parsing->outgoing_window_update;
+ stream_parsing->outgoing_window_update = 0;
+ is_zero = stream_global->outgoing_window <= 0;
+ if (was_zero && !is_zero)
+ {
+ grpc_chttp2_list_add_writable_stream (transport_global, stream_global);
+ }
+ }
+
+ /* updating closed status */
+ if (stream_parsing->received_close)
+ {
+ stream_global->read_closed = 1;
+ grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global);
+ }
+ if (stream_parsing->saw_rst_stream)
+ {
+ stream_global->cancelled = 1;
+ stream_global->cancelled_status = grpc_chttp2_http2_error_to_grpc_status ((grpc_chttp2_error_code) stream_parsing->rst_stream_reason);
+ if (stream_parsing->rst_stream_reason == GRPC_CHTTP2_NO_ERROR)
+ {
+ stream_global->published_cancelled = 1;
+ }
+ grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global);
+ }
+
+ /* publish incoming stream ops */
+ if (stream_parsing->data_parser.incoming_sopb.nops > 0)
+ {
+ grpc_incoming_metadata_buffer_move_to_referencing_sopb (&stream_parsing->incoming_metadata, &stream_global->incoming_metadata, &stream_parsing->data_parser.incoming_sopb);
+ grpc_sopb_move_to (&stream_parsing->data_parser.incoming_sopb, &stream_global->incoming_sopb);
+ grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global);
+ }
+ }
}
-int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing,
- gpr_slice slice, grpc_closure_list *closure_list) {
- gpr_uint8 *beg = GPR_SLICE_START_PTR(slice);
- gpr_uint8 *end = GPR_SLICE_END_PTR(slice);
+int
+grpc_chttp2_perform_read (grpc_chttp2_transport_parsing * transport_parsing, gpr_slice slice, grpc_closure_list * closure_list)
+{
+ gpr_uint8 *beg = GPR_SLICE_START_PTR (slice);
+ gpr_uint8 *end = GPR_SLICE_END_PTR (slice);
gpr_uint8 *cur = beg;
- if (cur == end) return 1;
+ if (cur == end)
+ return 1;
- switch (transport_parsing->deframe_state) {
+ switch (transport_parsing->deframe_state)
+ {
case GRPC_DTS_CLIENT_PREFIX_0:
case GRPC_DTS_CLIENT_PREFIX_1:
case GRPC_DTS_CLIENT_PREFIX_2:
@@ -268,300 +237,294 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing,
case GRPC_DTS_CLIENT_PREFIX_21:
case GRPC_DTS_CLIENT_PREFIX_22:
case GRPC_DTS_CLIENT_PREFIX_23:
- while (cur != end && transport_parsing->deframe_state != GRPC_DTS_FH_0) {
- if (*cur != GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing
- ->deframe_state]) {
- gpr_log(GPR_INFO,
- "Connect string mismatch: expected '%c' (%d) got '%c' (%d) "
- "at byte %d",
- GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing
- ->deframe_state],
- (int)(gpr_uint8)GRPC_CHTTP2_CLIENT_CONNECT_STRING
- [transport_parsing->deframe_state],
- *cur, (int)*cur, transport_parsing->deframe_state);
- return 0;
- }
- ++cur;
- ++transport_parsing->deframe_state;
- }
- if (cur == end) {
- return 1;
- }
- /* fallthrough */
+ while (cur != end && transport_parsing->deframe_state != GRPC_DTS_FH_0)
+ {
+ if (*cur != GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing->deframe_state])
+ {
+ gpr_log (GPR_INFO, "Connect string mismatch: expected '%c' (%d) got '%c' (%d) " "at byte %d", GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing->deframe_state], (int) (gpr_uint8) GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing->deframe_state], *cur, (int) *cur, transport_parsing->deframe_state);
+ return 0;
+ }
+ ++cur;
+ ++transport_parsing->deframe_state;
+ }
+ if (cur == end)
+ {
+ return 1;
+ }
+ /* fallthrough */
dts_fh_0:
case GRPC_DTS_FH_0:
- GPR_ASSERT(cur < end);
- transport_parsing->incoming_frame_size = ((gpr_uint32)*cur) << 16;
- if (++cur == end) {
- transport_parsing->deframe_state = GRPC_DTS_FH_1;
- return 1;
- }
- /* fallthrough */
+ GPR_ASSERT (cur < end);
+ transport_parsing->incoming_frame_size = ((gpr_uint32) * cur) << 16;
+ if (++cur == end)
+ {
+ transport_parsing->deframe_state = GRPC_DTS_FH_1;
+ return 1;
+ }
+ /* fallthrough */
case GRPC_DTS_FH_1:
- GPR_ASSERT(cur < end);
- transport_parsing->incoming_frame_size |= ((gpr_uint32)*cur) << 8;
- if (++cur == end) {
- transport_parsing->deframe_state = GRPC_DTS_FH_2;
- return 1;
- }
- /* fallthrough */
+ GPR_ASSERT (cur < end);
+ transport_parsing->incoming_frame_size |= ((gpr_uint32) * cur) << 8;
+ if (++cur == end)
+ {
+ transport_parsing->deframe_state = GRPC_DTS_FH_2;
+ return 1;
+ }
+ /* fallthrough */
case GRPC_DTS_FH_2:
- GPR_ASSERT(cur < end);
+ GPR_ASSERT (cur < end);
transport_parsing->incoming_frame_size |= *cur;
- if (++cur == end) {
- transport_parsing->deframe_state = GRPC_DTS_FH_3;
- return 1;
- }
- /* fallthrough */
+ if (++cur == end)
+ {
+ transport_parsing->deframe_state = GRPC_DTS_FH_3;
+ return 1;
+ }
+ /* fallthrough */
case GRPC_DTS_FH_3:
- GPR_ASSERT(cur < end);
+ GPR_ASSERT (cur < end);
transport_parsing->incoming_frame_type = *cur;
- if (++cur == end) {
- transport_parsing->deframe_state = GRPC_DTS_FH_4;
- return 1;
- }
- /* fallthrough */
+ if (++cur == end)
+ {
+ transport_parsing->deframe_state = GRPC_DTS_FH_4;
+ return 1;
+ }
+ /* fallthrough */
case GRPC_DTS_FH_4:
- GPR_ASSERT(cur < end);
+ GPR_ASSERT (cur < end);
transport_parsing->incoming_frame_flags = *cur;
- if (++cur == end) {
- transport_parsing->deframe_state = GRPC_DTS_FH_5;
- return 1;
- }
- /* fallthrough */
+ if (++cur == end)
+ {
+ transport_parsing->deframe_state = GRPC_DTS_FH_5;
+ return 1;
+ }
+ /* fallthrough */
case GRPC_DTS_FH_5:
- GPR_ASSERT(cur < end);
- transport_parsing->incoming_stream_id = (((gpr_uint32)*cur) & 0x7f) << 24;
- if (++cur == end) {
- transport_parsing->deframe_state = GRPC_DTS_FH_6;
- return 1;
- }
- /* fallthrough */
+ GPR_ASSERT (cur < end);
+ transport_parsing->incoming_stream_id = (((gpr_uint32) * cur) & 0x7f) << 24;
+ if (++cur == end)
+ {
+ transport_parsing->deframe_state = GRPC_DTS_FH_6;
+ return 1;
+ }
+ /* fallthrough */
case GRPC_DTS_FH_6:
- GPR_ASSERT(cur < end);
- transport_parsing->incoming_stream_id |= ((gpr_uint32)*cur) << 16;
- if (++cur == end) {
- transport_parsing->deframe_state = GRPC_DTS_FH_7;
- return 1;
- }
- /* fallthrough */
+ GPR_ASSERT (cur < end);
+ transport_parsing->incoming_stream_id |= ((gpr_uint32) * cur) << 16;
+ if (++cur == end)
+ {
+ transport_parsing->deframe_state = GRPC_DTS_FH_7;
+ return 1;
+ }
+ /* fallthrough */
case GRPC_DTS_FH_7:
- GPR_ASSERT(cur < end);
- transport_parsing->incoming_stream_id |= ((gpr_uint32)*cur) << 8;
- if (++cur == end) {
- transport_parsing->deframe_state = GRPC_DTS_FH_8;
- return 1;
- }
- /* fallthrough */
+ GPR_ASSERT (cur < end);
+ transport_parsing->incoming_stream_id |= ((gpr_uint32) * cur) << 8;
+ if (++cur == end)
+ {
+ transport_parsing->deframe_state = GRPC_DTS_FH_8;
+ return 1;
+ }
+ /* fallthrough */
case GRPC_DTS_FH_8:
- GPR_ASSERT(cur < end);
- transport_parsing->incoming_stream_id |= ((gpr_uint32)*cur);
+ GPR_ASSERT (cur < end);
+ transport_parsing->incoming_stream_id |= ((gpr_uint32) * cur);
transport_parsing->deframe_state = GRPC_DTS_FRAME;
- if (!init_frame_parser(transport_parsing)) {
- return 0;
- }
- if (transport_parsing->incoming_stream_id) {
- transport_parsing->last_incoming_stream_id =
- transport_parsing->incoming_stream_id;
- }
- if (transport_parsing->incoming_frame_size == 0) {
- if (!parse_frame_slice(transport_parsing, gpr_empty_slice(), 1,
- closure_list)) {
- return 0;
- }
- transport_parsing->incoming_stream = NULL;
- if (++cur == end) {
- transport_parsing->deframe_state = GRPC_DTS_FH_0;
- return 1;
- }
- goto dts_fh_0; /* loop */
- }
- if (++cur == end) {
- return 1;
- }
- /* fallthrough */
+ if (!init_frame_parser (transport_parsing))
+ {
+ return 0;
+ }
+ if (transport_parsing->incoming_stream_id)
+ {
+ transport_parsing->last_incoming_stream_id = transport_parsing->incoming_stream_id;
+ }
+ if (transport_parsing->incoming_frame_size == 0)
+ {
+ if (!parse_frame_slice (transport_parsing, gpr_empty_slice (), 1, closure_list))
+ {
+ return 0;
+ }
+ transport_parsing->incoming_stream = NULL;
+ if (++cur == end)
+ {
+ transport_parsing->deframe_state = GRPC_DTS_FH_0;
+ return 1;
+ }
+ goto dts_fh_0; /* loop */
+ }
+ if (++cur == end)
+ {
+ return 1;
+ }
+ /* fallthrough */
case GRPC_DTS_FRAME:
- GPR_ASSERT(cur < end);
- if ((gpr_uint32)(end - cur) == transport_parsing->incoming_frame_size) {
- if (!parse_frame_slice(transport_parsing,
- gpr_slice_sub_no_ref(slice, (size_t)(cur - beg),
- (size_t)(end - beg)),
- 1, closure_list)) {
- return 0;
- }
- transport_parsing->deframe_state = GRPC_DTS_FH_0;
- transport_parsing->incoming_stream = NULL;
- return 1;
- } else if ((gpr_uint32)(end - cur) >
- transport_parsing->incoming_frame_size) {
- size_t cur_offset = (size_t)(cur - beg);
- if (!parse_frame_slice(
- transport_parsing,
- gpr_slice_sub_no_ref(
- slice, cur_offset,
- cur_offset + transport_parsing->incoming_frame_size),
- 1, closure_list)) {
- return 0;
- }
- cur += transport_parsing->incoming_frame_size;
- transport_parsing->incoming_stream = NULL;
- goto dts_fh_0; /* loop */
- } else {
- if (!parse_frame_slice(transport_parsing,
- gpr_slice_sub_no_ref(slice, (size_t)(cur - beg),
- (size_t)(end - beg)),
- 0, closure_list)) {
- return 0;
- }
- transport_parsing->incoming_frame_size -= (gpr_uint32)(end - cur);
- return 1;
- }
- gpr_log(GPR_ERROR, "should never reach here");
- abort();
- }
-
- gpr_log(GPR_ERROR, "should never reach here");
- abort();
+ GPR_ASSERT (cur < end);
+ if ((gpr_uint32) (end - cur) == transport_parsing->incoming_frame_size)
+ {
+ if (!parse_frame_slice (transport_parsing, gpr_slice_sub_no_ref (slice, (size_t) (cur - beg), (size_t) (end - beg)), 1, closure_list))
+ {
+ return 0;
+ }
+ transport_parsing->deframe_state = GRPC_DTS_FH_0;
+ transport_parsing->incoming_stream = NULL;
+ return 1;
+ }
+ else if ((gpr_uint32) (end - cur) > transport_parsing->incoming_frame_size)
+ {
+ size_t cur_offset = (size_t) (cur - beg);
+ if (!parse_frame_slice (transport_parsing, gpr_slice_sub_no_ref (slice, cur_offset, cur_offset + transport_parsing->incoming_frame_size), 1, closure_list))
+ {
+ return 0;
+ }
+ cur += transport_parsing->incoming_frame_size;
+ transport_parsing->incoming_stream = NULL;
+ goto dts_fh_0; /* loop */
+ }
+ else
+ {
+ if (!parse_frame_slice (transport_parsing, gpr_slice_sub_no_ref (slice, (size_t) (cur - beg), (size_t) (end - beg)), 0, closure_list))
+ {
+ return 0;
+ }
+ transport_parsing->incoming_frame_size -= (gpr_uint32) (end - cur);
+ return 1;
+ }
+ gpr_log (GPR_ERROR, "should never reach here");
+ abort ();
+ }
+
+ gpr_log (GPR_ERROR, "should never reach here");
+ abort ();
return 0;
}
-static int init_frame_parser(grpc_chttp2_transport_parsing *transport_parsing) {
- if (transport_parsing->expect_continuation_stream_id != 0) {
- if (transport_parsing->incoming_frame_type !=
- GRPC_CHTTP2_FRAME_CONTINUATION) {
- gpr_log(GPR_ERROR, "Expected CONTINUATION frame, got frame type %02x",
- transport_parsing->incoming_frame_type);
- return 0;
- }
- if (transport_parsing->expect_continuation_stream_id !=
- transport_parsing->incoming_stream_id) {
- gpr_log(GPR_ERROR,
- "Expected CONTINUATION frame for grpc_chttp2_stream %08x, got "
- "grpc_chttp2_stream %08x",
- transport_parsing->expect_continuation_stream_id,
- transport_parsing->incoming_stream_id);
- return 0;
+static int
+init_frame_parser (grpc_chttp2_transport_parsing * transport_parsing)
+{
+ if (transport_parsing->expect_continuation_stream_id != 0)
+ {
+ if (transport_parsing->incoming_frame_type != GRPC_CHTTP2_FRAME_CONTINUATION)
+ {
+ gpr_log (GPR_ERROR, "Expected CONTINUATION frame, got frame type %02x", transport_parsing->incoming_frame_type);
+ return 0;
+ }
+ if (transport_parsing->expect_continuation_stream_id != transport_parsing->incoming_stream_id)
+ {
+ gpr_log (GPR_ERROR, "Expected CONTINUATION frame for grpc_chttp2_stream %08x, got " "grpc_chttp2_stream %08x", transport_parsing->expect_continuation_stream_id, transport_parsing->incoming_stream_id);
+ return 0;
+ }
+ return init_header_frame_parser (transport_parsing, 1);
}
- return init_header_frame_parser(transport_parsing, 1);
- }
- switch (transport_parsing->incoming_frame_type) {
+ switch (transport_parsing->incoming_frame_type)
+ {
case GRPC_CHTTP2_FRAME_DATA:
- return init_data_frame_parser(transport_parsing);
+ return init_data_frame_parser (transport_parsing);
case GRPC_CHTTP2_FRAME_HEADER:
- return init_header_frame_parser(transport_parsing, 0);
+ return init_header_frame_parser (transport_parsing, 0);
case GRPC_CHTTP2_FRAME_CONTINUATION:
- gpr_log(GPR_ERROR, "Unexpected CONTINUATION frame");
+ gpr_log (GPR_ERROR, "Unexpected CONTINUATION frame");
return 0;
case GRPC_CHTTP2_FRAME_RST_STREAM:
- return init_rst_stream_parser(transport_parsing);
+ return init_rst_stream_parser (transport_parsing);
case GRPC_CHTTP2_FRAME_SETTINGS:
- return init_settings_frame_parser(transport_parsing);
+ return init_settings_frame_parser (transport_parsing);
case GRPC_CHTTP2_FRAME_WINDOW_UPDATE:
- return init_window_update_frame_parser(transport_parsing);
+ return init_window_update_frame_parser (transport_parsing);
case GRPC_CHTTP2_FRAME_PING:
- return init_ping_parser(transport_parsing);
+ return init_ping_parser (transport_parsing);
case GRPC_CHTTP2_FRAME_GOAWAY:
- return init_goaway_parser(transport_parsing);
+ return init_goaway_parser (transport_parsing);
default:
- gpr_log(GPR_ERROR, "Unknown frame type %02x",
- transport_parsing->incoming_frame_type);
- return init_skip_frame_parser(transport_parsing, 0);
- }
+ gpr_log (GPR_ERROR, "Unknown frame type %02x", transport_parsing->incoming_frame_type);
+ return init_skip_frame_parser (transport_parsing, 0);
+ }
}
-static grpc_chttp2_parse_error skip_parser(
- void *parser, grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last,
- grpc_closure_list *closure_list) {
+static grpc_chttp2_parse_error
+skip_parser (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list)
+{
return GRPC_CHTTP2_PARSE_OK;
}
-static void skip_header(void *tp, grpc_mdelem *md) { GRPC_MDELEM_UNREF(md); }
-
-static int init_skip_frame_parser(
- grpc_chttp2_transport_parsing *transport_parsing, int is_header) {
- if (is_header) {
- gpr_uint8 is_eoh = transport_parsing->expect_continuation_stream_id != 0;
- transport_parsing->parser = grpc_chttp2_header_parser_parse;
- transport_parsing->parser_data = &transport_parsing->hpack_parser;
- transport_parsing->hpack_parser.on_header = skip_header;
- transport_parsing->hpack_parser.on_header_user_data = NULL;
- transport_parsing->hpack_parser.is_boundary = is_eoh;
- transport_parsing->hpack_parser.is_eof =
- (gpr_uint8)(is_eoh ? transport_parsing->header_eof : 0);
- } else {
- transport_parsing->parser = skip_parser;
- }
+static void
+skip_header (void *tp, grpc_mdelem * md)
+{
+ GRPC_MDELEM_UNREF (md);
+}
+
+static int
+init_skip_frame_parser (grpc_chttp2_transport_parsing * transport_parsing, int is_header)
+{
+ if (is_header)
+ {
+ gpr_uint8 is_eoh = transport_parsing->expect_continuation_stream_id != 0;
+ transport_parsing->parser = grpc_chttp2_header_parser_parse;
+ transport_parsing->parser_data = &transport_parsing->hpack_parser;
+ transport_parsing->hpack_parser.on_header = skip_header;
+ transport_parsing->hpack_parser.on_header_user_data = NULL;
+ transport_parsing->hpack_parser.is_boundary = is_eoh;
+ transport_parsing->hpack_parser.is_eof = (gpr_uint8) (is_eoh ? transport_parsing->header_eof : 0);
+ }
+ else
+ {
+ transport_parsing->parser = skip_parser;
+ }
return 1;
}
-void grpc_chttp2_parsing_become_skip_parser(
- grpc_chttp2_transport_parsing *transport_parsing) {
- init_skip_frame_parser(
- transport_parsing,
- transport_parsing->parser == grpc_chttp2_header_parser_parse);
+void
+grpc_chttp2_parsing_become_skip_parser (grpc_chttp2_transport_parsing * transport_parsing)
+{
+ init_skip_frame_parser (transport_parsing, transport_parsing->parser == grpc_chttp2_header_parser_parse);
}
-static grpc_chttp2_parse_error update_incoming_window(
- grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing) {
- if (transport_parsing->incoming_frame_size >
- transport_parsing->incoming_window) {
- gpr_log(GPR_ERROR, "frame of size %d overflows incoming window of %d",
- transport_parsing->incoming_frame_size,
- transport_parsing->incoming_window);
- return GRPC_CHTTP2_CONNECTION_ERROR;
- }
-
- if (transport_parsing->incoming_frame_size >
- stream_parsing->incoming_window) {
- gpr_log(GPR_ERROR, "frame of size %d overflows incoming window of %d",
- transport_parsing->incoming_frame_size,
- stream_parsing->incoming_window);
- return GRPC_CHTTP2_CONNECTION_ERROR;
- }
-
- GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(
- "data", transport_parsing, incoming_window,
- -(gpr_int64)transport_parsing->incoming_frame_size);
- GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT("data", transport_parsing,
- incoming_window_delta,
- transport_parsing->incoming_frame_size);
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "data", transport_parsing, stream_parsing, incoming_window,
- -(gpr_int64)transport_parsing->incoming_frame_size);
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("data", transport_parsing, stream_parsing,
- incoming_window_delta,
- transport_parsing->incoming_frame_size);
+static grpc_chttp2_parse_error
+update_incoming_window (grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing)
+{
+ if (transport_parsing->incoming_frame_size > transport_parsing->incoming_window)
+ {
+ gpr_log (GPR_ERROR, "frame of size %d overflows incoming window of %d", transport_parsing->incoming_frame_size, transport_parsing->incoming_window);
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
+
+ if (transport_parsing->incoming_frame_size > stream_parsing->incoming_window)
+ {
+ gpr_log (GPR_ERROR, "frame of size %d overflows incoming window of %d", transport_parsing->incoming_frame_size, stream_parsing->incoming_window);
+ return GRPC_CHTTP2_CONNECTION_ERROR;
+ }
+
+ GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("data", transport_parsing, incoming_window, -(gpr_int64) transport_parsing->incoming_frame_size);
+ GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("data", transport_parsing, incoming_window_delta, transport_parsing->incoming_frame_size);
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("data", transport_parsing, stream_parsing, incoming_window, -(gpr_int64) transport_parsing->incoming_frame_size);
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("data", transport_parsing, stream_parsing, incoming_window_delta, transport_parsing->incoming_frame_size);
transport_parsing->incoming_window -= transport_parsing->incoming_frame_size;
- transport_parsing->incoming_window_delta +=
- transport_parsing->incoming_frame_size;
+ transport_parsing->incoming_window_delta += transport_parsing->incoming_frame_size;
stream_parsing->incoming_window -= transport_parsing->incoming_frame_size;
- stream_parsing->incoming_window_delta +=
- transport_parsing->incoming_frame_size;
- grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, stream_parsing);
+ stream_parsing->incoming_window_delta += transport_parsing->incoming_frame_size;
+ grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing);
return GRPC_CHTTP2_PARSE_OK;
}
-static int init_data_frame_parser(
- grpc_chttp2_transport_parsing *transport_parsing) {
- grpc_chttp2_stream_parsing *stream_parsing =
- grpc_chttp2_parsing_lookup_stream(transport_parsing,
- transport_parsing->incoming_stream_id);
+static int
+init_data_frame_parser (grpc_chttp2_transport_parsing * transport_parsing)
+{
+ grpc_chttp2_stream_parsing *stream_parsing = grpc_chttp2_parsing_lookup_stream (transport_parsing,
+ transport_parsing->incoming_stream_id);
grpc_chttp2_parse_error err = GRPC_CHTTP2_PARSE_OK;
if (!stream_parsing || stream_parsing->received_close)
- return init_skip_frame_parser(transport_parsing, 0);
- if (err == GRPC_CHTTP2_PARSE_OK) {
- err = update_incoming_window(transport_parsing, stream_parsing);
- }
- if (err == GRPC_CHTTP2_PARSE_OK) {
- err = grpc_chttp2_data_parser_begin_frame(
- &stream_parsing->data_parser, transport_parsing->incoming_frame_flags);
- }
- switch (err) {
+ return init_skip_frame_parser (transport_parsing, 0);
+ if (err == GRPC_CHTTP2_PARSE_OK)
+ {
+ err = update_incoming_window (transport_parsing, stream_parsing);
+ }
+ if (err == GRPC_CHTTP2_PARSE_OK)
+ {
+ err = grpc_chttp2_data_parser_begin_frame (&stream_parsing->data_parser, transport_parsing->incoming_frame_flags);
+ }
+ switch (err)
+ {
case GRPC_CHTTP2_PARSE_OK:
transport_parsing->incoming_stream = stream_parsing;
transport_parsing->parser = grpc_chttp2_data_parser_parse;
@@ -571,215 +534,214 @@ static int init_data_frame_parser(
stream_parsing->received_close = 1;
stream_parsing->saw_rst_stream = 1;
stream_parsing->rst_stream_reason = GRPC_CHTTP2_PROTOCOL_ERROR;
- gpr_slice_buffer_add(
- &transport_parsing->qbuf,
- grpc_chttp2_rst_stream_create(transport_parsing->incoming_stream_id,
- GRPC_CHTTP2_PROTOCOL_ERROR));
- return init_skip_frame_parser(transport_parsing, 0);
+ gpr_slice_buffer_add (&transport_parsing->qbuf, grpc_chttp2_rst_stream_create (transport_parsing->incoming_stream_id, GRPC_CHTTP2_PROTOCOL_ERROR));
+ return init_skip_frame_parser (transport_parsing, 0);
case GRPC_CHTTP2_CONNECTION_ERROR:
return 0;
- }
- gpr_log(GPR_ERROR, "should never reach here");
- abort();
+ }
+ gpr_log (GPR_ERROR, "should never reach here");
+ abort ();
return 0;
}
-static void free_timeout(void *p) { gpr_free(p); }
+static void
+free_timeout (void *p)
+{
+ gpr_free (p);
+}
-static void on_header(void *tp, grpc_mdelem *md) {
+static void
+on_header (void *tp, grpc_mdelem * md)
+{
grpc_chttp2_transport_parsing *transport_parsing = tp;
- grpc_chttp2_stream_parsing *stream_parsing =
- transport_parsing->incoming_stream;
-
- GPR_ASSERT(stream_parsing);
-
- GRPC_CHTTP2_IF_TRACING(gpr_log(
- GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", stream_parsing->id,
- transport_parsing->is_client ? "CLI" : "SVR",
- grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value)));
-
- if (md->key == transport_parsing->str_grpc_timeout) {
- gpr_timespec *cached_timeout = grpc_mdelem_get_user_data(md, free_timeout);
- if (!cached_timeout) {
- /* not already parsed: parse it now, and store the result away */
- cached_timeout = gpr_malloc(sizeof(gpr_timespec));
- if (!grpc_chttp2_decode_timeout(grpc_mdstr_as_c_string(md->value),
- cached_timeout)) {
- gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'",
- grpc_mdstr_as_c_string(md->value));
- *cached_timeout = gpr_inf_future(GPR_CLOCK_REALTIME);
- }
- grpc_mdelem_set_user_data(md, free_timeout, cached_timeout);
- }
- grpc_chttp2_incoming_metadata_buffer_set_deadline(
- &stream_parsing->incoming_metadata,
- gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), *cached_timeout));
- GRPC_MDELEM_UNREF(md);
- } else {
- grpc_chttp2_incoming_metadata_buffer_add(&stream_parsing->incoming_metadata,
- md);
- }
-
- grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, stream_parsing);
+ grpc_chttp2_stream_parsing *stream_parsing = transport_parsing->incoming_stream;
+
+ GPR_ASSERT (stream_parsing);
+
+ GRPC_CHTTP2_IF_TRACING (gpr_log (GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", stream_parsing->id, transport_parsing->is_client ? "CLI" : "SVR", grpc_mdstr_as_c_string (md->key), grpc_mdstr_as_c_string (md->value)));
+
+ if (md->key == transport_parsing->str_grpc_timeout)
+ {
+ gpr_timespec *cached_timeout = grpc_mdelem_get_user_data (md, free_timeout);
+ if (!cached_timeout)
+ {
+ /* not already parsed: parse it now, and store the result away */
+ cached_timeout = gpr_malloc (sizeof (gpr_timespec));
+ if (!grpc_chttp2_decode_timeout (grpc_mdstr_as_c_string (md->value), cached_timeout))
+ {
+ gpr_log (GPR_ERROR, "Ignoring bad timeout value '%s'", grpc_mdstr_as_c_string (md->value));
+ *cached_timeout = gpr_inf_future (GPR_CLOCK_REALTIME);
+ }
+ grpc_mdelem_set_user_data (md, free_timeout, cached_timeout);
+ }
+ grpc_chttp2_incoming_metadata_buffer_set_deadline (&stream_parsing->incoming_metadata, gpr_time_add (gpr_now (GPR_CLOCK_MONOTONIC), *cached_timeout));
+ GRPC_MDELEM_UNREF (md);
+ }
+ else
+ {
+ grpc_chttp2_incoming_metadata_buffer_add (&stream_parsing->incoming_metadata, md);
+ }
+
+ grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing);
}
-static int init_header_frame_parser(
- grpc_chttp2_transport_parsing *transport_parsing, int is_continuation) {
- gpr_uint8 is_eoh = (transport_parsing->incoming_frame_flags &
- GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0;
+static int
+init_header_frame_parser (grpc_chttp2_transport_parsing * transport_parsing, int is_continuation)
+{
+ gpr_uint8 is_eoh = (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0;
int via_accept = 0;
grpc_chttp2_stream_parsing *stream_parsing;
- if (is_eoh) {
- transport_parsing->expect_continuation_stream_id = 0;
- } else {
- transport_parsing->expect_continuation_stream_id =
- transport_parsing->incoming_stream_id;
- }
+ if (is_eoh)
+ {
+ transport_parsing->expect_continuation_stream_id = 0;
+ }
+ else
+ {
+ transport_parsing->expect_continuation_stream_id = transport_parsing->incoming_stream_id;
+ }
- if (!is_continuation) {
- transport_parsing->header_eof = (transport_parsing->incoming_frame_flags &
- GRPC_CHTTP2_DATA_FLAG_END_STREAM) != 0;
- }
+ if (!is_continuation)
+ {
+ transport_parsing->header_eof = (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_DATA_FLAG_END_STREAM) != 0;
+ }
/* could be a new grpc_chttp2_stream or an existing grpc_chttp2_stream */
- stream_parsing = grpc_chttp2_parsing_lookup_stream(
- transport_parsing, transport_parsing->incoming_stream_id);
- if (stream_parsing == NULL) {
- if (is_continuation) {
- gpr_log(GPR_ERROR,
- "grpc_chttp2_stream disbanded before CONTINUATION received");
- return init_skip_frame_parser(transport_parsing, 1);
- }
- if (transport_parsing->is_client) {
- if ((transport_parsing->incoming_stream_id & 1) &&
- transport_parsing->incoming_stream_id <
- transport_parsing->next_stream_id) {
- /* this is an old (probably cancelled) grpc_chttp2_stream */
- } else {
- gpr_log(GPR_ERROR,
- "ignoring new grpc_chttp2_stream creation on client");
- }
- return init_skip_frame_parser(transport_parsing, 1);
- } else if (transport_parsing->last_incoming_stream_id >
- transport_parsing->incoming_stream_id) {
- gpr_log(GPR_ERROR,
- "ignoring out of order new grpc_chttp2_stream request on server; "
- "last grpc_chttp2_stream "
- "id=%d, new grpc_chttp2_stream id=%d",
- transport_parsing->last_incoming_stream_id,
- transport_parsing->incoming_stream_id);
- return init_skip_frame_parser(transport_parsing, 1);
- } else if ((transport_parsing->incoming_stream_id & 1) == 0) {
- gpr_log(GPR_ERROR,
- "ignoring grpc_chttp2_stream with non-client generated index %d",
- transport_parsing->incoming_stream_id);
- return init_skip_frame_parser(transport_parsing, 1);
- }
- stream_parsing = transport_parsing->incoming_stream =
- grpc_chttp2_parsing_accept_stream(
- transport_parsing, transport_parsing->incoming_stream_id);
- if (stream_parsing == NULL) {
- gpr_log(GPR_ERROR, "grpc_chttp2_stream not accepted");
- return init_skip_frame_parser(transport_parsing, 1);
- }
- via_accept = 1;
- } else {
- transport_parsing->incoming_stream = stream_parsing;
- }
- GPR_ASSERT(stream_parsing != NULL && (via_accept == 0 || via_accept == 1));
- if (stream_parsing->received_close) {
- gpr_log(GPR_ERROR, "skipping already closed grpc_chttp2_stream header");
- transport_parsing->incoming_stream = NULL;
- return init_skip_frame_parser(transport_parsing, 1);
- }
+ stream_parsing = grpc_chttp2_parsing_lookup_stream (transport_parsing, transport_parsing->incoming_stream_id);
+ if (stream_parsing == NULL)
+ {
+ if (is_continuation)
+ {
+ gpr_log (GPR_ERROR, "grpc_chttp2_stream disbanded before CONTINUATION received");
+ return init_skip_frame_parser (transport_parsing, 1);
+ }
+ if (transport_parsing->is_client)
+ {
+ if ((transport_parsing->incoming_stream_id & 1) && transport_parsing->incoming_stream_id < transport_parsing->next_stream_id)
+ {
+ /* this is an old (probably cancelled) grpc_chttp2_stream */
+ }
+ else
+ {
+ gpr_log (GPR_ERROR, "ignoring new grpc_chttp2_stream creation on client");
+ }
+ return init_skip_frame_parser (transport_parsing, 1);
+ }
+ else if (transport_parsing->last_incoming_stream_id > transport_parsing->incoming_stream_id)
+ {
+ gpr_log (GPR_ERROR, "ignoring out of order new grpc_chttp2_stream request on server; " "last grpc_chttp2_stream " "id=%d, new grpc_chttp2_stream id=%d", transport_parsing->last_incoming_stream_id, transport_parsing->incoming_stream_id);
+ return init_skip_frame_parser (transport_parsing, 1);
+ }
+ else if ((transport_parsing->incoming_stream_id & 1) == 0)
+ {
+ gpr_log (GPR_ERROR, "ignoring grpc_chttp2_stream with non-client generated index %d", transport_parsing->incoming_stream_id);
+ return init_skip_frame_parser (transport_parsing, 1);
+ }
+ stream_parsing = transport_parsing->incoming_stream = grpc_chttp2_parsing_accept_stream (transport_parsing, transport_parsing->incoming_stream_id);
+ if (stream_parsing == NULL)
+ {
+ gpr_log (GPR_ERROR, "grpc_chttp2_stream not accepted");
+ return init_skip_frame_parser (transport_parsing, 1);
+ }
+ via_accept = 1;
+ }
+ else
+ {
+ transport_parsing->incoming_stream = stream_parsing;
+ }
+ GPR_ASSERT (stream_parsing != NULL && (via_accept == 0 || via_accept == 1));
+ if (stream_parsing->received_close)
+ {
+ gpr_log (GPR_ERROR, "skipping already closed grpc_chttp2_stream header");
+ transport_parsing->incoming_stream = NULL;
+ return init_skip_frame_parser (transport_parsing, 1);
+ }
transport_parsing->parser = grpc_chttp2_header_parser_parse;
transport_parsing->parser_data = &transport_parsing->hpack_parser;
transport_parsing->hpack_parser.on_header = on_header;
transport_parsing->hpack_parser.on_header_user_data = transport_parsing;
transport_parsing->hpack_parser.is_boundary = is_eoh;
- transport_parsing->hpack_parser.is_eof =
- (gpr_uint8)(is_eoh ? transport_parsing->header_eof : 0);
- if (!is_continuation && (transport_parsing->incoming_frame_flags &
- GRPC_CHTTP2_FLAG_HAS_PRIORITY)) {
- grpc_chttp2_hpack_parser_set_has_priority(&transport_parsing->hpack_parser);
- }
+ transport_parsing->hpack_parser.is_eof = (gpr_uint8) (is_eoh ? transport_parsing->header_eof : 0);
+ if (!is_continuation && (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_FLAG_HAS_PRIORITY))
+ {
+ grpc_chttp2_hpack_parser_set_has_priority (&transport_parsing->hpack_parser);
+ }
return 1;
}
-static int init_window_update_frame_parser(
- grpc_chttp2_transport_parsing *transport_parsing) {
- int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_window_update_parser_begin_frame(
- &transport_parsing->simple.window_update,
- transport_parsing->incoming_frame_size,
- transport_parsing->incoming_frame_flags);
- if (transport_parsing->incoming_stream_id) {
- transport_parsing->incoming_stream = grpc_chttp2_parsing_lookup_stream(
- transport_parsing, transport_parsing->incoming_stream_id);
- }
+static int
+init_window_update_frame_parser (grpc_chttp2_transport_parsing * transport_parsing)
+{
+ int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_window_update_parser_begin_frame (&transport_parsing->simple.window_update,
+ transport_parsing->incoming_frame_size,
+ transport_parsing->incoming_frame_flags);
+ if (transport_parsing->incoming_stream_id)
+ {
+ transport_parsing->incoming_stream = grpc_chttp2_parsing_lookup_stream (transport_parsing, transport_parsing->incoming_stream_id);
+ }
transport_parsing->parser = grpc_chttp2_window_update_parser_parse;
transport_parsing->parser_data = &transport_parsing->simple.window_update;
return ok;
}
-static int init_ping_parser(grpc_chttp2_transport_parsing *transport_parsing) {
- int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_ping_parser_begin_frame(
- &transport_parsing->simple.ping,
- transport_parsing->incoming_frame_size,
- transport_parsing->incoming_frame_flags);
+static int
+init_ping_parser (grpc_chttp2_transport_parsing * transport_parsing)
+{
+ int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_ping_parser_begin_frame (&transport_parsing->simple.ping,
+ transport_parsing->incoming_frame_size,
+ transport_parsing->incoming_frame_flags);
transport_parsing->parser = grpc_chttp2_ping_parser_parse;
transport_parsing->parser_data = &transport_parsing->simple.ping;
return ok;
}
-static int init_rst_stream_parser(
- grpc_chttp2_transport_parsing *transport_parsing) {
- int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_rst_stream_parser_begin_frame(
- &transport_parsing->simple.rst_stream,
- transport_parsing->incoming_frame_size,
- transport_parsing->incoming_frame_flags);
- transport_parsing->incoming_stream = grpc_chttp2_parsing_lookup_stream(
- transport_parsing, transport_parsing->incoming_stream_id);
- if (!transport_parsing->incoming_stream) {
- return init_skip_frame_parser(transport_parsing, 0);
- }
+static int
+init_rst_stream_parser (grpc_chttp2_transport_parsing * transport_parsing)
+{
+ int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_rst_stream_parser_begin_frame (&transport_parsing->simple.rst_stream,
+ transport_parsing->incoming_frame_size,
+ transport_parsing->incoming_frame_flags);
+ transport_parsing->incoming_stream = grpc_chttp2_parsing_lookup_stream (transport_parsing, transport_parsing->incoming_stream_id);
+ if (!transport_parsing->incoming_stream)
+ {
+ return init_skip_frame_parser (transport_parsing, 0);
+ }
transport_parsing->parser = grpc_chttp2_rst_stream_parser_parse;
transport_parsing->parser_data = &transport_parsing->simple.rst_stream;
return ok;
}
-static int init_goaway_parser(
- grpc_chttp2_transport_parsing *transport_parsing) {
- int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_goaway_parser_begin_frame(
- &transport_parsing->goaway_parser,
- transport_parsing->incoming_frame_size,
- transport_parsing->incoming_frame_flags);
+static int
+init_goaway_parser (grpc_chttp2_transport_parsing * transport_parsing)
+{
+ int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_goaway_parser_begin_frame (&transport_parsing->goaway_parser,
+ transport_parsing->incoming_frame_size,
+ transport_parsing->incoming_frame_flags);
transport_parsing->parser = grpc_chttp2_goaway_parser_parse;
transport_parsing->parser_data = &transport_parsing->goaway_parser;
return ok;
}
-static int init_settings_frame_parser(
- grpc_chttp2_transport_parsing *transport_parsing) {
+static int
+init_settings_frame_parser (grpc_chttp2_transport_parsing * transport_parsing)
+{
int ok;
- if (transport_parsing->incoming_stream_id != 0) {
- gpr_log(GPR_ERROR, "settings frame received for grpc_chttp2_stream %d",
- transport_parsing->incoming_stream_id);
- return 0;
- }
-
- ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_settings_parser_begin_frame(
- &transport_parsing->simple.settings,
- transport_parsing->incoming_frame_size,
- transport_parsing->incoming_frame_flags,
- transport_parsing->settings);
- if (!ok) {
- return 0;
- }
- if (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_FLAG_ACK) {
- transport_parsing->settings_ack_received = 1;
- }
+ if (transport_parsing->incoming_stream_id != 0)
+ {
+ gpr_log (GPR_ERROR, "settings frame received for grpc_chttp2_stream %d", transport_parsing->incoming_stream_id);
+ return 0;
+ }
+
+ ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_settings_parser_begin_frame (&transport_parsing->simple.settings, transport_parsing->incoming_frame_size, transport_parsing->incoming_frame_flags, transport_parsing->settings);
+ if (!ok)
+ {
+ return 0;
+ }
+ if (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_FLAG_ACK)
+ {
+ transport_parsing->settings_ack_received = 1;
+ }
transport_parsing->parser = grpc_chttp2_settings_parser_parse;
transport_parsing->parser_data = &transport_parsing->simple.settings;
return ok;
@@ -791,35 +753,31 @@ static int is_window_update_legal(gpr_int64 window_update, gpr_int64 window) {
}
*/
-static int parse_frame_slice(grpc_chttp2_transport_parsing *transport_parsing,
- gpr_slice slice, int is_last,
- grpc_closure_list *closure_list) {
- grpc_chttp2_stream_parsing *stream_parsing =
- transport_parsing->incoming_stream;
- switch (transport_parsing->parser(transport_parsing->parser_data,
- transport_parsing, stream_parsing, slice,
- is_last, closure_list)) {
+static int
+parse_frame_slice (grpc_chttp2_transport_parsing * transport_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list)
+{
+ grpc_chttp2_stream_parsing *stream_parsing = transport_parsing->incoming_stream;
+ switch (transport_parsing->parser (transport_parsing->parser_data, transport_parsing, stream_parsing, slice, is_last, closure_list))
+ {
case GRPC_CHTTP2_PARSE_OK:
- if (stream_parsing) {
- grpc_chttp2_list_add_parsing_seen_stream(transport_parsing,
- stream_parsing);
- }
+ if (stream_parsing)
+ {
+ grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing);
+ }
return 1;
case GRPC_CHTTP2_STREAM_ERROR:
- grpc_chttp2_parsing_become_skip_parser(transport_parsing);
- if (stream_parsing) {
- stream_parsing->saw_rst_stream = 1;
- stream_parsing->rst_stream_reason = GRPC_CHTTP2_PROTOCOL_ERROR;
- gpr_slice_buffer_add(
- &transport_parsing->qbuf,
- grpc_chttp2_rst_stream_create(transport_parsing->incoming_stream_id,
- GRPC_CHTTP2_PROTOCOL_ERROR));
- }
+ grpc_chttp2_parsing_become_skip_parser (transport_parsing);
+ if (stream_parsing)
+ {
+ stream_parsing->saw_rst_stream = 1;
+ stream_parsing->rst_stream_reason = GRPC_CHTTP2_PROTOCOL_ERROR;
+ gpr_slice_buffer_add (&transport_parsing->qbuf, grpc_chttp2_rst_stream_create (transport_parsing->incoming_stream_id, GRPC_CHTTP2_PROTOCOL_ERROR));
+ }
return 1;
case GRPC_CHTTP2_CONNECTION_ERROR:
return 0;
- }
- gpr_log(GPR_ERROR, "should never reach here");
- abort();
+ }
+ gpr_log (GPR_ERROR, "should never reach here");
+ abort ();
return 0;
}
diff --git a/src/core/transport/chttp2/status_conversion.c b/src/core/transport/chttp2/status_conversion.c
index bf214b017a..8be4dc6150 100644
--- a/src/core/transport/chttp2/status_conversion.c
+++ b/src/core/transport/chttp2/status_conversion.c
@@ -33,8 +33,11 @@
#include "src/core/transport/chttp2/status_conversion.h"
-int grpc_chttp2_grpc_status_to_http2_error(grpc_status_code status) {
- switch (status) {
+int
+grpc_chttp2_grpc_status_to_http2_error (grpc_status_code status)
+{
+ switch (status)
+ {
case GRPC_STATUS_OK:
return GRPC_CHTTP2_NO_ERROR;
case GRPC_STATUS_CANCELLED:
@@ -47,12 +50,14 @@ int grpc_chttp2_grpc_status_to_http2_error(grpc_status_code status) {
return GRPC_CHTTP2_REFUSED_STREAM;
default:
return GRPC_CHTTP2_INTERNAL_ERROR;
- }
+ }
}
-grpc_status_code grpc_chttp2_http2_error_to_grpc_status(
- grpc_chttp2_error_code error) {
- switch (error) {
+grpc_status_code
+grpc_chttp2_http2_error_to_grpc_status (grpc_chttp2_error_code error)
+{
+ switch (error)
+ {
case GRPC_CHTTP2_NO_ERROR:
/* should never be received */
return GRPC_STATUS_INTERNAL;
@@ -66,12 +71,15 @@ grpc_status_code grpc_chttp2_http2_error_to_grpc_status(
return GRPC_STATUS_UNAVAILABLE;
default:
return GRPC_STATUS_INTERNAL;
- }
+ }
}
-grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) {
- switch (status) {
- /* these HTTP2 status codes are called out explicitly in status.proto */
+grpc_status_code
+grpc_chttp2_http2_status_to_grpc_status (int status)
+{
+ switch (status)
+ {
+ /* these HTTP2 status codes are called out explicitly in status.proto */
case 200:
return GRPC_STATUS_OK;
case 400:
@@ -98,12 +106,14 @@ grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) {
return GRPC_STATUS_UNAVAILABLE;
case 504:
return GRPC_STATUS_DEADLINE_EXCEEDED;
- /* everything else is unknown */
+ /* everything else is unknown */
default:
return GRPC_STATUS_UNKNOWN;
- }
+ }
}
-int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status) {
+int
+grpc_chttp2_grpc_status_to_http2_status (grpc_status_code status)
+{
return 200;
}
diff --git a/src/core/transport/chttp2/status_conversion.h b/src/core/transport/chttp2/status_conversion.h
index 0ec5b560b8..ae5b4960df 100644
--- a/src/core/transport/chttp2/status_conversion.h
+++ b/src/core/transport/chttp2/status_conversion.h
@@ -38,13 +38,11 @@
#include "src/core/transport/chttp2/http2_errors.h"
/* Conversion of grpc status codes to http2 error codes (for RST_STREAM) */
-grpc_chttp2_error_code grpc_chttp2_grpc_status_to_http2_error(
- grpc_status_code status);
-grpc_status_code grpc_chttp2_http2_error_to_grpc_status(
- grpc_chttp2_error_code error);
+grpc_chttp2_error_code grpc_chttp2_grpc_status_to_http2_error (grpc_status_code status);
+grpc_status_code grpc_chttp2_http2_error_to_grpc_status (grpc_chttp2_error_code error);
/* Conversion of HTTP status codes (:status) to grpc status codes */
-grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status);
-int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status);
+grpc_status_code grpc_chttp2_http2_status_to_grpc_status (int status);
+int grpc_chttp2_grpc_status_to_http2_status (grpc_status_code status);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_STATUS_CONVERSION_H */
diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c
index eb02ccdec3..cafd735ba2 100644
--- a/src/core/transport/chttp2/stream_encoder.c
+++ b/src/core/transport/chttp2/stream_encoder.c
@@ -55,9 +55,11 @@
#define MAX_DECODER_SPACE_USAGE 512
/* what kind of frame our we encoding? */
-typedef enum { HEADER, DATA, NONE } frame_type;
+typedef enum
+{ HEADER, DATA, NONE } frame_type;
-typedef struct {
+typedef struct
+{
frame_type cur_frame_type;
/* number of bytes in 'output' when we started the frame - used to calculate
frame length */
@@ -74,28 +76,30 @@ typedef struct {
} framer_state;
/* fills p (which is expected to be 9 bytes long) with a data frame header */
-static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, size_t len,
- gpr_uint8 flags) {
- GPR_ASSERT(len < 16777316);
- *p++ = (gpr_uint8)(len >> 16);
- *p++ = (gpr_uint8)(len >> 8);
- *p++ = (gpr_uint8)(len);
+static void
+fill_header (gpr_uint8 * p, gpr_uint8 type, gpr_uint32 id, size_t len, gpr_uint8 flags)
+{
+ GPR_ASSERT (len < 16777316);
+ *p++ = (gpr_uint8) (len >> 16);
+ *p++ = (gpr_uint8) (len >> 8);
+ *p++ = (gpr_uint8) (len);
*p++ = type;
*p++ = flags;
- *p++ = (gpr_uint8)(id >> 24);
- *p++ = (gpr_uint8)(id >> 16);
- *p++ = (gpr_uint8)(id >> 8);
- *p++ = (gpr_uint8)(id);
+ *p++ = (gpr_uint8) (id >> 24);
+ *p++ = (gpr_uint8) (id >> 16);
+ *p++ = (gpr_uint8) (id >> 8);
+ *p++ = (gpr_uint8) (id);
}
/* finish a frame - fill in the previously reserved header */
-static void finish_frame(framer_state *st, int is_header_boundary,
- int is_last_in_stream) {
+static void
+finish_frame (framer_state * st, int is_header_boundary, int is_last_in_stream)
+{
gpr_uint8 type = 0xff;
- switch (st->cur_frame_type) {
+ switch (st->cur_frame_type)
+ {
case HEADER:
- type = st->last_was_header ? GRPC_CHTTP2_FRAME_CONTINUATION
- : GRPC_CHTTP2_FRAME_HEADER;
+ type = st->last_was_header ? GRPC_CHTTP2_FRAME_CONTINUATION : GRPC_CHTTP2_FRAME_HEADER;
st->last_was_header = 1;
break;
case DATA:
@@ -105,397 +109,435 @@ static void finish_frame(framer_state *st, int is_header_boundary,
break;
case NONE:
return;
- }
- fill_header(
- GPR_SLICE_START_PTR(st->output->slices[st->header_idx]), type,
- st->stream_id, st->output->length - st->output_length_at_start_of_frame,
- (gpr_uint8)(
- (is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) |
- (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0)));
+ }
+ fill_header (GPR_SLICE_START_PTR (st->output->slices[st->header_idx]), type, st->stream_id, st->output->length - st->output_length_at_start_of_frame, (gpr_uint8) ((is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0)));
st->cur_frame_type = NONE;
}
/* begin a new frame: reserve off header space, remember how many bytes we'd
output before beginning */
-static void begin_frame(framer_state *st, frame_type type) {
- GPR_ASSERT(type != NONE);
- GPR_ASSERT(st->cur_frame_type == NONE);
+static void
+begin_frame (framer_state * st, frame_type type)
+{
+ GPR_ASSERT (type != NONE);
+ GPR_ASSERT (st->cur_frame_type == NONE);
st->cur_frame_type = type;
- st->header_idx =
- gpr_slice_buffer_add_indexed(st->output, gpr_slice_malloc(9));
+ st->header_idx = gpr_slice_buffer_add_indexed (st->output, gpr_slice_malloc (9));
st->output_length_at_start_of_frame = st->output->length;
}
-static void begin_new_frame(framer_state *st, frame_type type) {
- finish_frame(st, 1, 0);
+static void
+begin_new_frame (framer_state * st, frame_type type)
+{
+ finish_frame (st, 1, 0);
st->last_was_header = 0;
- begin_frame(st, type);
+ begin_frame (st, type);
}
/* make sure that the current frame is of the type desired, and has sufficient
space to add at least about_to_add bytes -- finishes the current frame if
needed */
-static void ensure_frame_type(framer_state *st, frame_type type,
- size_t need_bytes) {
- if (st->cur_frame_type == type &&
- st->output->length - st->output_length_at_start_of_frame + need_bytes <=
- GRPC_CHTTP2_MAX_PAYLOAD_LENGTH) {
- return;
- }
- finish_frame(st, type != HEADER, 0);
- begin_frame(st, type);
+static void
+ensure_frame_type (framer_state * st, frame_type type, size_t need_bytes)
+{
+ if (st->cur_frame_type == type && st->output->length - st->output_length_at_start_of_frame + need_bytes <= GRPC_CHTTP2_MAX_PAYLOAD_LENGTH)
+ {
+ return;
+ }
+ finish_frame (st, type != HEADER, 0);
+ begin_frame (st, type);
}
/* increment a filter count, halve all counts if one element reaches max */
-static void inc_filter(gpr_uint8 idx, gpr_uint32 *sum, gpr_uint8 *elems) {
+static void
+inc_filter (gpr_uint8 idx, gpr_uint32 * sum, gpr_uint8 * elems)
+{
elems[idx]++;
- if (elems[idx] < 255) {
- (*sum)++;
- } else {
- int i;
- *sum = 0;
- for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_FILTERS; i++) {
- elems[i] /= 2;
- (*sum) += elems[i];
- }
- }
+ if (elems[idx] < 255)
+ {
+ (*sum)++;
+ }
+ else
+ {
+ int i;
+ *sum = 0;
+ for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_FILTERS; i++)
+ {
+ elems[i] /= 2;
+ (*sum) += elems[i];
+ }
+ }
}
-static void add_header_data(framer_state *st, gpr_slice slice) {
- size_t len = GPR_SLICE_LENGTH(slice);
+static void
+add_header_data (framer_state * st, gpr_slice slice)
+{
+ size_t len = GPR_SLICE_LENGTH (slice);
size_t remaining;
- if (len == 0) return;
- ensure_frame_type(st, HEADER, 1);
- remaining = GRPC_CHTTP2_MAX_PAYLOAD_LENGTH +
- st->output_length_at_start_of_frame - st->output->length;
- if (len <= remaining) {
- gpr_slice_buffer_add(st->output, slice);
- } else {
- gpr_slice_buffer_add(st->output, gpr_slice_split_head(&slice, remaining));
- add_header_data(st, slice);
- }
+ if (len == 0)
+ return;
+ ensure_frame_type (st, HEADER, 1);
+ remaining = GRPC_CHTTP2_MAX_PAYLOAD_LENGTH + st->output_length_at_start_of_frame - st->output->length;
+ if (len <= remaining)
+ {
+ gpr_slice_buffer_add (st->output, slice);
+ }
+ else
+ {
+ gpr_slice_buffer_add (st->output, gpr_slice_split_head (&slice, remaining));
+ add_header_data (st, slice);
+ }
}
-static gpr_uint8 *add_tiny_header_data(framer_state *st, size_t len) {
- ensure_frame_type(st, HEADER, len);
- return gpr_slice_buffer_tiny_add(st->output, len);
+static gpr_uint8 *
+add_tiny_header_data (framer_state * st, size_t len)
+{
+ ensure_frame_type (st, HEADER, len);
+ return gpr_slice_buffer_tiny_add (st->output, len);
}
/* add an element to the decoder table: returns metadata element to unref */
-static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c,
- grpc_mdelem *elem) {
+static grpc_mdelem *
+add_elem (grpc_chttp2_hpack_compressor * c, grpc_mdelem * elem)
+{
gpr_uint32 key_hash = elem->key->hash;
- gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash);
+ gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH (key_hash, elem->value->hash);
gpr_uint32 new_index = c->tail_remote_index + c->table_elems + 1;
- size_t elem_size = 32 + GPR_SLICE_LENGTH(elem->key->slice) +
- GPR_SLICE_LENGTH(elem->value->slice);
+ size_t elem_size = 32 + GPR_SLICE_LENGTH (elem->key->slice) + GPR_SLICE_LENGTH (elem->value->slice);
grpc_mdelem *elem_to_unref;
- GPR_ASSERT(elem_size < 65536);
+ GPR_ASSERT (elem_size < 65536);
/* Reserve space for this element in the remote table: if this overflows
the current table, drop elements until it fits, matching the decompressor
algorithm */
/* TODO(ctiller): constant */
- while (c->table_size + elem_size > 4096) {
- c->tail_remote_index++;
- GPR_ASSERT(c->tail_remote_index > 0);
- GPR_ASSERT(c->table_size >=
- c->table_elem_size[c->tail_remote_index %
- GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]);
- GPR_ASSERT(c->table_elems > 0);
- c->table_size =
- (gpr_uint16)(c->table_size -
- c->table_elem_size[c->tail_remote_index %
- GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]);
- c->table_elems--;
- }
- GPR_ASSERT(c->table_elems < GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS);
- c->table_elem_size[new_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS] =
- (gpr_uint16)elem_size;
- c->table_size = (gpr_uint16)(c->table_size + elem_size);
+ while (c->table_size + elem_size > 4096)
+ {
+ c->tail_remote_index++;
+ GPR_ASSERT (c->tail_remote_index > 0);
+ GPR_ASSERT (c->table_size >= c->table_elem_size[c->tail_remote_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]);
+ GPR_ASSERT (c->table_elems > 0);
+ c->table_size = (gpr_uint16) (c->table_size - c->table_elem_size[c->tail_remote_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]);
+ c->table_elems--;
+ }
+ GPR_ASSERT (c->table_elems < GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS);
+ c->table_elem_size[new_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS] = (gpr_uint16) elem_size;
+ c->table_size = (gpr_uint16) (c->table_size + elem_size);
c->table_elems++;
/* Store this element into {entries,indices}_elem */
- if (c->entries_elems[HASH_FRAGMENT_2(elem_hash)] == elem) {
- /* already there: update with new index */
- c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index;
- elem_to_unref = elem;
- } else if (c->entries_elems[HASH_FRAGMENT_3(elem_hash)] == elem) {
- /* already there (cuckoo): update with new index */
- c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index;
- elem_to_unref = elem;
- } else if (c->entries_elems[HASH_FRAGMENT_2(elem_hash)] == NULL) {
- /* not there, but a free element: add */
- c->entries_elems[HASH_FRAGMENT_2(elem_hash)] = elem;
- c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index;
- elem_to_unref = NULL;
- } else if (c->entries_elems[HASH_FRAGMENT_3(elem_hash)] == NULL) {
- /* not there (cuckoo), but a free element: add */
- c->entries_elems[HASH_FRAGMENT_3(elem_hash)] = elem;
- c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index;
- elem_to_unref = NULL;
- } else if (c->indices_elems[HASH_FRAGMENT_2(elem_hash)] <
- c->indices_elems[HASH_FRAGMENT_3(elem_hash)]) {
- /* not there: replace oldest */
- elem_to_unref = c->entries_elems[HASH_FRAGMENT_2(elem_hash)];
- c->entries_elems[HASH_FRAGMENT_2(elem_hash)] = elem;
- c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index;
- } else {
- /* not there: replace oldest */
- elem_to_unref = c->entries_elems[HASH_FRAGMENT_3(elem_hash)];
- c->entries_elems[HASH_FRAGMENT_3(elem_hash)] = elem;
- c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index;
- }
+ if (c->entries_elems[HASH_FRAGMENT_2 (elem_hash)] == elem)
+ {
+ /* already there: update with new index */
+ c->indices_elems[HASH_FRAGMENT_2 (elem_hash)] = new_index;
+ elem_to_unref = elem;
+ }
+ else if (c->entries_elems[HASH_FRAGMENT_3 (elem_hash)] == elem)
+ {
+ /* already there (cuckoo): update with new index */
+ c->indices_elems[HASH_FRAGMENT_3 (elem_hash)] = new_index;
+ elem_to_unref = elem;
+ }
+ else if (c->entries_elems[HASH_FRAGMENT_2 (elem_hash)] == NULL)
+ {
+ /* not there, but a free element: add */
+ c->entries_elems[HASH_FRAGMENT_2 (elem_hash)] = elem;
+ c->indices_elems[HASH_FRAGMENT_2 (elem_hash)] = new_index;
+ elem_to_unref = NULL;
+ }
+ else if (c->entries_elems[HASH_FRAGMENT_3 (elem_hash)] == NULL)
+ {
+ /* not there (cuckoo), but a free element: add */
+ c->entries_elems[HASH_FRAGMENT_3 (elem_hash)] = elem;
+ c->indices_elems[HASH_FRAGMENT_3 (elem_hash)] = new_index;
+ elem_to_unref = NULL;
+ }
+ else if (c->indices_elems[HASH_FRAGMENT_2 (elem_hash)] < c->indices_elems[HASH_FRAGMENT_3 (elem_hash)])
+ {
+ /* not there: replace oldest */
+ elem_to_unref = c->entries_elems[HASH_FRAGMENT_2 (elem_hash)];
+ c->entries_elems[HASH_FRAGMENT_2 (elem_hash)] = elem;
+ c->indices_elems[HASH_FRAGMENT_2 (elem_hash)] = new_index;
+ }
+ else
+ {
+ /* not there: replace oldest */
+ elem_to_unref = c->entries_elems[HASH_FRAGMENT_3 (elem_hash)];
+ c->entries_elems[HASH_FRAGMENT_3 (elem_hash)] = elem;
+ c->indices_elems[HASH_FRAGMENT_3 (elem_hash)] = new_index;
+ }
/* do exactly the same for the key (so we can find by that again too) */
- if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == elem->key) {
- c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index;
- } else if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == elem->key) {
- c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index;
- } else if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == NULL) {
- c->entries_keys[HASH_FRAGMENT_2(key_hash)] = GRPC_MDSTR_REF(elem->key);
- c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index;
- } else if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == NULL) {
- c->entries_keys[HASH_FRAGMENT_3(key_hash)] = GRPC_MDSTR_REF(elem->key);
- c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index;
- } else if (c->indices_keys[HASH_FRAGMENT_2(key_hash)] <
- c->indices_keys[HASH_FRAGMENT_3(key_hash)]) {
- GRPC_MDSTR_UNREF(c->entries_keys[HASH_FRAGMENT_2(key_hash)]);
- c->entries_keys[HASH_FRAGMENT_2(key_hash)] = GRPC_MDSTR_REF(elem->key);
- c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index;
- } else {
- GRPC_MDSTR_UNREF(c->entries_keys[HASH_FRAGMENT_3(key_hash)]);
- c->entries_keys[HASH_FRAGMENT_3(key_hash)] = GRPC_MDSTR_REF(elem->key);
- c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index;
- }
+ if (c->entries_keys[HASH_FRAGMENT_2 (key_hash)] == elem->key)
+ {
+ c->indices_keys[HASH_FRAGMENT_2 (key_hash)] = new_index;
+ }
+ else if (c->entries_keys[HASH_FRAGMENT_3 (key_hash)] == elem->key)
+ {
+ c->indices_keys[HASH_FRAGMENT_3 (key_hash)] = new_index;
+ }
+ else if (c->entries_keys[HASH_FRAGMENT_2 (key_hash)] == NULL)
+ {
+ c->entries_keys[HASH_FRAGMENT_2 (key_hash)] = GRPC_MDSTR_REF (elem->key);
+ c->indices_keys[HASH_FRAGMENT_2 (key_hash)] = new_index;
+ }
+ else if (c->entries_keys[HASH_FRAGMENT_3 (key_hash)] == NULL)
+ {
+ c->entries_keys[HASH_FRAGMENT_3 (key_hash)] = GRPC_MDSTR_REF (elem->key);
+ c->indices_keys[HASH_FRAGMENT_3 (key_hash)] = new_index;
+ }
+ else if (c->indices_keys[HASH_FRAGMENT_2 (key_hash)] < c->indices_keys[HASH_FRAGMENT_3 (key_hash)])
+ {
+ GRPC_MDSTR_UNREF (c->entries_keys[HASH_FRAGMENT_2 (key_hash)]);
+ c->entries_keys[HASH_FRAGMENT_2 (key_hash)] = GRPC_MDSTR_REF (elem->key);
+ c->indices_keys[HASH_FRAGMENT_2 (key_hash)] = new_index;
+ }
+ else
+ {
+ GRPC_MDSTR_UNREF (c->entries_keys[HASH_FRAGMENT_3 (key_hash)]);
+ c->entries_keys[HASH_FRAGMENT_3 (key_hash)] = GRPC_MDSTR_REF (elem->key);
+ c->indices_keys[HASH_FRAGMENT_3 (key_hash)] = new_index;
+ }
return elem_to_unref;
}
-static void emit_indexed(grpc_chttp2_hpack_compressor *c, gpr_uint32 index,
- framer_state *st) {
- gpr_uint32 len = GRPC_CHTTP2_VARINT_LENGTH(index, 1);
- GRPC_CHTTP2_WRITE_VARINT(index, 1, 0x80, add_tiny_header_data(st, len), len);
+static void
+emit_indexed (grpc_chttp2_hpack_compressor * c, gpr_uint32 index, framer_state * st)
+{
+ gpr_uint32 len = GRPC_CHTTP2_VARINT_LENGTH (index, 1);
+ GRPC_CHTTP2_WRITE_VARINT (index, 1, 0x80, add_tiny_header_data (st, len), len);
}
-static gpr_slice get_wire_value(grpc_mdelem *elem, gpr_uint8 *huffman_prefix) {
- if (grpc_is_binary_header((const char *)GPR_SLICE_START_PTR(elem->key->slice),
- GPR_SLICE_LENGTH(elem->key->slice))) {
- *huffman_prefix = 0x80;
- return grpc_mdstr_as_base64_encoded_and_huffman_compressed(elem->value);
- }
+static gpr_slice
+get_wire_value (grpc_mdelem * elem, gpr_uint8 * huffman_prefix)
+{
+ if (grpc_is_binary_header ((const char *) GPR_SLICE_START_PTR (elem->key->slice), GPR_SLICE_LENGTH (elem->key->slice)))
+ {
+ *huffman_prefix = 0x80;
+ return grpc_mdstr_as_base64_encoded_and_huffman_compressed (elem->value);
+ }
/* TODO(ctiller): opportunistically compress non-binary headers */
*huffman_prefix = 0x00;
return elem->value->slice;
}
-static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c,
- gpr_uint32 key_index, grpc_mdelem *elem,
- framer_state *st) {
- gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2);
+static void
+emit_lithdr_incidx (grpc_chttp2_hpack_compressor * c, gpr_uint32 key_index, grpc_mdelem * elem, framer_state * st)
+{
+ gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH (key_index, 2);
gpr_uint8 huffman_prefix;
- gpr_slice value_slice = get_wire_value(elem, &huffman_prefix);
- size_t len_val = GPR_SLICE_LENGTH(value_slice);
+ gpr_slice value_slice = get_wire_value (elem, &huffman_prefix);
+ size_t len_val = GPR_SLICE_LENGTH (value_slice);
gpr_uint32 len_val_len;
- GPR_ASSERT(len_val <= GPR_UINT32_MAX);
- len_val_len = GRPC_CHTTP2_VARINT_LENGTH((gpr_uint32)len_val, 1);
- GRPC_CHTTP2_WRITE_VARINT(key_index, 2, 0x40,
- add_tiny_header_data(st, len_pfx), len_pfx);
- GRPC_CHTTP2_WRITE_VARINT((gpr_uint32)len_val, 1, 0x00,
- add_tiny_header_data(st, len_val_len), len_val_len);
- add_header_data(st, gpr_slice_ref(value_slice));
+ GPR_ASSERT (len_val <= GPR_UINT32_MAX);
+ len_val_len = GRPC_CHTTP2_VARINT_LENGTH ((gpr_uint32) len_val, 1);
+ GRPC_CHTTP2_WRITE_VARINT (key_index, 2, 0x40, add_tiny_header_data (st, len_pfx), len_pfx);
+ GRPC_CHTTP2_WRITE_VARINT ((gpr_uint32) len_val, 1, 0x00, add_tiny_header_data (st, len_val_len), len_val_len);
+ add_header_data (st, gpr_slice_ref (value_slice));
}
-static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c,
- gpr_uint32 key_index, grpc_mdelem *elem,
- framer_state *st) {
- gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4);
+static void
+emit_lithdr_noidx (grpc_chttp2_hpack_compressor * c, gpr_uint32 key_index, grpc_mdelem * elem, framer_state * st)
+{
+ gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH (key_index, 4);
gpr_uint8 huffman_prefix;
- gpr_slice value_slice = get_wire_value(elem, &huffman_prefix);
- size_t len_val = GPR_SLICE_LENGTH(value_slice);
+ gpr_slice value_slice = get_wire_value (elem, &huffman_prefix);
+ size_t len_val = GPR_SLICE_LENGTH (value_slice);
gpr_uint32 len_val_len;
- GPR_ASSERT(len_val <= GPR_UINT32_MAX);
- len_val_len = GRPC_CHTTP2_VARINT_LENGTH((gpr_uint32)len_val, 1);
- GRPC_CHTTP2_WRITE_VARINT(key_index, 4, 0x00,
- add_tiny_header_data(st, len_pfx), len_pfx);
- GRPC_CHTTP2_WRITE_VARINT((gpr_uint32)len_val, 1, 0x00,
- add_tiny_header_data(st, len_val_len), len_val_len);
- add_header_data(st, gpr_slice_ref(value_slice));
+ GPR_ASSERT (len_val <= GPR_UINT32_MAX);
+ len_val_len = GRPC_CHTTP2_VARINT_LENGTH ((gpr_uint32) len_val, 1);
+ GRPC_CHTTP2_WRITE_VARINT (key_index, 4, 0x00, add_tiny_header_data (st, len_pfx), len_pfx);
+ GRPC_CHTTP2_WRITE_VARINT ((gpr_uint32) len_val, 1, 0x00, add_tiny_header_data (st, len_val_len), len_val_len);
+ add_header_data (st, gpr_slice_ref (value_slice));
}
-static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c,
- grpc_mdelem *elem, framer_state *st) {
- gpr_uint32 len_key = (gpr_uint32)GPR_SLICE_LENGTH(elem->key->slice);
+static void
+emit_lithdr_incidx_v (grpc_chttp2_hpack_compressor * c, grpc_mdelem * elem, framer_state * st)
+{
+ gpr_uint32 len_key = (gpr_uint32) GPR_SLICE_LENGTH (elem->key->slice);
gpr_uint8 huffman_prefix;
- gpr_slice value_slice = get_wire_value(elem, &huffman_prefix);
- gpr_uint32 len_val = (gpr_uint32)GPR_SLICE_LENGTH(value_slice);
- gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1);
- gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
- GPR_ASSERT(len_key <= GPR_UINT32_MAX);
- GPR_ASSERT(GPR_SLICE_LENGTH(value_slice) <= GPR_UINT32_MAX);
- *add_tiny_header_data(st, 1) = 0x40;
- GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00,
- add_tiny_header_data(st, len_key_len), len_key_len);
- add_header_data(st, gpr_slice_ref(elem->key->slice));
- GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix,
- add_tiny_header_data(st, len_val_len), len_val_len);
- add_header_data(st, gpr_slice_ref(value_slice));
+ gpr_slice value_slice = get_wire_value (elem, &huffman_prefix);
+ gpr_uint32 len_val = (gpr_uint32) GPR_SLICE_LENGTH (value_slice);
+ gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH (len_key, 1);
+ gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH (len_val, 1);
+ GPR_ASSERT (len_key <= GPR_UINT32_MAX);
+ GPR_ASSERT (GPR_SLICE_LENGTH (value_slice) <= GPR_UINT32_MAX);
+ *add_tiny_header_data (st, 1) = 0x40;
+ GRPC_CHTTP2_WRITE_VARINT (len_key, 1, 0x00, add_tiny_header_data (st, len_key_len), len_key_len);
+ add_header_data (st, gpr_slice_ref (elem->key->slice));
+ GRPC_CHTTP2_WRITE_VARINT (len_val, 1, huffman_prefix, add_tiny_header_data (st, len_val_len), len_val_len);
+ add_header_data (st, gpr_slice_ref (value_slice));
}
-static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c,
- grpc_mdelem *elem, framer_state *st) {
- gpr_uint32 len_key = (gpr_uint32)GPR_SLICE_LENGTH(elem->key->slice);
+static void
+emit_lithdr_noidx_v (grpc_chttp2_hpack_compressor * c, grpc_mdelem * elem, framer_state * st)
+{
+ gpr_uint32 len_key = (gpr_uint32) GPR_SLICE_LENGTH (elem->key->slice);
gpr_uint8 huffman_prefix;
- gpr_slice value_slice = get_wire_value(elem, &huffman_prefix);
- gpr_uint32 len_val = (gpr_uint32)GPR_SLICE_LENGTH(value_slice);
- gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1);
- gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
- GPR_ASSERT(len_key <= GPR_UINT32_MAX);
- GPR_ASSERT(GPR_SLICE_LENGTH(value_slice) <= GPR_UINT32_MAX);
- *add_tiny_header_data(st, 1) = 0x00;
- GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00,
- add_tiny_header_data(st, len_key_len), len_key_len);
- add_header_data(st, gpr_slice_ref(elem->key->slice));
- GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix,
- add_tiny_header_data(st, len_val_len), len_val_len);
- add_header_data(st, gpr_slice_ref(value_slice));
+ gpr_slice value_slice = get_wire_value (elem, &huffman_prefix);
+ gpr_uint32 len_val = (gpr_uint32) GPR_SLICE_LENGTH (value_slice);
+ gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH (len_key, 1);
+ gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH (len_val, 1);
+ GPR_ASSERT (len_key <= GPR_UINT32_MAX);
+ GPR_ASSERT (GPR_SLICE_LENGTH (value_slice) <= GPR_UINT32_MAX);
+ *add_tiny_header_data (st, 1) = 0x00;
+ GRPC_CHTTP2_WRITE_VARINT (len_key, 1, 0x00, add_tiny_header_data (st, len_key_len), len_key_len);
+ add_header_data (st, gpr_slice_ref (elem->key->slice));
+ GRPC_CHTTP2_WRITE_VARINT (len_val, 1, huffman_prefix, add_tiny_header_data (st, len_val_len), len_val_len);
+ add_header_data (st, gpr_slice_ref (value_slice));
}
-static gpr_uint32 dynidx(grpc_chttp2_hpack_compressor *c, gpr_uint32 index) {
- return 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY + c->tail_remote_index +
- c->table_elems - index;
+static gpr_uint32
+dynidx (grpc_chttp2_hpack_compressor * c, gpr_uint32 index)
+{
+ return 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY + c->tail_remote_index + c->table_elems - index;
}
/* encode an mdelem; returns metadata element to unref */
-static grpc_mdelem *hpack_enc(grpc_chttp2_hpack_compressor *c,
- grpc_mdelem *elem, framer_state *st) {
+static grpc_mdelem *
+hpack_enc (grpc_chttp2_hpack_compressor * c, grpc_mdelem * elem, framer_state * st)
+{
gpr_uint32 key_hash = elem->key->hash;
- gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash);
+ gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH (key_hash, elem->value->hash);
size_t decoder_space_usage;
gpr_uint32 indices_key;
int should_add_elem;
- GPR_ASSERT(GPR_SLICE_LENGTH(elem->key->slice) > 0);
- if (GPR_SLICE_START_PTR(elem->key->slice)[0] != ':') { /* regular header */
- st->seen_regular_header = 1;
- } else if (st->seen_regular_header != 0) { /* reserved header */
- gpr_log(GPR_ERROR,
- "Reserved header (colon-prefixed) happening after regular ones.");
- abort();
- }
+ GPR_ASSERT (GPR_SLICE_LENGTH (elem->key->slice) > 0);
+ if (GPR_SLICE_START_PTR (elem->key->slice)[0] != ':')
+ { /* regular header */
+ st->seen_regular_header = 1;
+ }
+ else if (st->seen_regular_header != 0)
+ { /* reserved header */
+ gpr_log (GPR_ERROR, "Reserved header (colon-prefixed) happening after regular ones.");
+ abort ();
+ }
- inc_filter(HASH_FRAGMENT_1(elem_hash), &c->filter_elems_sum, c->filter_elems);
+ inc_filter (HASH_FRAGMENT_1 (elem_hash), &c->filter_elems_sum, c->filter_elems);
/* is this elem currently in the decoders table? */
- if (c->entries_elems[HASH_FRAGMENT_2(elem_hash)] == elem &&
- c->indices_elems[HASH_FRAGMENT_2(elem_hash)] > c->tail_remote_index) {
- /* HIT: complete element (first cuckoo hash) */
- emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_2(elem_hash)]),
- st);
- return elem;
- }
-
- if (c->entries_elems[HASH_FRAGMENT_3(elem_hash)] == elem &&
- c->indices_elems[HASH_FRAGMENT_3(elem_hash)] > c->tail_remote_index) {
- /* HIT: complete element (second cuckoo hash) */
- emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_3(elem_hash)]),
- st);
- return elem;
- }
+ if (c->entries_elems[HASH_FRAGMENT_2 (elem_hash)] == elem && c->indices_elems[HASH_FRAGMENT_2 (elem_hash)] > c->tail_remote_index)
+ {
+ /* HIT: complete element (first cuckoo hash) */
+ emit_indexed (c, dynidx (c, c->indices_elems[HASH_FRAGMENT_2 (elem_hash)]), st);
+ return elem;
+ }
+
+ if (c->entries_elems[HASH_FRAGMENT_3 (elem_hash)] == elem && c->indices_elems[HASH_FRAGMENT_3 (elem_hash)] > c->tail_remote_index)
+ {
+ /* HIT: complete element (second cuckoo hash) */
+ emit_indexed (c, dynidx (c, c->indices_elems[HASH_FRAGMENT_3 (elem_hash)]), st);
+ return elem;
+ }
/* should this elem be in the table? */
- decoder_space_usage = 32 + GPR_SLICE_LENGTH(elem->key->slice) +
- GPR_SLICE_LENGTH(elem->value->slice);
- should_add_elem = decoder_space_usage < MAX_DECODER_SPACE_USAGE &&
- c->filter_elems[HASH_FRAGMENT_1(elem_hash)] >=
- c->filter_elems_sum / ONE_ON_ADD_PROBABILITY;
+ decoder_space_usage = 32 + GPR_SLICE_LENGTH (elem->key->slice) + GPR_SLICE_LENGTH (elem->value->slice);
+ should_add_elem = decoder_space_usage < MAX_DECODER_SPACE_USAGE && c->filter_elems[HASH_FRAGMENT_1 (elem_hash)] >= c->filter_elems_sum / ONE_ON_ADD_PROBABILITY;
/* no hits for the elem... maybe there's a key? */
- indices_key = c->indices_keys[HASH_FRAGMENT_2(key_hash)];
- if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == elem->key &&
- indices_key > c->tail_remote_index) {
- /* HIT: key (first cuckoo hash) */
- if (should_add_elem) {
- emit_lithdr_incidx(c, dynidx(c, indices_key), elem, st);
- return add_elem(c, elem);
- } else {
- emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st);
- return elem;
+ indices_key = c->indices_keys[HASH_FRAGMENT_2 (key_hash)];
+ if (c->entries_keys[HASH_FRAGMENT_2 (key_hash)] == elem->key && indices_key > c->tail_remote_index)
+ {
+ /* HIT: key (first cuckoo hash) */
+ if (should_add_elem)
+ {
+ emit_lithdr_incidx (c, dynidx (c, indices_key), elem, st);
+ return add_elem (c, elem);
+ }
+ else
+ {
+ emit_lithdr_noidx (c, dynidx (c, indices_key), elem, st);
+ return elem;
+ }
+ abort ();
}
- abort();
- }
-
- indices_key = c->indices_keys[HASH_FRAGMENT_3(key_hash)];
- if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == elem->key &&
- indices_key > c->tail_remote_index) {
- /* HIT: key (first cuckoo hash) */
- if (should_add_elem) {
- emit_lithdr_incidx(c, dynidx(c, indices_key), elem, st);
- return add_elem(c, elem);
- } else {
- emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st);
- return elem;
+
+ indices_key = c->indices_keys[HASH_FRAGMENT_3 (key_hash)];
+ if (c->entries_keys[HASH_FRAGMENT_3 (key_hash)] == elem->key && indices_key > c->tail_remote_index)
+ {
+ /* HIT: key (first cuckoo hash) */
+ if (should_add_elem)
+ {
+ emit_lithdr_incidx (c, dynidx (c, indices_key), elem, st);
+ return add_elem (c, elem);
+ }
+ else
+ {
+ emit_lithdr_noidx (c, dynidx (c, indices_key), elem, st);
+ return elem;
+ }
+ abort ();
}
- abort();
- }
/* no elem, key in the table... fall back to literal emission */
- if (should_add_elem) {
- emit_lithdr_incidx_v(c, elem, st);
- return add_elem(c, elem);
- } else {
- emit_lithdr_noidx_v(c, elem, st);
- return elem;
- }
- abort();
+ if (should_add_elem)
+ {
+ emit_lithdr_incidx_v (c, elem, st);
+ return add_elem (c, elem);
+ }
+ else
+ {
+ emit_lithdr_noidx_v (c, elem, st);
+ return elem;
+ }
+ abort ();
}
#define STRLEN_LIT(x) (sizeof(x) - 1)
#define TIMEOUT_KEY "grpc-timeout"
-static void deadline_enc(grpc_chttp2_hpack_compressor *c, gpr_timespec deadline,
- framer_state *st) {
+static void
+deadline_enc (grpc_chttp2_hpack_compressor * c, gpr_timespec deadline, framer_state * st)
+{
char timeout_str[GRPC_CHTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE];
grpc_mdelem *mdelem;
- grpc_chttp2_encode_timeout(
- gpr_time_sub(deadline, gpr_now(deadline.clock_type)), timeout_str);
- mdelem = grpc_mdelem_from_metadata_strings(
- c->mdctx, GRPC_MDSTR_REF(c->timeout_key_str),
- grpc_mdstr_from_string(c->mdctx, timeout_str, 0));
- mdelem = hpack_enc(c, mdelem, st);
- if (mdelem) GRPC_MDELEM_UNREF(mdelem);
+ grpc_chttp2_encode_timeout (gpr_time_sub (deadline, gpr_now (deadline.clock_type)), timeout_str);
+ mdelem = grpc_mdelem_from_metadata_strings (c->mdctx, GRPC_MDSTR_REF (c->timeout_key_str), grpc_mdstr_from_string (c->mdctx, timeout_str, 0));
+ mdelem = hpack_enc (c, mdelem, st);
+ if (mdelem)
+ GRPC_MDELEM_UNREF (mdelem);
}
-gpr_slice grpc_chttp2_data_frame_create_empty_close(gpr_uint32 id) {
- gpr_slice slice = gpr_slice_malloc(9);
- fill_header(GPR_SLICE_START_PTR(slice), GRPC_CHTTP2_FRAME_DATA, id, 0, 1);
+gpr_slice
+grpc_chttp2_data_frame_create_empty_close (gpr_uint32 id)
+{
+ gpr_slice slice = gpr_slice_malloc (9);
+ fill_header (GPR_SLICE_START_PTR (slice), GRPC_CHTTP2_FRAME_DATA, id, 0, 1);
return slice;
}
-void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c,
- grpc_mdctx *ctx) {
- memset(c, 0, sizeof(*c));
+void
+grpc_chttp2_hpack_compressor_init (grpc_chttp2_hpack_compressor * c, grpc_mdctx * ctx)
+{
+ memset (c, 0, sizeof (*c));
c->mdctx = ctx;
- c->timeout_key_str = grpc_mdstr_from_string(ctx, "grpc-timeout", 0);
+ c->timeout_key_str = grpc_mdstr_from_string (ctx, "grpc-timeout", 0);
}
-void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c) {
+void
+grpc_chttp2_hpack_compressor_destroy (grpc_chttp2_hpack_compressor * c)
+{
int i;
- for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++) {
- if (c->entries_keys[i]) GRPC_MDSTR_UNREF(c->entries_keys[i]);
- if (c->entries_elems[i]) GRPC_MDELEM_UNREF(c->entries_elems[i]);
- }
- GRPC_MDSTR_UNREF(c->timeout_key_str);
+ for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++)
+ {
+ if (c->entries_keys[i])
+ GRPC_MDSTR_UNREF (c->entries_keys[i]);
+ if (c->entries_elems[i])
+ GRPC_MDELEM_UNREF (c->entries_elems[i]);
+ }
+ GRPC_MDSTR_UNREF (c->timeout_key_str);
}
-gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count,
- gpr_uint32 max_flow_controlled_bytes,
- grpc_stream_op_buffer *outops) {
+gpr_uint32
+grpc_chttp2_preencode (grpc_stream_op * inops, size_t * inops_count, gpr_uint32 max_flow_controlled_bytes, grpc_stream_op_buffer * outops)
+{
gpr_slice slice;
grpc_stream_op *op;
gpr_uint32 max_take_size;
@@ -504,78 +546,85 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count,
gpr_uint8 *p;
gpr_uint8 compressed_flag_set = 0;
- while (curop < *inops_count) {
- GPR_ASSERT(flow_controlled_bytes_taken <= max_flow_controlled_bytes);
- op = &inops[curop];
- switch (op->type) {
- case GRPC_NO_OP:
- /* skip */
- curop++;
- break;
- case GRPC_OP_METADATA:
- grpc_metadata_batch_assert_ok(&op->data.metadata);
- /* these just get copied as they don't impact the number of flow
- controlled bytes */
- grpc_sopb_append(outops, op, 1);
- curop++;
- break;
- case GRPC_OP_BEGIN_MESSAGE:
- /* begin op: for now we just convert the op to a slice and fall
- through - this lets us reuse the slice framing code below */
- compressed_flag_set =
- (op->data.begin_message.flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0;
- slice = gpr_slice_malloc(5);
-
- p = GPR_SLICE_START_PTR(slice);
- p[0] = compressed_flag_set;
- p[1] = (gpr_uint8)(op->data.begin_message.length >> 24);
- p[2] = (gpr_uint8)(op->data.begin_message.length >> 16);
- p[3] = (gpr_uint8)(op->data.begin_message.length >> 8);
- p[4] = (gpr_uint8)(op->data.begin_message.length);
- op->type = GRPC_OP_SLICE;
- op->data.slice = slice;
- /* fallthrough */
- case GRPC_OP_SLICE:
- slice = op->data.slice;
- if (!GPR_SLICE_LENGTH(slice)) {
- /* skip zero length slices */
- gpr_slice_unref(slice);
- curop++;
- break;
- }
- max_take_size = max_flow_controlled_bytes - flow_controlled_bytes_taken;
- if (max_take_size == 0) {
- goto exit_loop;
- }
- if (GPR_SLICE_LENGTH(slice) > max_take_size) {
- slice = gpr_slice_split_head(&op->data.slice, max_take_size);
- grpc_sopb_add_slice(outops, slice);
- } else {
- /* consume this op immediately */
- grpc_sopb_append(outops, op, 1);
- curop++;
- }
- flow_controlled_bytes_taken += (gpr_uint32)GPR_SLICE_LENGTH(slice);
- break;
- }
- }
+ while (curop < *inops_count)
+ {
+ GPR_ASSERT (flow_controlled_bytes_taken <= max_flow_controlled_bytes);
+ op = &inops[curop];
+ switch (op->type)
+ {
+ case GRPC_NO_OP:
+ /* skip */
+ curop++;
+ break;
+ case GRPC_OP_METADATA:
+ grpc_metadata_batch_assert_ok (&op->data.metadata);
+ /* these just get copied as they don't impact the number of flow
+ controlled bytes */
+ grpc_sopb_append (outops, op, 1);
+ curop++;
+ break;
+ case GRPC_OP_BEGIN_MESSAGE:
+ /* begin op: for now we just convert the op to a slice and fall
+ through - this lets us reuse the slice framing code below */
+ compressed_flag_set = (op->data.begin_message.flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0;
+ slice = gpr_slice_malloc (5);
+
+ p = GPR_SLICE_START_PTR (slice);
+ p[0] = compressed_flag_set;
+ p[1] = (gpr_uint8) (op->data.begin_message.length >> 24);
+ p[2] = (gpr_uint8) (op->data.begin_message.length >> 16);
+ p[3] = (gpr_uint8) (op->data.begin_message.length >> 8);
+ p[4] = (gpr_uint8) (op->data.begin_message.length);
+ op->type = GRPC_OP_SLICE;
+ op->data.slice = slice;
+ /* fallthrough */
+ case GRPC_OP_SLICE:
+ slice = op->data.slice;
+ if (!GPR_SLICE_LENGTH (slice))
+ {
+ /* skip zero length slices */
+ gpr_slice_unref (slice);
+ curop++;
+ break;
+ }
+ max_take_size = max_flow_controlled_bytes - flow_controlled_bytes_taken;
+ if (max_take_size == 0)
+ {
+ goto exit_loop;
+ }
+ if (GPR_SLICE_LENGTH (slice) > max_take_size)
+ {
+ slice = gpr_slice_split_head (&op->data.slice, max_take_size);
+ grpc_sopb_add_slice (outops, slice);
+ }
+ else
+ {
+ /* consume this op immediately */
+ grpc_sopb_append (outops, op, 1);
+ curop++;
+ }
+ flow_controlled_bytes_taken += (gpr_uint32) GPR_SLICE_LENGTH (slice);
+ break;
+ }
+ }
exit_loop:
*inops_count -= curop;
- memmove(inops, inops + curop, *inops_count * sizeof(grpc_stream_op));
-
- for (curop = 0; curop < *inops_count; curop++) {
- if (inops[curop].type == GRPC_OP_METADATA) {
- grpc_metadata_batch_assert_ok(&inops[curop].data.metadata);
+ memmove (inops, inops + curop, *inops_count * sizeof (grpc_stream_op));
+
+ for (curop = 0; curop < *inops_count; curop++)
+ {
+ if (inops[curop].type == GRPC_OP_METADATA)
+ {
+ grpc_metadata_batch_assert_ok (&inops[curop].data.metadata);
+ }
}
- }
return flow_controlled_bytes_taken;
}
-void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof,
- gpr_uint32 stream_id,
- grpc_chttp2_hpack_compressor *compressor,
- gpr_slice_buffer *output) {
+void
+grpc_chttp2_encode (grpc_stream_op * ops, size_t ops_count, int eof, gpr_uint32 stream_id, grpc_chttp2_hpack_compressor * compressor, gpr_slice_buffer * output)
+{
framer_state st;
gpr_slice slice;
grpc_stream_op *op;
@@ -587,7 +636,7 @@ void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof,
int need_unref = 0;
gpr_timespec deadline;
- GPR_ASSERT(stream_id != 0);
+ GPR_ASSERT (stream_id != 0);
st.cur_frame_type = NONE;
st.last_was_header = 0;
@@ -595,70 +644,80 @@ void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof,
st.stream_id = stream_id;
st.output = output;
- while (curop < ops_count) {
- op = &ops[curop];
- switch (op->type) {
- case GRPC_NO_OP:
- case GRPC_OP_BEGIN_MESSAGE:
- gpr_log(
- GPR_ERROR,
- "These stream ops should be filtered out by grpc_chttp2_preencode");
- abort();
- case GRPC_OP_METADATA:
- /* Encode a metadata batch; store the returned values, representing
- a metadata element that needs to be unreffed back into the metadata
- slot. THIS MAY NOT BE THE SAME ELEMENT (if a decoder table slot got
- updated). After this loop, we'll do a batch unref of elements. */
- begin_new_frame(&st, HEADER);
- need_unref |= op->data.metadata.garbage.head != NULL;
- grpc_metadata_batch_assert_ok(&op->data.metadata);
- for (l = op->data.metadata.list.head; l; l = l->next) {
- l->md = hpack_enc(compressor, l->md, &st);
- need_unref |= l->md != NULL;
- }
- deadline = op->data.metadata.deadline;
- if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) != 0) {
- deadline_enc(compressor, deadline, &st);
- }
- curop++;
- break;
- case GRPC_OP_SLICE:
- slice = op->data.slice;
- if (st.cur_frame_type == DATA &&
- st.output->length - st.output_length_at_start_of_frame ==
- GRPC_CHTTP2_MAX_PAYLOAD_LENGTH) {
- finish_frame(&st, 0, 0);
- }
- ensure_frame_type(&st, DATA, 1);
- max_take_size = GRPC_CHTTP2_MAX_PAYLOAD_LENGTH +
- st.output_length_at_start_of_frame - st.output->length;
- if (GPR_SLICE_LENGTH(slice) > max_take_size) {
- slice = gpr_slice_split_head(&op->data.slice, max_take_size);
- } else {
- /* consume this op immediately */
- curop++;
- }
- gpr_slice_buffer_add(output, slice);
- break;
- }
- }
- if (eof && st.cur_frame_type == NONE) {
- begin_frame(&st, DATA);
- }
- finish_frame(&st, 1, eof);
-
- if (need_unref) {
- grpc_mdctx_lock(mdctx);
- for (unref_op = 0; unref_op < curop; unref_op++) {
- op = &ops[unref_op];
- if (op->type != GRPC_OP_METADATA) continue;
- for (l = op->data.metadata.list.head; l; l = l->next) {
- if (l->md) GRPC_MDCTX_LOCKED_MDELEM_UNREF(mdctx, l->md);
- }
- for (l = op->data.metadata.garbage.head; l; l = l->next) {
- GRPC_MDCTX_LOCKED_MDELEM_UNREF(mdctx, l->md);
- }
- }
- grpc_mdctx_unlock(mdctx);
- }
+ while (curop < ops_count)
+ {
+ op = &ops[curop];
+ switch (op->type)
+ {
+ case GRPC_NO_OP:
+ case GRPC_OP_BEGIN_MESSAGE:
+ gpr_log (GPR_ERROR, "These stream ops should be filtered out by grpc_chttp2_preencode");
+ abort ();
+ case GRPC_OP_METADATA:
+ /* Encode a metadata batch; store the returned values, representing
+ a metadata element that needs to be unreffed back into the metadata
+ slot. THIS MAY NOT BE THE SAME ELEMENT (if a decoder table slot got
+ updated). After this loop, we'll do a batch unref of elements. */
+ begin_new_frame (&st, HEADER);
+ need_unref |= op->data.metadata.garbage.head != NULL;
+ grpc_metadata_batch_assert_ok (&op->data.metadata);
+ for (l = op->data.metadata.list.head; l; l = l->next)
+ {
+ l->md = hpack_enc (compressor, l->md, &st);
+ need_unref |= l->md != NULL;
+ }
+ deadline = op->data.metadata.deadline;
+ if (gpr_time_cmp (deadline, gpr_inf_future (deadline.clock_type)) != 0)
+ {
+ deadline_enc (compressor, deadline, &st);
+ }
+ curop++;
+ break;
+ case GRPC_OP_SLICE:
+ slice = op->data.slice;
+ if (st.cur_frame_type == DATA && st.output->length - st.output_length_at_start_of_frame == GRPC_CHTTP2_MAX_PAYLOAD_LENGTH)
+ {
+ finish_frame (&st, 0, 0);
+ }
+ ensure_frame_type (&st, DATA, 1);
+ max_take_size = GRPC_CHTTP2_MAX_PAYLOAD_LENGTH + st.output_length_at_start_of_frame - st.output->length;
+ if (GPR_SLICE_LENGTH (slice) > max_take_size)
+ {
+ slice = gpr_slice_split_head (&op->data.slice, max_take_size);
+ }
+ else
+ {
+ /* consume this op immediately */
+ curop++;
+ }
+ gpr_slice_buffer_add (output, slice);
+ break;
+ }
+ }
+ if (eof && st.cur_frame_type == NONE)
+ {
+ begin_frame (&st, DATA);
+ }
+ finish_frame (&st, 1, eof);
+
+ if (need_unref)
+ {
+ grpc_mdctx_lock (mdctx);
+ for (unref_op = 0; unref_op < curop; unref_op++)
+ {
+ op = &ops[unref_op];
+ if (op->type != GRPC_OP_METADATA)
+ continue;
+ for (l = op->data.metadata.list.head; l; l = l->next)
+ {
+ if (l->md)
+ GRPC_MDCTX_LOCKED_MDELEM_UNREF (mdctx, l->md);
+ }
+ for (l = op->data.metadata.garbage.head; l; l = l->next)
+ {
+ GRPC_MDCTX_LOCKED_MDELEM_UNREF (mdctx, l->md);
+ }
+ }
+ grpc_mdctx_unlock (mdctx);
+ }
}
diff --git a/src/core/transport/chttp2/stream_encoder.h b/src/core/transport/chttp2/stream_encoder.h
index db52f2a0f6..32f003d000 100644
--- a/src/core/transport/chttp2/stream_encoder.h
+++ b/src/core/transport/chttp2/stream_encoder.h
@@ -45,7 +45,8 @@
#define GRPC_CHTTP2_HPACKC_NUM_VALUES 256
#define GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS (4096 / 32)
-typedef struct {
+typedef struct
+{
gpr_uint32 filter_elems_sum;
/* one before the lowest usable table index */
gpr_uint32 tail_remote_index;
@@ -74,20 +75,14 @@ typedef struct {
gpr_uint16 table_elem_size[GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS];
} grpc_chttp2_hpack_compressor;
-void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c,
- grpc_mdctx *mdctx);
-void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c);
+void grpc_chttp2_hpack_compressor_init (grpc_chttp2_hpack_compressor * c, grpc_mdctx * mdctx);
+void grpc_chttp2_hpack_compressor_destroy (grpc_chttp2_hpack_compressor * c);
/* select stream ops to be encoded, moving them from inops to outops, and
moving subsequent ops in inops forward in the queue */
-gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count,
- gpr_uint32 max_flow_controlled_bytes,
- grpc_stream_op_buffer *outops);
+gpr_uint32 grpc_chttp2_preencode (grpc_stream_op * inops, size_t * inops_count, gpr_uint32 max_flow_controlled_bytes, grpc_stream_op_buffer * outops);
/* encode stream ops to output */
-void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof,
- gpr_uint32 stream_id,
- grpc_chttp2_hpack_compressor *compressor,
- gpr_slice_buffer *output);
+void grpc_chttp2_encode (grpc_stream_op * ops, size_t ops_count, int eof, gpr_uint32 stream_id, grpc_chttp2_hpack_compressor * compressor, gpr_slice_buffer * output);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_STREAM_ENCODER_H */
diff --git a/src/core/transport/chttp2/stream_lists.c b/src/core/transport/chttp2/stream_lists.c
index 781db7b0d6..43d7b0b39f 100644
--- a/src/core/transport/chttp2/stream_lists.c
+++ b/src/core/transport/chttp2/stream_lists.c
@@ -58,346 +58,348 @@
/* core list management */
-static int stream_list_empty(grpc_chttp2_transport *t,
- grpc_chttp2_stream_list_id id) {
+static int
+stream_list_empty (grpc_chttp2_transport * t, grpc_chttp2_stream_list_id id)
+{
return t->lists[id].head == NULL;
}
-static int stream_list_pop(grpc_chttp2_transport *t,
- grpc_chttp2_stream **stream,
- grpc_chttp2_stream_list_id id) {
+static int
+stream_list_pop (grpc_chttp2_transport * t, grpc_chttp2_stream ** stream, grpc_chttp2_stream_list_id id)
+{
grpc_chttp2_stream *s = t->lists[id].head;
- if (s) {
- grpc_chttp2_stream *new_head = s->links[id].next;
- GPR_ASSERT(s->included[id]);
- if (new_head) {
- t->lists[id].head = new_head;
- new_head->links[id].prev = NULL;
- } else {
- t->lists[id].head = NULL;
- t->lists[id].tail = NULL;
+ if (s)
+ {
+ grpc_chttp2_stream *new_head = s->links[id].next;
+ GPR_ASSERT (s->included[id]);
+ if (new_head)
+ {
+ t->lists[id].head = new_head;
+ new_head->links[id].prev = NULL;
+ }
+ else
+ {
+ t->lists[id].head = NULL;
+ t->lists[id].tail = NULL;
+ }
+ s->included[id] = 0;
}
- s->included[id] = 0;
- }
*stream = s;
return s != 0;
}
-static void stream_list_remove(grpc_chttp2_transport *t, grpc_chttp2_stream *s,
- grpc_chttp2_stream_list_id id) {
- GPR_ASSERT(s->included[id]);
+static void
+stream_list_remove (grpc_chttp2_transport * t, grpc_chttp2_stream * s, grpc_chttp2_stream_list_id id)
+{
+ GPR_ASSERT (s->included[id]);
s->included[id] = 0;
- if (s->links[id].prev) {
- s->links[id].prev->links[id].next = s->links[id].next;
- } else {
- GPR_ASSERT(t->lists[id].head == s);
- t->lists[id].head = s->links[id].next;
- }
- if (s->links[id].next) {
- s->links[id].next->links[id].prev = s->links[id].prev;
- } else {
- t->lists[id].tail = s->links[id].prev;
- }
-}
-
-static void stream_list_maybe_remove(grpc_chttp2_transport *t,
- grpc_chttp2_stream *s,
- grpc_chttp2_stream_list_id id) {
- if (s->included[id]) {
- stream_list_remove(t, s, id);
- }
-}
-
-static void stream_list_add_head(grpc_chttp2_transport *t,
- grpc_chttp2_stream *s,
- grpc_chttp2_stream_list_id id) {
+ if (s->links[id].prev)
+ {
+ s->links[id].prev->links[id].next = s->links[id].next;
+ }
+ else
+ {
+ GPR_ASSERT (t->lists[id].head == s);
+ t->lists[id].head = s->links[id].next;
+ }
+ if (s->links[id].next)
+ {
+ s->links[id].next->links[id].prev = s->links[id].prev;
+ }
+ else
+ {
+ t->lists[id].tail = s->links[id].prev;
+ }
+}
+
+static void
+stream_list_maybe_remove (grpc_chttp2_transport * t, grpc_chttp2_stream * s, grpc_chttp2_stream_list_id id)
+{
+ if (s->included[id])
+ {
+ stream_list_remove (t, s, id);
+ }
+}
+
+static void
+stream_list_add_head (grpc_chttp2_transport * t, grpc_chttp2_stream * s, grpc_chttp2_stream_list_id id)
+{
grpc_chttp2_stream *old_head;
- GPR_ASSERT(!s->included[id]);
+ GPR_ASSERT (!s->included[id]);
old_head = t->lists[id].head;
s->links[id].next = old_head;
s->links[id].prev = NULL;
- if (old_head) {
- old_head->links[id].prev = s;
- } else {
- t->lists[id].tail = s;
- }
+ if (old_head)
+ {
+ old_head->links[id].prev = s;
+ }
+ else
+ {
+ t->lists[id].tail = s;
+ }
t->lists[id].head = s;
s->included[id] = 1;
}
-static void stream_list_add_tail(grpc_chttp2_transport *t,
- grpc_chttp2_stream *s,
- grpc_chttp2_stream_list_id id) {
+static void
+stream_list_add_tail (grpc_chttp2_transport * t, grpc_chttp2_stream * s, grpc_chttp2_stream_list_id id)
+{
grpc_chttp2_stream *old_tail;
- GPR_ASSERT(!s->included[id]);
+ GPR_ASSERT (!s->included[id]);
old_tail = t->lists[id].tail;
s->links[id].next = NULL;
s->links[id].prev = old_tail;
- if (old_tail) {
- old_tail->links[id].next = s;
- } else {
- t->lists[id].head = s;
- }
+ if (old_tail)
+ {
+ old_tail->links[id].next = s;
+ }
+ else
+ {
+ t->lists[id].head = s;
+ }
t->lists[id].tail = s;
s->included[id] = 1;
}
-static void stream_list_add(grpc_chttp2_transport *t, grpc_chttp2_stream *s,
- grpc_chttp2_stream_list_id id) {
- if (s->included[id]) {
- return;
- }
- stream_list_add_tail(t, s, id);
+static void
+stream_list_add (grpc_chttp2_transport * t, grpc_chttp2_stream * s, grpc_chttp2_stream_list_id id)
+{
+ if (s->included[id])
+ {
+ return;
+ }
+ stream_list_add_tail (t, s, id);
}
/* wrappers for specializations */
-void grpc_chttp2_list_add_writable_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global) {
- GPR_ASSERT(stream_global->id != 0);
- stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
- STREAM_FROM_GLOBAL(stream_global), GRPC_CHTTP2_LIST_WRITABLE);
+void
+grpc_chttp2_list_add_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global)
+{
+ GPR_ASSERT (stream_global->id != 0);
+ stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_WRITABLE);
}
-void grpc_chttp2_list_add_first_writable_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global) {
- GPR_ASSERT(stream_global->id != 0);
- stream_list_add_head(TRANSPORT_FROM_GLOBAL(transport_global),
- STREAM_FROM_GLOBAL(stream_global),
- GRPC_CHTTP2_LIST_WRITABLE);
+void
+grpc_chttp2_list_add_first_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global)
+{
+ GPR_ASSERT (stream_global->id != 0);
+ stream_list_add_head (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_WRITABLE);
}
-int grpc_chttp2_list_pop_writable_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_writing *transport_writing,
- grpc_chttp2_stream_global **stream_global,
- grpc_chttp2_stream_writing **stream_writing) {
+int
+grpc_chttp2_list_pop_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_writing ** stream_writing)
+{
grpc_chttp2_stream *stream;
- int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
- GRPC_CHTTP2_LIST_WRITABLE);
- if (r != 0) {
- *stream_global = &stream->global;
- *stream_writing = &stream->writing;
- }
+ int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream,
+ GRPC_CHTTP2_LIST_WRITABLE);
+ if (r != 0)
+ {
+ *stream_global = &stream->global;
+ *stream_writing = &stream->writing;
+ }
return r;
}
-void grpc_chttp2_list_remove_writable_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global) {
- stream_list_maybe_remove(TRANSPORT_FROM_GLOBAL(transport_global),
- STREAM_FROM_GLOBAL(stream_global),
- GRPC_CHTTP2_LIST_WRITABLE);
+void
+grpc_chttp2_list_remove_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global)
+{
+ stream_list_maybe_remove (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_WRITABLE);
}
-void grpc_chttp2_list_add_writing_stream(
- grpc_chttp2_transport_writing *transport_writing,
- grpc_chttp2_stream_writing *stream_writing) {
- stream_list_add(TRANSPORT_FROM_WRITING(transport_writing),
- STREAM_FROM_WRITING(stream_writing),
- GRPC_CHTTP2_LIST_WRITING);
+void
+grpc_chttp2_list_add_writing_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing * stream_writing)
+{
+ stream_list_add (TRANSPORT_FROM_WRITING (transport_writing), STREAM_FROM_WRITING (stream_writing), GRPC_CHTTP2_LIST_WRITING);
}
-int grpc_chttp2_list_have_writing_streams(
- grpc_chttp2_transport_writing *transport_writing) {
- return !stream_list_empty(TRANSPORT_FROM_WRITING(transport_writing),
- GRPC_CHTTP2_LIST_WRITING);
+int
+grpc_chttp2_list_have_writing_streams (grpc_chttp2_transport_writing * transport_writing)
+{
+ return !stream_list_empty (TRANSPORT_FROM_WRITING (transport_writing), GRPC_CHTTP2_LIST_WRITING);
}
-int grpc_chttp2_list_pop_writing_stream(
- grpc_chttp2_transport_writing *transport_writing,
- grpc_chttp2_stream_writing **stream_writing) {
+int
+grpc_chttp2_list_pop_writing_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing ** stream_writing)
+{
grpc_chttp2_stream *stream;
- int r = stream_list_pop(TRANSPORT_FROM_WRITING(transport_writing), &stream,
- GRPC_CHTTP2_LIST_WRITING);
- if (r != 0) {
- *stream_writing = &stream->writing;
- }
+ int r = stream_list_pop (TRANSPORT_FROM_WRITING (transport_writing), &stream,
+ GRPC_CHTTP2_LIST_WRITING);
+ if (r != 0)
+ {
+ *stream_writing = &stream->writing;
+ }
return r;
}
-void grpc_chttp2_list_add_written_stream(
- grpc_chttp2_transport_writing *transport_writing,
- grpc_chttp2_stream_writing *stream_writing) {
- stream_list_add(TRANSPORT_FROM_WRITING(transport_writing),
- STREAM_FROM_WRITING(stream_writing),
- GRPC_CHTTP2_LIST_WRITTEN);
+void
+grpc_chttp2_list_add_written_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing * stream_writing)
+{
+ stream_list_add (TRANSPORT_FROM_WRITING (transport_writing), STREAM_FROM_WRITING (stream_writing), GRPC_CHTTP2_LIST_WRITTEN);
}
-int grpc_chttp2_list_pop_written_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_writing *transport_writing,
- grpc_chttp2_stream_global **stream_global,
- grpc_chttp2_stream_writing **stream_writing) {
+int
+grpc_chttp2_list_pop_written_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_writing ** stream_writing)
+{
grpc_chttp2_stream *stream;
- int r = stream_list_pop(TRANSPORT_FROM_WRITING(transport_writing), &stream,
- GRPC_CHTTP2_LIST_WRITTEN);
- if (r != 0) {
- *stream_global = &stream->global;
- *stream_writing = &stream->writing;
- }
+ int r = stream_list_pop (TRANSPORT_FROM_WRITING (transport_writing), &stream,
+ GRPC_CHTTP2_LIST_WRITTEN);
+ if (r != 0)
+ {
+ *stream_global = &stream->global;
+ *stream_writing = &stream->writing;
+ }
return r;
}
-void grpc_chttp2_list_add_parsing_seen_stream(
- grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_parsing *stream_parsing) {
- stream_list_add(TRANSPORT_FROM_PARSING(transport_parsing),
- STREAM_FROM_PARSING(stream_parsing),
- GRPC_CHTTP2_LIST_PARSING_SEEN);
+void
+grpc_chttp2_list_add_parsing_seen_stream (grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing)
+{
+ stream_list_add (TRANSPORT_FROM_PARSING (transport_parsing), STREAM_FROM_PARSING (stream_parsing), GRPC_CHTTP2_LIST_PARSING_SEEN);
}
-int grpc_chttp2_list_pop_parsing_seen_stream(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_global **stream_global,
- grpc_chttp2_stream_parsing **stream_parsing) {
+int
+grpc_chttp2_list_pop_parsing_seen_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_parsing ** stream_parsing)
+{
grpc_chttp2_stream *stream;
- int r = stream_list_pop(TRANSPORT_FROM_PARSING(transport_parsing), &stream,
- GRPC_CHTTP2_LIST_PARSING_SEEN);
- if (r != 0) {
- *stream_global = &stream->global;
- *stream_parsing = &stream->parsing;
- }
+ int r = stream_list_pop (TRANSPORT_FROM_PARSING (transport_parsing), &stream,
+ GRPC_CHTTP2_LIST_PARSING_SEEN);
+ if (r != 0)
+ {
+ *stream_global = &stream->global;
+ *stream_parsing = &stream->parsing;
+ }
return r;
}
-void grpc_chttp2_list_add_waiting_for_concurrency(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global) {
- stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
- STREAM_FROM_GLOBAL(stream_global),
- GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY);
+void
+grpc_chttp2_list_add_waiting_for_concurrency (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global)
+{
+ stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY);
}
-int grpc_chttp2_list_pop_waiting_for_concurrency(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global **stream_global) {
+int
+grpc_chttp2_list_pop_waiting_for_concurrency (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global)
+{
grpc_chttp2_stream *stream;
- int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
- GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY);
- if (r != 0) {
- *stream_global = &stream->global;
- }
+ int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream,
+ GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY);
+ if (r != 0)
+ {
+ *stream_global = &stream->global;
+ }
return r;
}
-void grpc_chttp2_list_add_closed_waiting_for_parsing(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global) {
- stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
- STREAM_FROM_GLOBAL(stream_global),
- GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING);
+void
+grpc_chttp2_list_add_closed_waiting_for_parsing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global)
+{
+ stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING);
}
-int grpc_chttp2_list_pop_closed_waiting_for_parsing(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global **stream_global) {
+int
+grpc_chttp2_list_pop_closed_waiting_for_parsing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global)
+{
grpc_chttp2_stream *stream;
- int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
- GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING);
- if (r != 0) {
- *stream_global = &stream->global;
- }
+ int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream,
+ GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING);
+ if (r != 0)
+ {
+ *stream_global = &stream->global;
+ }
return r;
}
-void grpc_chttp2_list_add_cancelled_waiting_for_writing(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global) {
- stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
- STREAM_FROM_GLOBAL(stream_global),
- GRPC_CHTTP2_LIST_CANCELLED_WAITING_FOR_WRITING);
+void
+grpc_chttp2_list_add_cancelled_waiting_for_writing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global)
+{
+ stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_CANCELLED_WAITING_FOR_WRITING);
}
-int grpc_chttp2_list_pop_cancelled_waiting_for_writing(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global **stream_global) {
+int
+grpc_chttp2_list_pop_cancelled_waiting_for_writing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global)
+{
grpc_chttp2_stream *stream;
- int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
- GRPC_CHTTP2_LIST_CANCELLED_WAITING_FOR_WRITING);
- if (r != 0) {
- *stream_global = &stream->global;
- }
+ int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream,
+ GRPC_CHTTP2_LIST_CANCELLED_WAITING_FOR_WRITING);
+ if (r != 0)
+ {
+ *stream_global = &stream->global;
+ }
return r;
}
-void grpc_chttp2_list_add_incoming_window_updated(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global) {
- stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
- STREAM_FROM_GLOBAL(stream_global),
- GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED);
+void
+grpc_chttp2_list_add_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global)
+{
+ stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED);
}
-int grpc_chttp2_list_pop_incoming_window_updated(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_parsing *transport_parsing,
- grpc_chttp2_stream_global **stream_global,
- grpc_chttp2_stream_parsing **stream_parsing) {
+int
+grpc_chttp2_list_pop_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_parsing ** stream_parsing)
+{
grpc_chttp2_stream *stream;
- int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
- GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED);
- if (r != 0) {
- *stream_global = &stream->global;
- *stream_parsing = &stream->parsing;
- }
+ int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream,
+ GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED);
+ if (r != 0)
+ {
+ *stream_global = &stream->global;
+ *stream_parsing = &stream->parsing;
+ }
return r;
}
-void grpc_chttp2_list_remove_incoming_window_updated(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global) {
- stream_list_maybe_remove(TRANSPORT_FROM_GLOBAL(transport_global),
- STREAM_FROM_GLOBAL(stream_global),
- GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED);
+void
+grpc_chttp2_list_remove_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global)
+{
+ stream_list_maybe_remove (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED);
}
-void grpc_chttp2_list_add_read_write_state_changed(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global) {
- stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
- STREAM_FROM_GLOBAL(stream_global),
- GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED);
+void
+grpc_chttp2_list_add_read_write_state_changed (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global)
+{
+ stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED);
}
-int grpc_chttp2_list_pop_read_write_state_changed(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global **stream_global) {
+int
+grpc_chttp2_list_pop_read_write_state_changed (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global)
+{
grpc_chttp2_stream *stream;
- int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
- GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED);
- if (r != 0) {
- *stream_global = &stream->global;
- }
+ int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream,
+ GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED);
+ if (r != 0)
+ {
+ *stream_global = &stream->global;
+ }
return r;
}
-void grpc_chttp2_register_stream(grpc_chttp2_transport *t,
- grpc_chttp2_stream *s) {
- stream_list_add_tail(t, s, GRPC_CHTTP2_LIST_ALL_STREAMS);
+void
+grpc_chttp2_register_stream (grpc_chttp2_transport * t, grpc_chttp2_stream * s)
+{
+ stream_list_add_tail (t, s, GRPC_CHTTP2_LIST_ALL_STREAMS);
}
-int grpc_chttp2_unregister_stream(grpc_chttp2_transport *t,
- grpc_chttp2_stream *s) {
- stream_list_maybe_remove(t, s, GRPC_CHTTP2_LIST_ALL_STREAMS);
- return stream_list_empty(t, GRPC_CHTTP2_LIST_ALL_STREAMS);
+int
+grpc_chttp2_unregister_stream (grpc_chttp2_transport * t, grpc_chttp2_stream * s)
+{
+ stream_list_maybe_remove (t, s, GRPC_CHTTP2_LIST_ALL_STREAMS);
+ return stream_list_empty (t, GRPC_CHTTP2_LIST_ALL_STREAMS);
}
-int grpc_chttp2_has_streams(grpc_chttp2_transport *t) {
- return !stream_list_empty(t, GRPC_CHTTP2_LIST_ALL_STREAMS);
+int
+grpc_chttp2_has_streams (grpc_chttp2_transport * t)
+{
+ return !stream_list_empty (t, GRPC_CHTTP2_LIST_ALL_STREAMS);
}
-void grpc_chttp2_for_all_streams(
- grpc_chttp2_transport_global *transport_global, void *user_data,
- void (*cb)(grpc_chttp2_transport_global *transport_global, void *user_data,
- grpc_chttp2_stream_global *stream_global)) {
+void
+grpc_chttp2_for_all_streams (grpc_chttp2_transport_global * transport_global, void *user_data, void (*cb) (grpc_chttp2_transport_global * transport_global, void *user_data, grpc_chttp2_stream_global * stream_global))
+{
grpc_chttp2_stream *s;
- grpc_chttp2_transport *t = TRANSPORT_FROM_GLOBAL(transport_global);
- for (s = t->lists[GRPC_CHTTP2_LIST_ALL_STREAMS].head; s != NULL;
- s = s->links[GRPC_CHTTP2_LIST_ALL_STREAMS].next) {
- cb(transport_global, user_data, &s->global);
- }
+ grpc_chttp2_transport *t = TRANSPORT_FROM_GLOBAL (transport_global);
+ for (s = t->lists[GRPC_CHTTP2_LIST_ALL_STREAMS].head; s != NULL; s = s->links[GRPC_CHTTP2_LIST_ALL_STREAMS].next)
+ {
+ cb (transport_global, user_data, &s->global);
+ }
}
diff --git a/src/core/transport/chttp2/stream_map.c b/src/core/transport/chttp2/stream_map.c
index bd16153ed1..00878c1d2a 100644
--- a/src/core/transport/chttp2/stream_map.c
+++ b/src/core/transport/chttp2/stream_map.c
@@ -39,98 +39,117 @@
#include <grpc/support/log.h>
#include <grpc/support/useful.h>
-void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map *map,
- size_t initial_capacity) {
- GPR_ASSERT(initial_capacity > 1);
- map->keys = gpr_malloc(sizeof(gpr_uint32) * initial_capacity);
- map->values = gpr_malloc(sizeof(void *) * initial_capacity);
+void
+grpc_chttp2_stream_map_init (grpc_chttp2_stream_map * map, size_t initial_capacity)
+{
+ GPR_ASSERT (initial_capacity > 1);
+ map->keys = gpr_malloc (sizeof (gpr_uint32) * initial_capacity);
+ map->values = gpr_malloc (sizeof (void *) * initial_capacity);
map->count = 0;
map->free = 0;
map->capacity = initial_capacity;
}
-void grpc_chttp2_stream_map_destroy(grpc_chttp2_stream_map *map) {
- gpr_free(map->keys);
- gpr_free(map->values);
+void
+grpc_chttp2_stream_map_destroy (grpc_chttp2_stream_map * map)
+{
+ gpr_free (map->keys);
+ gpr_free (map->values);
}
-static size_t compact(gpr_uint32 *keys, void **values, size_t count) {
+static size_t
+compact (gpr_uint32 * keys, void **values, size_t count)
+{
size_t i, out;
- for (i = 0, out = 0; i < count; i++) {
- if (values[i]) {
- keys[out] = keys[i];
- values[out] = values[i];
- out++;
+ for (i = 0, out = 0; i < count; i++)
+ {
+ if (values[i])
+ {
+ keys[out] = keys[i];
+ values[out] = values[i];
+ out++;
+ }
}
- }
return out;
}
-void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map *map, gpr_uint32 key,
- void *value) {
+void
+grpc_chttp2_stream_map_add (grpc_chttp2_stream_map * map, gpr_uint32 key, void *value)
+{
size_t count = map->count;
size_t capacity = map->capacity;
gpr_uint32 *keys = map->keys;
void **values = map->values;
- GPR_ASSERT(count == 0 || keys[count - 1] < key);
- GPR_ASSERT(value);
-
- if (count == capacity) {
- if (map->free > capacity / 4) {
- count = compact(keys, values, count);
- map->free = 0;
- } else {
- /* resize when less than 25% of the table is free, because compaction
- won't help much */
- map->capacity = capacity = 3 * capacity / 2;
- map->keys = keys = gpr_realloc(keys, capacity * sizeof(gpr_uint32));
- map->values = values = gpr_realloc(values, capacity * sizeof(void *));
+ GPR_ASSERT (count == 0 || keys[count - 1] < key);
+ GPR_ASSERT (value);
+
+ if (count == capacity)
+ {
+ if (map->free > capacity / 4)
+ {
+ count = compact (keys, values, count);
+ map->free = 0;
+ }
+ else
+ {
+ /* resize when less than 25% of the table is free, because compaction
+ won't help much */
+ map->capacity = capacity = 3 * capacity / 2;
+ map->keys = keys = gpr_realloc (keys, capacity * sizeof (gpr_uint32));
+ map->values = values = gpr_realloc (values, capacity * sizeof (void *));
+ }
}
- }
keys[count] = key;
values[count] = value;
map->count = count + 1;
}
-void grpc_chttp2_stream_map_move_into(grpc_chttp2_stream_map *src,
- grpc_chttp2_stream_map *dst) {
+void
+grpc_chttp2_stream_map_move_into (grpc_chttp2_stream_map * src, grpc_chttp2_stream_map * dst)
+{
/* if src is empty we dont need to do anything */
- if (src->count == src->free) {
- return;
- }
+ if (src->count == src->free)
+ {
+ return;
+ }
/* if dst is empty we simply need to swap */
- if (dst->count == dst->free) {
- GPR_SWAP(grpc_chttp2_stream_map, *src, *dst);
- return;
- }
+ if (dst->count == dst->free)
+ {
+ GPR_SWAP (grpc_chttp2_stream_map, *src, *dst);
+ return;
+ }
/* the first element of src must be greater than the last of dst...
* however the maps may need compacting for this property to hold */
- if (src->keys[0] <= dst->keys[dst->count - 1]) {
- src->count = compact(src->keys, src->values, src->count);
- src->free = 0;
- dst->count = compact(dst->keys, dst->values, dst->count);
- dst->free = 0;
- }
- GPR_ASSERT(src->keys[0] > dst->keys[dst->count - 1]);
+ if (src->keys[0] <= dst->keys[dst->count - 1])
+ {
+ src->count = compact (src->keys, src->values, src->count);
+ src->free = 0;
+ dst->count = compact (dst->keys, dst->values, dst->count);
+ dst->free = 0;
+ }
+ GPR_ASSERT (src->keys[0] > dst->keys[dst->count - 1]);
/* if dst doesn't have capacity, resize */
- if (dst->count + src->count > dst->capacity) {
- dst->capacity = GPR_MAX(dst->capacity * 3 / 2, dst->count + src->count);
- dst->keys = gpr_realloc(dst->keys, dst->capacity * sizeof(gpr_uint32));
- dst->values = gpr_realloc(dst->values, dst->capacity * sizeof(void *));
- }
- memcpy(dst->keys + dst->count, src->keys, src->count * sizeof(gpr_uint32));
- memcpy(dst->values + dst->count, src->values, src->count * sizeof(void *));
+ if (dst->count + src->count > dst->capacity)
+ {
+ dst->capacity = GPR_MAX (dst->capacity * 3 / 2, dst->count + src->count);
+ dst->keys = gpr_realloc (dst->keys, dst->capacity * sizeof (gpr_uint32));
+ dst->values = gpr_realloc (dst->values, dst->capacity * sizeof (void *));
+ }
+ memcpy (dst->keys + dst->count, src->keys, src->count * sizeof (gpr_uint32));
+ memcpy (dst->values + dst->count, src->values, src->count * sizeof (void *));
dst->count += src->count;
dst->free += src->free;
src->count = 0;
src->free = 0;
}
-static void **find(grpc_chttp2_stream_map *map, gpr_uint32 key) {
+static void **
+find (grpc_chttp2_stream_map * map, gpr_uint32 key)
+{
size_t min_idx = 0;
size_t max_idx = map->count;
size_t mid_idx;
@@ -138,60 +157,75 @@ static void **find(grpc_chttp2_stream_map *map, gpr_uint32 key) {
void **values = map->values;
gpr_uint32 mid_key;
- if (max_idx == 0) return NULL;
-
- while (min_idx < max_idx) {
- /* find the midpoint, avoiding overflow */
- mid_idx = min_idx + ((max_idx - min_idx) / 2);
- mid_key = keys[mid_idx];
-
- if (mid_key < key) {
- min_idx = mid_idx + 1;
- } else if (mid_key > key) {
- max_idx = mid_idx;
- } else /* mid_key == key */ {
- return &values[mid_idx];
+ if (max_idx == 0)
+ return NULL;
+
+ while (min_idx < max_idx)
+ {
+ /* find the midpoint, avoiding overflow */
+ mid_idx = min_idx + ((max_idx - min_idx) / 2);
+ mid_key = keys[mid_idx];
+
+ if (mid_key < key)
+ {
+ min_idx = mid_idx + 1;
+ }
+ else if (mid_key > key)
+ {
+ max_idx = mid_idx;
+ }
+ else /* mid_key == key */
+ {
+ return &values[mid_idx];
+ }
}
- }
return NULL;
}
-void *grpc_chttp2_stream_map_delete(grpc_chttp2_stream_map *map,
- gpr_uint32 key) {
- void **pvalue = find(map, key);
+void *
+grpc_chttp2_stream_map_delete (grpc_chttp2_stream_map * map, gpr_uint32 key)
+{
+ void **pvalue = find (map, key);
void *out = NULL;
- if (pvalue != NULL) {
- out = *pvalue;
- *pvalue = NULL;
- map->free += (out != NULL);
- /* recognize complete emptyness and ensure we can skip
- * defragmentation later */
- if (map->free == map->count) {
- map->free = map->count = 0;
+ if (pvalue != NULL)
+ {
+ out = *pvalue;
+ *pvalue = NULL;
+ map->free += (out != NULL);
+ /* recognize complete emptyness and ensure we can skip
+ * defragmentation later */
+ if (map->free == map->count)
+ {
+ map->free = map->count = 0;
+ }
}
- }
return out;
}
-void *grpc_chttp2_stream_map_find(grpc_chttp2_stream_map *map, gpr_uint32 key) {
- void **pvalue = find(map, key);
+void *
+grpc_chttp2_stream_map_find (grpc_chttp2_stream_map * map, gpr_uint32 key)
+{
+ void **pvalue = find (map, key);
return pvalue != NULL ? *pvalue : NULL;
}
-size_t grpc_chttp2_stream_map_size(grpc_chttp2_stream_map *map) {
+size_t
+grpc_chttp2_stream_map_size (grpc_chttp2_stream_map * map)
+{
return map->count - map->free;
}
-void grpc_chttp2_stream_map_for_each(grpc_chttp2_stream_map *map,
- void (*f)(void *user_data, gpr_uint32 key,
- void *value),
- void *user_data) {
+void
+grpc_chttp2_stream_map_for_each (grpc_chttp2_stream_map * map, void (*f) (void *user_data, gpr_uint32 key, void *value), void *user_data)
+{
size_t i;
- for (i = 0; i < map->count; i++) {
- if (map->values[i]) {
- f(user_data, map->keys[i], map->values[i]);
+ for (i = 0; i < map->count; i++)
+ {
+ if (map->values[i])
+ {
+ f (user_data, map->keys[i], map->values[i]);
+ }
}
- }
}
diff --git a/src/core/transport/chttp2/stream_map.h b/src/core/transport/chttp2/stream_map.h
index 71b0582054..2af61212da 100644
--- a/src/core/transport/chttp2/stream_map.h
+++ b/src/core/transport/chttp2/stream_map.h
@@ -44,7 +44,8 @@
Lookups are performed with binary search.
Adds are restricted to strictly higher keys than previously seen (this is
guaranteed by http2). */
-typedef struct {
+typedef struct
+{
gpr_uint32 *keys;
void **values;
size_t count;
@@ -52,34 +53,27 @@ typedef struct {
size_t capacity;
} grpc_chttp2_stream_map;
-void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map *map,
- size_t initial_capacity);
-void grpc_chttp2_stream_map_destroy(grpc_chttp2_stream_map *map);
+void grpc_chttp2_stream_map_init (grpc_chttp2_stream_map * map, size_t initial_capacity);
+void grpc_chttp2_stream_map_destroy (grpc_chttp2_stream_map * map);
/* Add a new key: given http2 semantics, new keys must always be greater than
existing keys - this is asserted */
-void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map *map, gpr_uint32 key,
- void *value);
+void grpc_chttp2_stream_map_add (grpc_chttp2_stream_map * map, gpr_uint32 key, void *value);
/* Delete an existing key - returns the previous value of the key if it existed,
or NULL otherwise */
-void *grpc_chttp2_stream_map_delete(grpc_chttp2_stream_map *map,
- gpr_uint32 key);
+void *grpc_chttp2_stream_map_delete (grpc_chttp2_stream_map * map, gpr_uint32 key);
/* Move all elements of src into dst */
-void grpc_chttp2_stream_map_move_into(grpc_chttp2_stream_map *src,
- grpc_chttp2_stream_map *dst);
+void grpc_chttp2_stream_map_move_into (grpc_chttp2_stream_map * src, grpc_chttp2_stream_map * dst);
/* Return an existing key, or NULL if it does not exist */
-void *grpc_chttp2_stream_map_find(grpc_chttp2_stream_map *map, gpr_uint32 key);
+void *grpc_chttp2_stream_map_find (grpc_chttp2_stream_map * map, gpr_uint32 key);
/* How many (populated) entries are in the stream map? */
-size_t grpc_chttp2_stream_map_size(grpc_chttp2_stream_map *map);
+size_t grpc_chttp2_stream_map_size (grpc_chttp2_stream_map * map);
/* Callback on each stream */
-void grpc_chttp2_stream_map_for_each(grpc_chttp2_stream_map *map,
- void (*f)(void *user_data, gpr_uint32 key,
- void *value),
- void *user_data);
+void grpc_chttp2_stream_map_for_each (grpc_chttp2_stream_map * map, void (*f) (void *user_data, gpr_uint32 key, void *value), void *user_data);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_STREAM_MAP_H */
diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c
index 8a9b290ecb..e241242403 100644
--- a/src/core/transport/chttp2/timeout_encoding.c
+++ b/src/core/transport/chttp2/timeout_encoding.c
@@ -38,147 +38,215 @@
#include "src/core/support/string.h"
-static int round_up(int x, int divisor) {
+static int
+round_up (int x, int divisor)
+{
return (x / divisor + (x % divisor != 0)) * divisor;
}
/* round an integer up to the next value with three significant figures */
-static int round_up_to_three_sig_figs(int x) {
- if (x < 1000) return x;
- if (x < 10000) return round_up(x, 10);
- if (x < 100000) return round_up(x, 100);
- if (x < 1000000) return round_up(x, 1000);
- if (x < 10000000) return round_up(x, 10000);
- if (x < 100000000) return round_up(x, 100000);
- if (x < 1000000000) return round_up(x, 1000000);
- return round_up(x, 10000000);
+static int
+round_up_to_three_sig_figs (int x)
+{
+ if (x < 1000)
+ return x;
+ if (x < 10000)
+ return round_up (x, 10);
+ if (x < 100000)
+ return round_up (x, 100);
+ if (x < 1000000)
+ return round_up (x, 1000);
+ if (x < 10000000)
+ return round_up (x, 10000);
+ if (x < 100000000)
+ return round_up (x, 100000);
+ if (x < 1000000000)
+ return round_up (x, 1000000);
+ return round_up (x, 10000000);
}
/* encode our minimum viable timeout value */
-static void enc_tiny(char *buffer) { memcpy(buffer, "1n", 3); }
+static void
+enc_tiny (char *buffer)
+{
+ memcpy (buffer, "1n", 3);
+}
-static void enc_ext(char *buffer, long value, char ext) {
- int n = gpr_ltoa(value, buffer);
+static void
+enc_ext (char *buffer, long value, char ext)
+{
+ int n = gpr_ltoa (value, buffer);
buffer[n] = ext;
buffer[n + 1] = 0;
}
-static void enc_seconds(char *buffer, long sec) {
- if (sec % 3600 == 0) {
- enc_ext(buffer, sec / 3600, 'H');
- } else if (sec % 60 == 0) {
- enc_ext(buffer, sec / 60, 'M');
- } else {
- enc_ext(buffer, sec, 'S');
- }
+static void
+enc_seconds (char *buffer, long sec)
+{
+ if (sec % 3600 == 0)
+ {
+ enc_ext (buffer, sec / 3600, 'H');
+ }
+ else if (sec % 60 == 0)
+ {
+ enc_ext (buffer, sec / 60, 'M');
+ }
+ else
+ {
+ enc_ext (buffer, sec, 'S');
+ }
}
-static void enc_nanos(char *buffer, int x) {
- x = round_up_to_three_sig_figs(x);
- if (x < 100000) {
- if (x % 1000 == 0) {
- enc_ext(buffer, x / 1000, 'u');
- } else {
- enc_ext(buffer, x, 'n');
- }
- } else if (x < 100000000) {
- if (x % 1000000 == 0) {
- enc_ext(buffer, x / 1000000, 'm');
- } else {
- enc_ext(buffer, x / 1000, 'u');
- }
- } else if (x < 1000000000) {
- enc_ext(buffer, x / 1000000, 'm');
- } else {
- /* note that this is only ever called with times of less than one second,
- so if we reach here the time must have been rounded up to a whole second
- (and no more) */
- memcpy(buffer, "1S", 3);
- }
+static void
+enc_nanos (char *buffer, int x)
+{
+ x = round_up_to_three_sig_figs (x);
+ if (x < 100000)
+ {
+ if (x % 1000 == 0)
+ {
+ enc_ext (buffer, x / 1000, 'u');
+ }
+ else
+ {
+ enc_ext (buffer, x, 'n');
+ }
+ }
+ else if (x < 100000000)
+ {
+ if (x % 1000000 == 0)
+ {
+ enc_ext (buffer, x / 1000000, 'm');
+ }
+ else
+ {
+ enc_ext (buffer, x / 1000, 'u');
+ }
+ }
+ else if (x < 1000000000)
+ {
+ enc_ext (buffer, x / 1000000, 'm');
+ }
+ else
+ {
+ /* note that this is only ever called with times of less than one second,
+ so if we reach here the time must have been rounded up to a whole second
+ (and no more) */
+ memcpy (buffer, "1S", 3);
+ }
}
-static void enc_micros(char *buffer, int x) {
- x = round_up_to_three_sig_figs(x);
- if (x < 100000) {
- if (x % 1000 == 0) {
- enc_ext(buffer, x / 1000, 'm');
- } else {
- enc_ext(buffer, x, 'u');
- }
- } else if (x < 100000000) {
- if (x % 1000000 == 0) {
- enc_ext(buffer, x / 1000000, 'S');
- } else {
- enc_ext(buffer, x / 1000, 'm');
- }
- } else {
- enc_ext(buffer, x / 1000000, 'S');
- }
+static void
+enc_micros (char *buffer, int x)
+{
+ x = round_up_to_three_sig_figs (x);
+ if (x < 100000)
+ {
+ if (x % 1000 == 0)
+ {
+ enc_ext (buffer, x / 1000, 'm');
+ }
+ else
+ {
+ enc_ext (buffer, x, 'u');
+ }
+ }
+ else if (x < 100000000)
+ {
+ if (x % 1000000 == 0)
+ {
+ enc_ext (buffer, x / 1000000, 'S');
+ }
+ else
+ {
+ enc_ext (buffer, x / 1000, 'm');
+ }
+ }
+ else
+ {
+ enc_ext (buffer, x / 1000000, 'S');
+ }
}
-void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer) {
- if (timeout.tv_sec < 0) {
- enc_tiny(buffer);
- } else if (timeout.tv_sec == 0) {
- enc_nanos(buffer, timeout.tv_nsec);
- } else if (timeout.tv_sec < 1000 && timeout.tv_nsec != 0) {
- enc_micros(buffer,
- (int)(timeout.tv_sec * 1000000) +
- (timeout.tv_nsec / 1000 + (timeout.tv_nsec % 1000 != 0)));
- } else {
- enc_seconds(buffer, timeout.tv_sec + (timeout.tv_nsec != 0));
- }
+void
+grpc_chttp2_encode_timeout (gpr_timespec timeout, char *buffer)
+{
+ if (timeout.tv_sec < 0)
+ {
+ enc_tiny (buffer);
+ }
+ else if (timeout.tv_sec == 0)
+ {
+ enc_nanos (buffer, timeout.tv_nsec);
+ }
+ else if (timeout.tv_sec < 1000 && timeout.tv_nsec != 0)
+ {
+ enc_micros (buffer, (int) (timeout.tv_sec * 1000000) + (timeout.tv_nsec / 1000 + (timeout.tv_nsec % 1000 != 0)));
+ }
+ else
+ {
+ enc_seconds (buffer, timeout.tv_sec + (timeout.tv_nsec != 0));
+ }
}
-static int is_all_whitespace(const char *p) {
- while (*p == ' ') p++;
+static int
+is_all_whitespace (const char *p)
+{
+ while (*p == ' ')
+ p++;
return *p == 0;
}
-int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout) {
+int
+grpc_chttp2_decode_timeout (const char *buffer, gpr_timespec * timeout)
+{
gpr_uint32 x = 0;
- const gpr_uint8 *p = (const gpr_uint8 *)buffer;
+ const gpr_uint8 *p = (const gpr_uint8 *) buffer;
int have_digit = 0;
/* skip whitespace */
for (; *p == ' '; p++)
;
/* decode numeric part */
- for (; *p >= '0' && *p <= '9'; p++) {
- gpr_uint32 xp = x * 10u + (gpr_uint32)*p - (gpr_uint32)'0';
- have_digit = 1;
- if (xp < x) {
- *timeout = gpr_inf_future(GPR_CLOCK_REALTIME);
- return 1;
- }
- x = xp;
- }
- if (!have_digit) return 0;
+ for (; *p >= '0' && *p <= '9'; p++)
+ {
+ gpr_uint32 xp = x * 10u + (gpr_uint32) * p - (gpr_uint32) '0';
+ have_digit = 1;
+ if (xp < x)
+ {
+ *timeout = gpr_inf_future (GPR_CLOCK_REALTIME);
+ return 1;
+ }
+ x = xp;
+ }
+ if (!have_digit)
+ return 0;
/* skip whitespace */
for (; *p == ' '; p++)
;
/* decode unit specifier */
- switch (*p) {
+ switch (*p)
+ {
case 'n':
- *timeout = gpr_time_from_nanos(x, GPR_TIMESPAN);
+ *timeout = gpr_time_from_nanos (x, GPR_TIMESPAN);
break;
case 'u':
- *timeout = gpr_time_from_micros(x, GPR_TIMESPAN);
+ *timeout = gpr_time_from_micros (x, GPR_TIMESPAN);
break;
case 'm':
- *timeout = gpr_time_from_millis(x, GPR_TIMESPAN);
+ *timeout = gpr_time_from_millis (x, GPR_TIMESPAN);
break;
case 'S':
- *timeout = gpr_time_from_seconds(x, GPR_TIMESPAN);
+ *timeout = gpr_time_from_seconds (x, GPR_TIMESPAN);
break;
case 'M':
- *timeout = gpr_time_from_minutes(x, GPR_TIMESPAN);
+ *timeout = gpr_time_from_minutes (x, GPR_TIMESPAN);
break;
case 'H':
- *timeout = gpr_time_from_hours(x, GPR_TIMESPAN);
+ *timeout = gpr_time_from_hours (x, GPR_TIMESPAN);
break;
default:
return 0;
- }
+ }
p++;
- return is_all_whitespace((const char *)p);
+ return is_all_whitespace ((const char *) p);
}
diff --git a/src/core/transport/chttp2/timeout_encoding.h b/src/core/transport/chttp2/timeout_encoding.h
index 9d8756e799..b68ce2e5d6 100644
--- a/src/core/transport/chttp2/timeout_encoding.h
+++ b/src/core/transport/chttp2/timeout_encoding.h
@@ -41,7 +41,7 @@
/* Encode/decode timeouts to the GRPC over HTTP2 format;
encoding may round up arbitrarily */
-void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer);
-int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout);
+void grpc_chttp2_encode_timeout (gpr_timespec timeout, char *buffer);
+int grpc_chttp2_decode_timeout (const char *buffer, gpr_timespec * timeout);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_TIMEOUT_ENCODING_H */
diff --git a/src/core/transport/chttp2/varint.c b/src/core/transport/chttp2/varint.c
index 056f68047b..f478a9d847 100644
--- a/src/core/transport/chttp2/varint.c
+++ b/src/core/transport/chttp2/varint.c
@@ -33,34 +33,46 @@
#include "src/core/transport/chttp2/varint.h"
-gpr_uint32 grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value) {
- if (tail_value < (1 << 7)) {
- return 2;
- } else if (tail_value < (1 << 14)) {
- return 3;
- } else if (tail_value < (1 << 21)) {
- return 4;
- } else if (tail_value < (1 << 28)) {
- return 5;
- } else {
- return 6;
- }
+gpr_uint32
+grpc_chttp2_hpack_varint_length (gpr_uint32 tail_value)
+{
+ if (tail_value < (1 << 7))
+ {
+ return 2;
+ }
+ else if (tail_value < (1 << 14))
+ {
+ return 3;
+ }
+ else if (tail_value < (1 << 21))
+ {
+ return 4;
+ }
+ else if (tail_value < (1 << 28))
+ {
+ return 5;
+ }
+ else
+ {
+ return 6;
+ }
}
-void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value,
- gpr_uint8* target,
- gpr_uint32 tail_length) {
- switch (tail_length) {
+void
+grpc_chttp2_hpack_write_varint_tail (gpr_uint32 tail_value, gpr_uint8 * target, gpr_uint32 tail_length)
+{
+ switch (tail_length)
+ {
case 5:
- target[4] = (gpr_uint8)((tail_value >> 28) | 0x80);
+ target[4] = (gpr_uint8) ((tail_value >> 28) | 0x80);
case 4:
- target[3] = (gpr_uint8)((tail_value >> 21) | 0x80);
+ target[3] = (gpr_uint8) ((tail_value >> 21) | 0x80);
case 3:
- target[2] = (gpr_uint8)((tail_value >> 14) | 0x80);
+ target[2] = (gpr_uint8) ((tail_value >> 14) | 0x80);
case 2:
- target[1] = (gpr_uint8)((tail_value >> 7) | 0x80);
+ target[1] = (gpr_uint8) ((tail_value >> 7) | 0x80);
case 1:
- target[0] = (gpr_uint8)((tail_value) | 0x80);
- }
+ target[0] = (gpr_uint8) ((tail_value) | 0x80);
+ }
target[tail_length - 1] &= 0x7f;
}
diff --git a/src/core/transport/chttp2/varint.h b/src/core/transport/chttp2/varint.h
index 4dfcc76773..4193305d0f 100644
--- a/src/core/transport/chttp2/varint.h
+++ b/src/core/transport/chttp2/varint.h
@@ -41,11 +41,9 @@
/* length of a value that needs varint tail encoding (it's bigger than can be
bitpacked into the opcode byte) - returned value includes the length of the
opcode byte */
-gpr_uint32 grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value);
+gpr_uint32 grpc_chttp2_hpack_varint_length (gpr_uint32 tail_value);
-void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value,
- gpr_uint8* target,
- gpr_uint32 tail_length);
+void grpc_chttp2_hpack_write_varint_tail (gpr_uint32 tail_value, gpr_uint8 * target, gpr_uint32 tail_length);
/* maximum value that can be bitpacked with the opcode if the opcode has a
prefix
diff --git a/src/core/transport/chttp2/writing.c b/src/core/transport/chttp2/writing.c
index e6f169c280..edf40f54fb 100644
--- a/src/core/transport/chttp2/writing.c
+++ b/src/core/transport/chttp2/writing.c
@@ -39,205 +39,174 @@
#include "src/core/transport/chttp2/http2_errors.h"
-static void finalize_outbuf(grpc_chttp2_transport_writing *transport_writing);
+static void finalize_outbuf (grpc_chttp2_transport_writing * transport_writing);
-int grpc_chttp2_unlocking_check_writes(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_writing *transport_writing) {
+int
+grpc_chttp2_unlocking_check_writes (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing)
+{
grpc_chttp2_stream_global *stream_global;
grpc_chttp2_stream_writing *stream_writing;
grpc_chttp2_stream_global *first_reinserted_stream = NULL;
gpr_uint32 window_delta;
/* simple writes are queued to qbuf, and flushed here */
- gpr_slice_buffer_swap(&transport_global->qbuf, &transport_writing->outbuf);
- GPR_ASSERT(transport_global->qbuf.count == 0);
-
- if (transport_global->dirtied_local_settings &&
- !transport_global->sent_local_settings) {
- gpr_slice_buffer_add(
- &transport_writing->outbuf,
- grpc_chttp2_settings_create(
- transport_global->settings[GRPC_SENT_SETTINGS],
- transport_global->settings[GRPC_LOCAL_SETTINGS],
- transport_global->force_send_settings, GRPC_CHTTP2_NUM_SETTINGS));
- transport_global->force_send_settings = 0;
- transport_global->dirtied_local_settings = 0;
- transport_global->sent_local_settings = 1;
- }
+ gpr_slice_buffer_swap (&transport_global->qbuf, &transport_writing->outbuf);
+ GPR_ASSERT (transport_global->qbuf.count == 0);
+
+ if (transport_global->dirtied_local_settings && !transport_global->sent_local_settings)
+ {
+ gpr_slice_buffer_add (&transport_writing->outbuf, grpc_chttp2_settings_create (transport_global->settings[GRPC_SENT_SETTINGS], transport_global->settings[GRPC_LOCAL_SETTINGS], transport_global->force_send_settings, GRPC_CHTTP2_NUM_SETTINGS));
+ transport_global->force_send_settings = 0;
+ transport_global->dirtied_local_settings = 0;
+ transport_global->sent_local_settings = 1;
+ }
/* for each grpc_chttp2_stream that's become writable, frame it's data
(according to available window sizes) and add to the output buffer */
- while (grpc_chttp2_list_pop_writable_stream(
- transport_global, transport_writing, &stream_global, &stream_writing)) {
- if (stream_global == first_reinserted_stream) {
- /* prevent infinite loop */
- grpc_chttp2_list_add_first_writable_stream(transport_global,
- stream_global);
- break;
- }
-
- stream_writing->id = stream_global->id;
- stream_writing->send_closed = GRPC_DONT_SEND_CLOSED;
-
- if (stream_global->outgoing_sopb) {
- window_delta = grpc_chttp2_preencode(
- stream_global->outgoing_sopb->ops,
- &stream_global->outgoing_sopb->nops,
- (gpr_uint32)GPR_MIN(GPR_MIN(transport_global->outgoing_window,
- stream_global->outgoing_window),
- GPR_UINT32_MAX),
- &stream_writing->sopb);
- GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(
- "write", transport_global, outgoing_window, -(gpr_int64)window_delta);
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("write", transport_global, stream_global,
- outgoing_window,
- -(gpr_int64)window_delta);
- transport_global->outgoing_window -= window_delta;
- stream_global->outgoing_window -= window_delta;
-
- if (stream_global->write_state == GRPC_WRITE_STATE_QUEUED_CLOSE &&
- stream_global->outgoing_sopb->nops == 0) {
- if (!transport_global->is_client && !stream_global->read_closed) {
- stream_writing->send_closed = GRPC_SEND_CLOSED_WITH_RST_STREAM;
- } else {
- stream_writing->send_closed = GRPC_SEND_CLOSED;
- }
- }
-
- if (stream_global->outgoing_window > 0 &&
- stream_global->outgoing_sopb->nops != 0) {
- grpc_chttp2_list_add_writable_stream(transport_global, stream_global);
- if (first_reinserted_stream == NULL &&
- transport_global->outgoing_window == 0) {
- first_reinserted_stream = stream_global;
- }
- }
- }
-
- if (!stream_global->read_closed &&
- stream_global->unannounced_incoming_window > 0) {
- GPR_ASSERT(stream_writing->announce_window == 0);
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "write", transport_writing, stream_writing, announce_window,
- stream_global->unannounced_incoming_window);
- stream_writing->announce_window =
- stream_global->unannounced_incoming_window;
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "write", transport_global, stream_global, incoming_window,
- stream_global->unannounced_incoming_window);
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "write", transport_global, stream_global, unannounced_incoming_window,
- -(gpr_int64)stream_global->unannounced_incoming_window);
- stream_global->incoming_window +=
- stream_global->unannounced_incoming_window;
- stream_global->unannounced_incoming_window = 0;
- grpc_chttp2_list_add_incoming_window_updated(transport_global,
- stream_global);
- stream_global->writing_now |= GRPC_CHTTP2_WRITING_WINDOW;
- }
- if (stream_writing->sopb.nops > 0 ||
- stream_writing->send_closed != GRPC_DONT_SEND_CLOSED) {
- stream_global->writing_now |= GRPC_CHTTP2_WRITING_DATA;
+ while (grpc_chttp2_list_pop_writable_stream (transport_global, transport_writing, &stream_global, &stream_writing))
+ {
+ if (stream_global == first_reinserted_stream)
+ {
+ /* prevent infinite loop */
+ grpc_chttp2_list_add_first_writable_stream (transport_global, stream_global);
+ break;
+ }
+
+ stream_writing->id = stream_global->id;
+ stream_writing->send_closed = GRPC_DONT_SEND_CLOSED;
+
+ if (stream_global->outgoing_sopb)
+ {
+ window_delta = grpc_chttp2_preencode (stream_global->outgoing_sopb->ops, &stream_global->outgoing_sopb->nops, (gpr_uint32) GPR_MIN (GPR_MIN (transport_global->outgoing_window, stream_global->outgoing_window), GPR_UINT32_MAX), &stream_writing->sopb);
+ GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("write", transport_global, outgoing_window, -(gpr_int64) window_delta);
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("write", transport_global, stream_global, outgoing_window, -(gpr_int64) window_delta);
+ transport_global->outgoing_window -= window_delta;
+ stream_global->outgoing_window -= window_delta;
+
+ if (stream_global->write_state == GRPC_WRITE_STATE_QUEUED_CLOSE && stream_global->outgoing_sopb->nops == 0)
+ {
+ if (!transport_global->is_client && !stream_global->read_closed)
+ {
+ stream_writing->send_closed = GRPC_SEND_CLOSED_WITH_RST_STREAM;
+ }
+ else
+ {
+ stream_writing->send_closed = GRPC_SEND_CLOSED;
+ }
+ }
+
+ if (stream_global->outgoing_window > 0 && stream_global->outgoing_sopb->nops != 0)
+ {
+ grpc_chttp2_list_add_writable_stream (transport_global, stream_global);
+ if (first_reinserted_stream == NULL && transport_global->outgoing_window == 0)
+ {
+ first_reinserted_stream = stream_global;
+ }
+ }
+ }
+
+ if (!stream_global->read_closed && stream_global->unannounced_incoming_window > 0)
+ {
+ GPR_ASSERT (stream_writing->announce_window == 0);
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("write", transport_writing, stream_writing, announce_window, stream_global->unannounced_incoming_window);
+ stream_writing->announce_window = stream_global->unannounced_incoming_window;
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("write", transport_global, stream_global, incoming_window, stream_global->unannounced_incoming_window);
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("write", transport_global, stream_global, unannounced_incoming_window, -(gpr_int64) stream_global->unannounced_incoming_window);
+ stream_global->incoming_window += stream_global->unannounced_incoming_window;
+ stream_global->unannounced_incoming_window = 0;
+ grpc_chttp2_list_add_incoming_window_updated (transport_global, stream_global);
+ stream_global->writing_now |= GRPC_CHTTP2_WRITING_WINDOW;
+ }
+ if (stream_writing->sopb.nops > 0 || stream_writing->send_closed != GRPC_DONT_SEND_CLOSED)
+ {
+ stream_global->writing_now |= GRPC_CHTTP2_WRITING_DATA;
+ }
+ if (stream_global->writing_now != 0)
+ {
+ grpc_chttp2_list_add_writing_stream (transport_writing, stream_writing);
+ }
}
- if (stream_global->writing_now != 0) {
- grpc_chttp2_list_add_writing_stream(transport_writing, stream_writing);
- }
- }
/* if the grpc_chttp2_transport is ready to send a window update, do so here
also; 3/4 is a magic number that will likely get tuned soon */
- if (transport_global->incoming_window <
- transport_global->connection_window_target * 3 / 4) {
- window_delta = transport_global->connection_window_target -
- transport_global->incoming_window;
- gpr_slice_buffer_add(&transport_writing->outbuf,
- grpc_chttp2_window_update_create(0, window_delta));
- GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT("write", transport_global,
- incoming_window, window_delta);
- transport_global->incoming_window += window_delta;
- }
-
- return transport_writing->outbuf.count > 0 ||
- grpc_chttp2_list_have_writing_streams(transport_writing);
+ if (transport_global->incoming_window < transport_global->connection_window_target * 3 / 4)
+ {
+ window_delta = transport_global->connection_window_target - transport_global->incoming_window;
+ gpr_slice_buffer_add (&transport_writing->outbuf, grpc_chttp2_window_update_create (0, window_delta));
+ GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("write", transport_global, incoming_window, window_delta);
+ transport_global->incoming_window += window_delta;
+ }
+
+ return transport_writing->outbuf.count > 0 || grpc_chttp2_list_have_writing_streams (transport_writing);
}
-void grpc_chttp2_perform_writes(
- grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint,
- grpc_closure_list *closure_list) {
- GPR_ASSERT(transport_writing->outbuf.count > 0 ||
- grpc_chttp2_list_have_writing_streams(transport_writing));
+void
+grpc_chttp2_perform_writes (grpc_chttp2_transport_writing * transport_writing, grpc_endpoint * endpoint, grpc_closure_list * closure_list)
+{
+ GPR_ASSERT (transport_writing->outbuf.count > 0 || grpc_chttp2_list_have_writing_streams (transport_writing));
- finalize_outbuf(transport_writing);
+ finalize_outbuf (transport_writing);
- GPR_ASSERT(transport_writing->outbuf.count > 0);
- GPR_ASSERT(endpoint);
+ GPR_ASSERT (transport_writing->outbuf.count > 0);
+ GPR_ASSERT (endpoint);
- grpc_endpoint_write(endpoint, &transport_writing->outbuf,
- &transport_writing->done_cb, closure_list);
+ grpc_endpoint_write (endpoint, &transport_writing->outbuf, &transport_writing->done_cb, closure_list);
}
-static void finalize_outbuf(grpc_chttp2_transport_writing *transport_writing) {
+static void
+finalize_outbuf (grpc_chttp2_transport_writing * transport_writing)
+{
grpc_chttp2_stream_writing *stream_writing;
- while (
- grpc_chttp2_list_pop_writing_stream(transport_writing, &stream_writing)) {
- if (stream_writing->sopb.nops > 0 ||
- stream_writing->send_closed != GRPC_DONT_SEND_CLOSED) {
- grpc_chttp2_encode(stream_writing->sopb.ops, stream_writing->sopb.nops,
- stream_writing->send_closed != GRPC_DONT_SEND_CLOSED,
- stream_writing->id,
- &transport_writing->hpack_compressor,
- &transport_writing->outbuf);
- stream_writing->sopb.nops = 0;
+ while (grpc_chttp2_list_pop_writing_stream (transport_writing, &stream_writing))
+ {
+ if (stream_writing->sopb.nops > 0 || stream_writing->send_closed != GRPC_DONT_SEND_CLOSED)
+ {
+ grpc_chttp2_encode (stream_writing->sopb.ops, stream_writing->sopb.nops, stream_writing->send_closed != GRPC_DONT_SEND_CLOSED, stream_writing->id, &transport_writing->hpack_compressor, &transport_writing->outbuf);
+ stream_writing->sopb.nops = 0;
+ }
+ if (stream_writing->announce_window > 0)
+ {
+ gpr_slice_buffer_add (&transport_writing->outbuf, grpc_chttp2_window_update_create (stream_writing->id, stream_writing->announce_window));
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("write", transport_writing, stream_writing, announce_window, -(gpr_int64) stream_writing->announce_window);
+ stream_writing->announce_window = 0;
+ }
+ if (stream_writing->send_closed == GRPC_SEND_CLOSED_WITH_RST_STREAM)
+ {
+ gpr_slice_buffer_add (&transport_writing->outbuf, grpc_chttp2_rst_stream_create (stream_writing->id, GRPC_CHTTP2_NO_ERROR));
+ }
+ grpc_chttp2_list_add_written_stream (transport_writing, stream_writing);
}
- if (stream_writing->announce_window > 0) {
- gpr_slice_buffer_add(
- &transport_writing->outbuf,
- grpc_chttp2_window_update_create(stream_writing->id,
- stream_writing->announce_window));
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "write", transport_writing, stream_writing, announce_window,
- -(gpr_int64)stream_writing->announce_window);
- stream_writing->announce_window = 0;
- }
- if (stream_writing->send_closed == GRPC_SEND_CLOSED_WITH_RST_STREAM) {
- gpr_slice_buffer_add(&transport_writing->outbuf,
- grpc_chttp2_rst_stream_create(stream_writing->id,
- GRPC_CHTTP2_NO_ERROR));
- }
- grpc_chttp2_list_add_written_stream(transport_writing, stream_writing);
- }
}
-void grpc_chttp2_cleanup_writing(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_transport_writing *transport_writing,
- grpc_closure_list *closure_list) {
+void
+grpc_chttp2_cleanup_writing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing, grpc_closure_list * closure_list)
+{
grpc_chttp2_stream_writing *stream_writing;
grpc_chttp2_stream_global *stream_global;
- while (grpc_chttp2_list_pop_written_stream(
- transport_global, transport_writing, &stream_global, &stream_writing)) {
- GPR_ASSERT(stream_global->writing_now != 0);
- if (stream_writing->send_closed != GRPC_DONT_SEND_CLOSED) {
- stream_global->write_state = GRPC_WRITE_STATE_SENT_CLOSE;
- if (!transport_global->is_client) {
- stream_global->read_closed = 1;
- }
- }
- if (stream_global->writing_now & GRPC_CHTTP2_WRITING_DATA) {
- if (stream_global->outgoing_sopb != NULL &&
- stream_global->outgoing_sopb->nops == 0) {
- GPR_ASSERT(stream_global->write_state != GRPC_WRITE_STATE_QUEUED_CLOSE);
- stream_global->outgoing_sopb = NULL;
- grpc_closure_list_add(closure_list, stream_global->send_done_closure,
- 1);
- }
+ while (grpc_chttp2_list_pop_written_stream (transport_global, transport_writing, &stream_global, &stream_writing))
+ {
+ GPR_ASSERT (stream_global->writing_now != 0);
+ if (stream_writing->send_closed != GRPC_DONT_SEND_CLOSED)
+ {
+ stream_global->write_state = GRPC_WRITE_STATE_SENT_CLOSE;
+ if (!transport_global->is_client)
+ {
+ stream_global->read_closed = 1;
+ }
+ }
+ if (stream_global->writing_now & GRPC_CHTTP2_WRITING_DATA)
+ {
+ if (stream_global->outgoing_sopb != NULL && stream_global->outgoing_sopb->nops == 0)
+ {
+ GPR_ASSERT (stream_global->write_state != GRPC_WRITE_STATE_QUEUED_CLOSE);
+ stream_global->outgoing_sopb = NULL;
+ grpc_closure_list_add (closure_list, stream_global->send_done_closure, 1);
+ }
+ }
+ stream_global->writing_now = 0;
+ grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global);
}
- stream_global->writing_now = 0;
- grpc_chttp2_list_add_read_write_state_changed(transport_global,
- stream_global);
- }
- gpr_slice_buffer_reset_and_unref(&transport_writing->outbuf);
+ gpr_slice_buffer_reset_and_unref (&transport_writing->outbuf);
}
diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c
index 766b55b5fa..f99fa52dcc 100644
--- a/src/core/transport/chttp2_transport.c
+++ b/src/core/transport/chttp2_transport.c
@@ -77,169 +77,153 @@ int grpc_flowctl_trace = 0;
static const grpc_transport_vtable vtable;
-static void lock(grpc_chttp2_transport *t);
-static void unlock(grpc_chttp2_transport *t, grpc_closure_list *closure_list);
+static void lock (grpc_chttp2_transport * t);
+static void unlock (grpc_chttp2_transport * t, grpc_closure_list * closure_list);
-static void unlock_check_read_write_state(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list);
+static void unlock_check_read_write_state (grpc_chttp2_transport * t, grpc_closure_list * closure_list);
/* forward declarations of various callbacks that we'll build closures around */
-static void writing_action(void *t, int iomgr_success_ignored,
- grpc_closure_list *closure_list);
+static void writing_action (void *t, int iomgr_success_ignored, grpc_closure_list * closure_list);
/** Set a transport level setting, and push it to our peer */
-static void push_setting(grpc_chttp2_transport *t, grpc_chttp2_setting_id id,
- gpr_uint32 value);
+static void push_setting (grpc_chttp2_transport * t, grpc_chttp2_setting_id id, gpr_uint32 value);
/** Endpoint callback to process incoming data */
-static void recv_data(void *tp, int success, grpc_closure_list *closure_list);
+static void recv_data (void *tp, int success, grpc_closure_list * closure_list);
/** Start disconnection chain */
-static void drop_connection(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list);
+static void drop_connection (grpc_chttp2_transport * t, grpc_closure_list * closure_list);
/** Perform a transport_op */
-static void perform_stream_op_locked(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global, grpc_transport_stream_op *op,
- grpc_closure_list *closure_list);
+static void perform_stream_op_locked (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global, grpc_transport_stream_op * op, grpc_closure_list * closure_list);
/** Cancel a stream: coming from the transport API */
-static void cancel_from_api(grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global,
- grpc_status_code status);
+static void cancel_from_api (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global, grpc_status_code status);
-static void close_from_api(grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global,
- grpc_status_code status,
- gpr_slice *optional_message);
+static void close_from_api (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global, grpc_status_code status, gpr_slice * optional_message);
/** Add endpoint from this transport to pollset */
-static void add_to_pollset_locked(grpc_chttp2_transport *t,
- grpc_pollset *pollset,
- grpc_closure_list *closure_list);
-static void add_to_pollset_set_locked(grpc_chttp2_transport *t,
- grpc_pollset_set *pollset_set,
- grpc_closure_list *closure_list);
+static void add_to_pollset_locked (grpc_chttp2_transport * t, grpc_pollset * pollset, grpc_closure_list * closure_list);
+static void add_to_pollset_set_locked (grpc_chttp2_transport * t, grpc_pollset_set * pollset_set, grpc_closure_list * closure_list);
/** Start new streams that have been created if we can */
-static void maybe_start_some_streams(
- grpc_chttp2_transport_global *transport_global,
- grpc_closure_list *closure_list);
+static void maybe_start_some_streams (grpc_chttp2_transport_global * transport_global, grpc_closure_list * closure_list);
-static void connectivity_state_set(
- grpc_chttp2_transport_global *transport_global,
- grpc_connectivity_state state, const char *reason,
- grpc_closure_list *closure_list);
+static void connectivity_state_set (grpc_chttp2_transport_global * transport_global, grpc_connectivity_state state, const char *reason, grpc_closure_list * closure_list);
/*
* CONSTRUCTION/DESTRUCTION/REFCOUNTING
*/
-static void destruct_transport(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list) {
+static void
+destruct_transport (grpc_chttp2_transport * t, grpc_closure_list * closure_list)
+{
size_t i;
- gpr_mu_lock(&t->mu);
+ gpr_mu_lock (&t->mu);
- GPR_ASSERT(t->ep == NULL);
+ GPR_ASSERT (t->ep == NULL);
- gpr_slice_buffer_destroy(&t->global.qbuf);
+ gpr_slice_buffer_destroy (&t->global.qbuf);
- gpr_slice_buffer_destroy(&t->writing.outbuf);
- grpc_chttp2_hpack_compressor_destroy(&t->writing.hpack_compressor);
+ gpr_slice_buffer_destroy (&t->writing.outbuf);
+ grpc_chttp2_hpack_compressor_destroy (&t->writing.hpack_compressor);
- gpr_slice_buffer_destroy(&t->parsing.qbuf);
- gpr_slice_buffer_destroy(&t->read_buffer);
- grpc_chttp2_hpack_parser_destroy(&t->parsing.hpack_parser);
- grpc_chttp2_goaway_parser_destroy(&t->parsing.goaway_parser);
+ gpr_slice_buffer_destroy (&t->parsing.qbuf);
+ gpr_slice_buffer_destroy (&t->read_buffer);
+ grpc_chttp2_hpack_parser_destroy (&t->parsing.hpack_parser);
+ grpc_chttp2_goaway_parser_destroy (&t->parsing.goaway_parser);
- GRPC_MDSTR_UNREF(t->parsing.str_grpc_timeout);
+ GRPC_MDSTR_UNREF (t->parsing.str_grpc_timeout);
- for (i = 0; i < STREAM_LIST_COUNT; i++) {
- GPR_ASSERT(t->lists[i].head == NULL);
- GPR_ASSERT(t->lists[i].tail == NULL);
- }
+ for (i = 0; i < STREAM_LIST_COUNT; i++)
+ {
+ GPR_ASSERT (t->lists[i].head == NULL);
+ GPR_ASSERT (t->lists[i].tail == NULL);
+ }
- GPR_ASSERT(grpc_chttp2_stream_map_size(&t->parsing_stream_map) == 0);
- GPR_ASSERT(grpc_chttp2_stream_map_size(&t->new_stream_map) == 0);
+ GPR_ASSERT (grpc_chttp2_stream_map_size (&t->parsing_stream_map) == 0);
+ GPR_ASSERT (grpc_chttp2_stream_map_size (&t->new_stream_map) == 0);
- grpc_chttp2_stream_map_destroy(&t->parsing_stream_map);
- grpc_chttp2_stream_map_destroy(&t->new_stream_map);
- grpc_connectivity_state_destroy(&t->channel_callback.state_tracker,
- closure_list);
+ grpc_chttp2_stream_map_destroy (&t->parsing_stream_map);
+ grpc_chttp2_stream_map_destroy (&t->new_stream_map);
+ grpc_connectivity_state_destroy (&t->channel_callback.state_tracker, closure_list);
- gpr_mu_unlock(&t->mu);
- gpr_mu_destroy(&t->mu);
+ gpr_mu_unlock (&t->mu);
+ gpr_mu_destroy (&t->mu);
/* callback remaining pings: they're not allowed to call into the transpot,
and maybe they hold resources that need to be freed */
- while (t->global.pings.next != &t->global.pings) {
- grpc_chttp2_outstanding_ping *ping = t->global.pings.next;
- grpc_closure_list_add(closure_list, ping->on_recv, 0);
- ping->next->prev = ping->prev;
- ping->prev->next = ping->next;
- gpr_free(ping);
- }
-
- grpc_mdctx_unref(t->metadata_context);
-
- gpr_free(t->peer_string);
- gpr_free(t);
+ while (t->global.pings.next != &t->global.pings)
+ {
+ grpc_chttp2_outstanding_ping *ping = t->global.pings.next;
+ grpc_closure_list_add (closure_list, ping->on_recv, 0);
+ ping->next->prev = ping->prev;
+ ping->prev->next = ping->next;
+ gpr_free (ping);
+ }
+
+ grpc_mdctx_unref (t->metadata_context);
+
+ gpr_free (t->peer_string);
+ gpr_free (t);
}
#ifdef REFCOUNTING_DEBUG
#define REF_TRANSPORT(t, r) ref_transport(t, r, __FILE__, __LINE__)
#define UNREF_TRANSPORT(t, r, cl) unref_transport(t, cl, r, __FILE__, __LINE__)
-static void unref_transport(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list, const char *reason,
- const char *file, int line) {
- gpr_log(GPR_DEBUG, "chttp2:unref:%p %d->%d %s [%s:%d]", t, t->refs.count,
- t->refs.count - 1, reason, file, line);
- if (!gpr_unref(&t->refs)) return;
- destruct_transport(t, closure_list);
+static void
+unref_transport (grpc_chttp2_transport * t, grpc_closure_list * closure_list, const char *reason, const char *file, int line)
+{
+ gpr_log (GPR_DEBUG, "chttp2:unref:%p %d->%d %s [%s:%d]", t, t->refs.count, t->refs.count - 1, reason, file, line);
+ if (!gpr_unref (&t->refs))
+ return;
+ destruct_transport (t, closure_list);
}
-static void ref_transport(grpc_chttp2_transport *t, const char *reason,
- const char *file, int line) {
- gpr_log(GPR_DEBUG, "chttp2: ref:%p %d->%d %s [%s:%d]", t, t->refs.count,
- t->refs.count + 1, reason, file, line);
- gpr_ref(&t->refs);
+static void
+ref_transport (grpc_chttp2_transport * t, const char *reason, const char *file, int line)
+{
+ gpr_log (GPR_DEBUG, "chttp2: ref:%p %d->%d %s [%s:%d]", t, t->refs.count, t->refs.count + 1, reason, file, line);
+ gpr_ref (&t->refs);
}
#else
#define REF_TRANSPORT(t, r) ref_transport(t)
#define UNREF_TRANSPORT(t, r, cl) unref_transport(t, cl)
-static void unref_transport(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list) {
- if (!gpr_unref(&t->refs)) return;
- destruct_transport(t, closure_list);
+static void
+unref_transport (grpc_chttp2_transport * t, grpc_closure_list * closure_list)
+{
+ if (!gpr_unref (&t->refs))
+ return;
+ destruct_transport (t, closure_list);
}
-static void ref_transport(grpc_chttp2_transport *t) { gpr_ref(&t->refs); }
+static void
+ref_transport (grpc_chttp2_transport * t)
+{
+ gpr_ref (&t->refs);
+}
#endif
-static void init_transport(grpc_chttp2_transport *t,
- const grpc_channel_args *channel_args,
- grpc_endpoint *ep, grpc_mdctx *mdctx,
- gpr_uint8 is_client,
- grpc_closure_list *closure_list) {
+static void
+init_transport (grpc_chttp2_transport * t, const grpc_channel_args * channel_args, grpc_endpoint * ep, grpc_mdctx * mdctx, gpr_uint8 is_client, grpc_closure_list * closure_list)
+{
size_t i;
int j;
- GPR_ASSERT(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) ==
- GRPC_CHTTP2_CLIENT_CONNECT_STRLEN);
+ GPR_ASSERT (strlen (GRPC_CHTTP2_CLIENT_CONNECT_STRING) == GRPC_CHTTP2_CLIENT_CONNECT_STRLEN);
- memset(t, 0, sizeof(*t));
+ memset (t, 0, sizeof (*t));
t->base.vtable = &vtable;
t->ep = ep;
/* one ref is for destroy, the other for when ep becomes NULL */
- gpr_ref_init(&t->refs, 2);
+ gpr_ref_init (&t->refs, 2);
/* ref is dropped at transport close() */
- gpr_ref_init(&t->shutdown_ep_refs, 1);
- gpr_mu_init(&t->mu);
- grpc_mdctx_ref(mdctx);
- t->peer_string = grpc_endpoint_get_peer(ep);
+ gpr_ref_init (&t->shutdown_ep_refs, 1);
+ gpr_mu_init (&t->mu);
+ grpc_mdctx_ref (mdctx);
+ t->peer_string = grpc_endpoint_get_peer (ep);
t->metadata_context = mdctx;
t->endpoint_reading = 1;
t->global.next_stream_id = is_client ? 1 : 2;
@@ -250,51 +234,46 @@ static void init_transport(grpc_chttp2_transport *t,
t->global.ping_counter = 1;
t->global.pings.next = t->global.pings.prev = &t->global.pings;
t->parsing.is_client = is_client;
- t->parsing.str_grpc_timeout =
- grpc_mdstr_from_string(t->metadata_context, "grpc-timeout", 0);
- t->parsing.deframe_state =
- is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0;
+ t->parsing.str_grpc_timeout = grpc_mdstr_from_string (t->metadata_context, "grpc-timeout", 0);
+ t->parsing.deframe_state = is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0;
t->writing.is_client = is_client;
- grpc_connectivity_state_init(
- &t->channel_callback.state_tracker, GRPC_CHANNEL_READY,
- is_client ? "client_transport" : "server_transport");
-
- gpr_slice_buffer_init(&t->global.qbuf);
-
- gpr_slice_buffer_init(&t->writing.outbuf);
- grpc_chttp2_hpack_compressor_init(&t->writing.hpack_compressor, mdctx);
- grpc_closure_init(&t->writing_action, writing_action, t);
-
- gpr_slice_buffer_init(&t->parsing.qbuf);
- grpc_chttp2_goaway_parser_init(&t->parsing.goaway_parser);
- grpc_chttp2_hpack_parser_init(&t->parsing.hpack_parser, t->metadata_context);
-
- grpc_closure_init(&t->writing.done_cb, grpc_chttp2_terminate_writing,
- &t->writing);
- grpc_closure_init(&t->recv_data, recv_data, t);
- gpr_slice_buffer_init(&t->read_buffer);
-
- if (is_client) {
- gpr_slice_buffer_add(
- &t->global.qbuf,
- gpr_slice_from_copied_string(GRPC_CHTTP2_CLIENT_CONNECT_STRING));
- }
+ grpc_connectivity_state_init (&t->channel_callback.state_tracker, GRPC_CHANNEL_READY, is_client ? "client_transport" : "server_transport");
+
+ gpr_slice_buffer_init (&t->global.qbuf);
+
+ gpr_slice_buffer_init (&t->writing.outbuf);
+ grpc_chttp2_hpack_compressor_init (&t->writing.hpack_compressor, mdctx);
+ grpc_closure_init (&t->writing_action, writing_action, t);
+
+ gpr_slice_buffer_init (&t->parsing.qbuf);
+ grpc_chttp2_goaway_parser_init (&t->parsing.goaway_parser);
+ grpc_chttp2_hpack_parser_init (&t->parsing.hpack_parser, t->metadata_context);
+
+ grpc_closure_init (&t->writing.done_cb, grpc_chttp2_terminate_writing, &t->writing);
+ grpc_closure_init (&t->recv_data, recv_data, t);
+ gpr_slice_buffer_init (&t->read_buffer);
+
+ if (is_client)
+ {
+ gpr_slice_buffer_add (&t->global.qbuf, gpr_slice_from_copied_string (GRPC_CHTTP2_CLIENT_CONNECT_STRING));
+ }
/* 8 is a random stab in the dark as to a good initial size: it's small enough
that it shouldn't waste memory for infrequently used connections, yet
large enough that the exponential growth should happen nicely when it's
needed.
TODO(ctiller): tune this */
- grpc_chttp2_stream_map_init(&t->parsing_stream_map, 8);
- grpc_chttp2_stream_map_init(&t->new_stream_map, 8);
+ grpc_chttp2_stream_map_init (&t->parsing_stream_map, 8);
+ grpc_chttp2_stream_map_init (&t->new_stream_map, 8);
/* copy in initial settings to all setting sets */
- for (i = 0; i < GRPC_CHTTP2_NUM_SETTINGS; i++) {
- t->parsing.settings[i] = grpc_chttp2_settings_parameters[i].default_value;
- for (j = 0; j < GRPC_NUM_SETTING_SETS; j++) {
- t->global.settings[j][i] =
- grpc_chttp2_settings_parameters[i].default_value;
+ for (i = 0; i < GRPC_CHTTP2_NUM_SETTINGS; i++)
+ {
+ t->parsing.settings[i] = grpc_chttp2_settings_parameters[i].default_value;
+ for (j = 0; j < GRPC_NUM_SETTING_SETS; j++)
+ {
+ t->global.settings[j][i] = grpc_chttp2_settings_parameters[i].default_value;
+ }
}
- }
t->global.dirtied_local_settings = 1;
/* Hack: it's common for implementations to assume 65536 bytes initial send
window -- this should by rights be 0 */
@@ -302,207 +281,220 @@ static void init_transport(grpc_chttp2_transport *t,
t->global.sent_local_settings = 0;
/* configure http2 the way we like it */
- if (is_client) {
- push_setting(t, GRPC_CHTTP2_SETTINGS_ENABLE_PUSH, 0);
- push_setting(t, GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 0);
- }
- push_setting(t, GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, DEFAULT_WINDOW);
-
- if (channel_args) {
- for (i = 0; i < channel_args->num_args; i++) {
- if (0 ==
- strcmp(channel_args->args[i].key, GRPC_ARG_MAX_CONCURRENT_STREAMS)) {
- if (is_client) {
- gpr_log(GPR_ERROR, "%s: is ignored on the client",
- GRPC_ARG_MAX_CONCURRENT_STREAMS);
- } else if (channel_args->args[i].type != GRPC_ARG_INTEGER) {
- gpr_log(GPR_ERROR, "%s: must be an integer",
- GRPC_ARG_MAX_CONCURRENT_STREAMS);
- } else {
- push_setting(t, GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS,
- (gpr_uint32)channel_args->args[i].value.integer);
- }
- } else if (0 == strcmp(channel_args->args[i].key,
- GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER)) {
- if (channel_args->args[i].type != GRPC_ARG_INTEGER) {
- gpr_log(GPR_ERROR, "%s: must be an integer",
- GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER);
- } else if ((t->global.next_stream_id & 1) !=
- (channel_args->args[i].value.integer & 1)) {
- gpr_log(GPR_ERROR, "%s: low bit must be %d on %s",
- GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER,
- t->global.next_stream_id & 1,
- is_client ? "client" : "server");
- } else {
- t->global.next_stream_id =
- (gpr_uint32)channel_args->args[i].value.integer;
- }
- }
+ if (is_client)
+ {
+ push_setting (t, GRPC_CHTTP2_SETTINGS_ENABLE_PUSH, 0);
+ push_setting (t, GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 0);
+ }
+ push_setting (t, GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, DEFAULT_WINDOW);
+
+ if (channel_args)
+ {
+ for (i = 0; i < channel_args->num_args; i++)
+ {
+ if (0 == strcmp (channel_args->args[i].key, GRPC_ARG_MAX_CONCURRENT_STREAMS))
+ {
+ if (is_client)
+ {
+ gpr_log (GPR_ERROR, "%s: is ignored on the client", GRPC_ARG_MAX_CONCURRENT_STREAMS);
+ }
+ else if (channel_args->args[i].type != GRPC_ARG_INTEGER)
+ {
+ gpr_log (GPR_ERROR, "%s: must be an integer", GRPC_ARG_MAX_CONCURRENT_STREAMS);
+ }
+ else
+ {
+ push_setting (t, GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, (gpr_uint32) channel_args->args[i].value.integer);
+ }
+ }
+ else if (0 == strcmp (channel_args->args[i].key, GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER))
+ {
+ if (channel_args->args[i].type != GRPC_ARG_INTEGER)
+ {
+ gpr_log (GPR_ERROR, "%s: must be an integer", GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER);
+ }
+ else if ((t->global.next_stream_id & 1) !=(channel_args->args[i].value.integer & 1))
+ {
+ gpr_log (GPR_ERROR, "%s: low bit must be %d on %s", GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER, t->global.next_stream_id & 1, is_client ? "client" : "server");
+ }
+ else
+ {
+ t->global.next_stream_id = (gpr_uint32) channel_args->args[i].value.integer;
+ }
+ }
+ }
}
- }
}
-static void destroy_transport(grpc_transport *gt,
- grpc_closure_list *closure_list) {
- grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
+static void
+destroy_transport (grpc_transport * gt, grpc_closure_list * closure_list)
+{
+ grpc_chttp2_transport *t = (grpc_chttp2_transport *) gt;
- lock(t);
+ lock (t);
t->destroying = 1;
- drop_connection(t, closure_list);
- unlock(t, closure_list);
+ drop_connection (t, closure_list);
+ unlock (t, closure_list);
- UNREF_TRANSPORT(t, "destroy", closure_list);
+ UNREF_TRANSPORT (t, "destroy", closure_list);
}
/** block grpc_endpoint_shutdown being called until a paired
allow_endpoint_shutdown is made */
-static void prevent_endpoint_shutdown(grpc_chttp2_transport *t) {
- GPR_ASSERT(t->ep);
- gpr_ref(&t->shutdown_ep_refs);
+static void
+prevent_endpoint_shutdown (grpc_chttp2_transport * t)
+{
+ GPR_ASSERT (t->ep);
+ gpr_ref (&t->shutdown_ep_refs);
}
-static void allow_endpoint_shutdown_locked(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list) {
- if (gpr_unref(&t->shutdown_ep_refs)) {
- if (t->ep) {
- grpc_endpoint_shutdown(t->ep, closure_list);
+static void
+allow_endpoint_shutdown_locked (grpc_chttp2_transport * t, grpc_closure_list * closure_list)
+{
+ if (gpr_unref (&t->shutdown_ep_refs))
+ {
+ if (t->ep)
+ {
+ grpc_endpoint_shutdown (t->ep, closure_list);
+ }
}
- }
}
-static void allow_endpoint_shutdown_unlocked(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list) {
- if (gpr_unref(&t->shutdown_ep_refs)) {
- gpr_mu_lock(&t->mu);
- if (t->ep) {
- grpc_endpoint_shutdown(t->ep, closure_list);
+static void
+allow_endpoint_shutdown_unlocked (grpc_chttp2_transport * t, grpc_closure_list * closure_list)
+{
+ if (gpr_unref (&t->shutdown_ep_refs))
+ {
+ gpr_mu_lock (&t->mu);
+ if (t->ep)
+ {
+ grpc_endpoint_shutdown (t->ep, closure_list);
+ }
+ gpr_mu_unlock (&t->mu);
}
- gpr_mu_unlock(&t->mu);
- }
}
-static void destroy_endpoint(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list) {
- grpc_endpoint_destroy(t->ep, closure_list);
+static void
+destroy_endpoint (grpc_chttp2_transport * t, grpc_closure_list * closure_list)
+{
+ grpc_endpoint_destroy (t->ep, closure_list);
t->ep = NULL;
/* safe because we'll still have the ref for write */
- UNREF_TRANSPORT(t, "disconnect", closure_list);
+ UNREF_TRANSPORT (t, "disconnect", closure_list);
}
-static void close_transport_locked(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list) {
- if (!t->closed) {
- t->closed = 1;
- connectivity_state_set(&t->global, GRPC_CHANNEL_FATAL_FAILURE,
- "close_transport", closure_list);
- if (t->ep) {
- allow_endpoint_shutdown_locked(t, closure_list);
+static void
+close_transport_locked (grpc_chttp2_transport * t, grpc_closure_list * closure_list)
+{
+ if (!t->closed)
+ {
+ t->closed = 1;
+ connectivity_state_set (&t->global, GRPC_CHANNEL_FATAL_FAILURE, "close_transport", closure_list);
+ if (t->ep)
+ {
+ allow_endpoint_shutdown_locked (t, closure_list);
+ }
}
- }
}
-static int init_stream(grpc_transport *gt, grpc_stream *gs,
- const void *server_data,
- grpc_transport_stream_op *initial_op,
- grpc_closure_list *closure_list) {
- grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
- grpc_chttp2_stream *s = (grpc_chttp2_stream *)gs;
-
- memset(s, 0, sizeof(*s));
-
- grpc_chttp2_incoming_metadata_buffer_init(&s->parsing.incoming_metadata);
- grpc_chttp2_incoming_metadata_buffer_init(&s->global.incoming_metadata);
- grpc_sopb_init(&s->writing.sopb);
- grpc_sopb_init(&s->global.incoming_sopb);
- grpc_chttp2_data_parser_init(&s->parsing.data_parser);
-
- REF_TRANSPORT(t, "stream");
-
- lock(t);
- grpc_chttp2_register_stream(t, s);
- if (server_data) {
- GPR_ASSERT(t->parsing_active);
- s->global.id = (gpr_uint32)(gpr_uintptr)server_data;
- s->global.outgoing_window =
- t->global.settings[GRPC_PEER_SETTINGS]
- [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
- s->global.max_recv_bytes = s->parsing.incoming_window =
- s->global.incoming_window =
- t->global.settings[GRPC_SENT_SETTINGS]
- [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
- *t->accepting_stream = s;
- grpc_chttp2_stream_map_add(&t->parsing_stream_map, s->global.id, s);
- s->global.in_stream_map = 1;
- }
+static int
+init_stream (grpc_transport * gt, grpc_stream * gs, const void *server_data, grpc_transport_stream_op * initial_op, grpc_closure_list * closure_list)
+{
+ grpc_chttp2_transport *t = (grpc_chttp2_transport *) gt;
+ grpc_chttp2_stream *s = (grpc_chttp2_stream *) gs;
+
+ memset (s, 0, sizeof (*s));
+
+ grpc_chttp2_incoming_metadata_buffer_init (&s->parsing.incoming_metadata);
+ grpc_chttp2_incoming_metadata_buffer_init (&s->global.incoming_metadata);
+ grpc_sopb_init (&s->writing.sopb);
+ grpc_sopb_init (&s->global.incoming_sopb);
+ grpc_chttp2_data_parser_init (&s->parsing.data_parser);
+
+ REF_TRANSPORT (t, "stream");
+
+ lock (t);
+ grpc_chttp2_register_stream (t, s);
+ if (server_data)
+ {
+ GPR_ASSERT (t->parsing_active);
+ s->global.id = (gpr_uint32) (gpr_uintptr) server_data;
+ s->global.outgoing_window = t->global.settings[GRPC_PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
+ s->global.max_recv_bytes = s->parsing.incoming_window = s->global.incoming_window = t->global.settings[GRPC_SENT_SETTINGS][GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
+ *t->accepting_stream = s;
+ grpc_chttp2_stream_map_add (&t->parsing_stream_map, s->global.id, s);
+ s->global.in_stream_map = 1;
+ }
if (initial_op)
- perform_stream_op_locked(&t->global, &s->global, initial_op, closure_list);
- unlock(t, closure_list);
+ perform_stream_op_locked (&t->global, &s->global, initial_op, closure_list);
+ unlock (t, closure_list);
return 0;
}
-static void destroy_stream(grpc_transport *gt, grpc_stream *gs,
- grpc_closure_list *closure_list) {
- grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
- grpc_chttp2_stream *s = (grpc_chttp2_stream *)gs;
+static void
+destroy_stream (grpc_transport * gt, grpc_stream * gs, grpc_closure_list * closure_list)
+{
+ grpc_chttp2_transport *t = (grpc_chttp2_transport *) gt;
+ grpc_chttp2_stream *s = (grpc_chttp2_stream *) gs;
int i;
- gpr_mu_lock(&t->mu);
-
- GPR_ASSERT(s->global.published_state == GRPC_STREAM_CLOSED ||
- s->global.id == 0);
- GPR_ASSERT(!s->global.in_stream_map);
- if (grpc_chttp2_unregister_stream(t, s) && t->global.sent_goaway) {
- close_transport_locked(t, closure_list);
- }
- if (!t->parsing_active && s->global.id) {
- GPR_ASSERT(grpc_chttp2_stream_map_find(&t->parsing_stream_map,
- s->global.id) == NULL);
- }
-
- grpc_chttp2_list_remove_incoming_window_updated(&t->global, &s->global);
- grpc_chttp2_list_remove_writable_stream(&t->global, &s->global);
-
- gpr_mu_unlock(&t->mu);
-
- for (i = 0; i < STREAM_LIST_COUNT; i++) {
- if (s->included[i]) {
- gpr_log(GPR_ERROR, "%s stream %d still included in list %d",
- t->global.is_client ? "client" : "server", s->global.id, i);
- abort();
+ gpr_mu_lock (&t->mu);
+
+ GPR_ASSERT (s->global.published_state == GRPC_STREAM_CLOSED || s->global.id == 0);
+ GPR_ASSERT (!s->global.in_stream_map);
+ if (grpc_chttp2_unregister_stream (t, s) && t->global.sent_goaway)
+ {
+ close_transport_locked (t, closure_list);
+ }
+ if (!t->parsing_active && s->global.id)
+ {
+ GPR_ASSERT (grpc_chttp2_stream_map_find (&t->parsing_stream_map, s->global.id) == NULL);
+ }
+
+ grpc_chttp2_list_remove_incoming_window_updated (&t->global, &s->global);
+ grpc_chttp2_list_remove_writable_stream (&t->global, &s->global);
+
+ gpr_mu_unlock (&t->mu);
+
+ for (i = 0; i < STREAM_LIST_COUNT; i++)
+ {
+ if (s->included[i])
+ {
+ gpr_log (GPR_ERROR, "%s stream %d still included in list %d", t->global.is_client ? "client" : "server", s->global.id, i);
+ abort ();
+ }
}
- }
-
- GPR_ASSERT(s->global.outgoing_sopb == NULL);
- GPR_ASSERT(s->global.publish_sopb == NULL);
- grpc_sopb_destroy(&s->writing.sopb);
- grpc_sopb_destroy(&s->global.incoming_sopb);
- grpc_chttp2_data_parser_destroy(&s->parsing.data_parser);
- grpc_chttp2_incoming_metadata_buffer_destroy(&s->parsing.incoming_metadata);
- grpc_chttp2_incoming_metadata_buffer_destroy(&s->global.incoming_metadata);
- grpc_chttp2_incoming_metadata_live_op_buffer_end(
- &s->global.outstanding_metadata);
-
- UNREF_TRANSPORT(t, "stream", closure_list);
+
+ GPR_ASSERT (s->global.outgoing_sopb == NULL);
+ GPR_ASSERT (s->global.publish_sopb == NULL);
+ grpc_sopb_destroy (&s->writing.sopb);
+ grpc_sopb_destroy (&s->global.incoming_sopb);
+ grpc_chttp2_data_parser_destroy (&s->parsing.data_parser);
+ grpc_chttp2_incoming_metadata_buffer_destroy (&s->parsing.incoming_metadata);
+ grpc_chttp2_incoming_metadata_buffer_destroy (&s->global.incoming_metadata);
+ grpc_chttp2_incoming_metadata_live_op_buffer_end (&s->global.outstanding_metadata);
+
+ UNREF_TRANSPORT (t, "stream", closure_list);
}
-grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream(
- grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id) {
- grpc_chttp2_transport *t = TRANSPORT_FROM_PARSING(transport_parsing);
- grpc_chttp2_stream *s =
- grpc_chttp2_stream_map_find(&t->parsing_stream_map, id);
+grpc_chttp2_stream_parsing *
+grpc_chttp2_parsing_lookup_stream (grpc_chttp2_transport_parsing * transport_parsing, gpr_uint32 id)
+{
+ grpc_chttp2_transport *t = TRANSPORT_FROM_PARSING (transport_parsing);
+ grpc_chttp2_stream *s = grpc_chttp2_stream_map_find (&t->parsing_stream_map, id);
return s ? &s->parsing : NULL;
}
-grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream(
- grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id) {
+grpc_chttp2_stream_parsing *
+grpc_chttp2_parsing_accept_stream (grpc_chttp2_transport_parsing * transport_parsing, gpr_uint32 id)
+{
grpc_chttp2_stream *accepting;
- grpc_chttp2_transport *t = TRANSPORT_FROM_PARSING(transport_parsing);
- GPR_ASSERT(t->accepting_stream == NULL);
+ grpc_chttp2_transport *t = TRANSPORT_FROM_PARSING (transport_parsing);
+ GPR_ASSERT (t->accepting_stream == NULL);
t->accepting_stream = &accepting;
- t->channel_callback.accept_stream(t->channel_callback.accept_stream_user_data,
- &t->base, (void *)(gpr_uintptr)id);
+ t->channel_callback.accept_stream (t->channel_callback.accept_stream_user_data, &t->base, (void *) (gpr_uintptr) id);
t->accepting_stream = NULL;
return &accepting->parsing;
}
@@ -517,469 +509,467 @@ grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream(
is always queued, as are callbacks to process data. During unlock() we
check our todo lists and initiate callbacks and flush writes. */
-static void lock(grpc_chttp2_transport *t) { gpr_mu_lock(&t->mu); }
+static void
+lock (grpc_chttp2_transport * t)
+{
+ gpr_mu_lock (&t->mu);
+}
-static void unlock(grpc_chttp2_transport *t, grpc_closure_list *closure_list) {
- unlock_check_read_write_state(t, closure_list);
- if (!t->writing_active && !t->closed &&
- grpc_chttp2_unlocking_check_writes(&t->global, &t->writing)) {
- t->writing_active = 1;
- REF_TRANSPORT(t, "writing");
- grpc_closure_list_add(closure_list, &t->writing_action, 1);
- prevent_endpoint_shutdown(t);
- }
+static void
+unlock (grpc_chttp2_transport * t, grpc_closure_list * closure_list)
+{
+ unlock_check_read_write_state (t, closure_list);
+ if (!t->writing_active && !t->closed && grpc_chttp2_unlocking_check_writes (&t->global, &t->writing))
+ {
+ t->writing_active = 1;
+ REF_TRANSPORT (t, "writing");
+ grpc_closure_list_add (closure_list, &t->writing_action, 1);
+ prevent_endpoint_shutdown (t);
+ }
- gpr_mu_unlock(&t->mu);
+ gpr_mu_unlock (&t->mu);
}
/*
* OUTPUT PROCESSING
*/
-static void push_setting(grpc_chttp2_transport *t, grpc_chttp2_setting_id id,
- gpr_uint32 value) {
- const grpc_chttp2_setting_parameters *sp =
- &grpc_chttp2_settings_parameters[id];
- gpr_uint32 use_value = GPR_CLAMP(value, sp->min_value, sp->max_value);
- if (use_value != value) {
- gpr_log(GPR_INFO, "Requested parameter %s clamped from %d to %d", sp->name,
- value, use_value);
- }
- if (use_value != t->global.settings[GRPC_LOCAL_SETTINGS][id]) {
- t->global.settings[GRPC_LOCAL_SETTINGS][id] = use_value;
- t->global.dirtied_local_settings = 1;
- }
+static void
+push_setting (grpc_chttp2_transport * t, grpc_chttp2_setting_id id, gpr_uint32 value)
+{
+ const grpc_chttp2_setting_parameters *sp = &grpc_chttp2_settings_parameters[id];
+ gpr_uint32 use_value = GPR_CLAMP (value, sp->min_value, sp->max_value);
+ if (use_value != value)
+ {
+ gpr_log (GPR_INFO, "Requested parameter %s clamped from %d to %d", sp->name, value, use_value);
+ }
+ if (use_value != t->global.settings[GRPC_LOCAL_SETTINGS][id])
+ {
+ t->global.settings[GRPC_LOCAL_SETTINGS][id] = use_value;
+ t->global.dirtied_local_settings = 1;
+ }
}
-void grpc_chttp2_terminate_writing(void *transport_writing_ptr, int success,
- grpc_closure_list *closure_list) {
+void
+grpc_chttp2_terminate_writing (void *transport_writing_ptr, int success, grpc_closure_list * closure_list)
+{
grpc_chttp2_transport_writing *transport_writing = transport_writing_ptr;
- grpc_chttp2_transport *t = TRANSPORT_FROM_WRITING(transport_writing);
+ grpc_chttp2_transport *t = TRANSPORT_FROM_WRITING (transport_writing);
- lock(t);
+ lock (t);
- allow_endpoint_shutdown_locked(t, closure_list);
+ allow_endpoint_shutdown_locked (t, closure_list);
- if (!success) {
- drop_connection(t, closure_list);
- }
+ if (!success)
+ {
+ drop_connection (t, closure_list);
+ }
/* cleanup writing related jazz */
- grpc_chttp2_cleanup_writing(&t->global, &t->writing, closure_list);
+ grpc_chttp2_cleanup_writing (&t->global, &t->writing, closure_list);
/* leave the writing flag up on shutdown to prevent further writes in unlock()
from starting */
t->writing_active = 0;
- if (t->ep && !t->endpoint_reading) {
- destroy_endpoint(t, closure_list);
- }
+ if (t->ep && !t->endpoint_reading)
+ {
+ destroy_endpoint (t, closure_list);
+ }
- unlock(t, closure_list);
+ unlock (t, closure_list);
- UNREF_TRANSPORT(t, "writing", closure_list);
+ UNREF_TRANSPORT (t, "writing", closure_list);
}
-static void writing_action(void *gt, int iomgr_success_ignored,
- grpc_closure_list *closure_list) {
+static void
+writing_action (void *gt, int iomgr_success_ignored, grpc_closure_list * closure_list)
+{
grpc_chttp2_transport *t = gt;
- grpc_chttp2_perform_writes(&t->writing, t->ep, closure_list);
+ grpc_chttp2_perform_writes (&t->writing, t->ep, closure_list);
}
-void grpc_chttp2_add_incoming_goaway(
- grpc_chttp2_transport_global *transport_global, gpr_uint32 goaway_error,
- gpr_slice goaway_text, grpc_closure_list *closure_list) {
- char *msg = gpr_dump_slice(goaway_text, GPR_DUMP_HEX | GPR_DUMP_ASCII);
- gpr_log(GPR_DEBUG, "got goaway [%d]: %s", goaway_error, msg);
- gpr_free(msg);
- gpr_slice_unref(goaway_text);
+void
+grpc_chttp2_add_incoming_goaway (grpc_chttp2_transport_global * transport_global, gpr_uint32 goaway_error, gpr_slice goaway_text, grpc_closure_list * closure_list)
+{
+ char *msg = gpr_dump_slice (goaway_text, GPR_DUMP_HEX | GPR_DUMP_ASCII);
+ gpr_log (GPR_DEBUG, "got goaway [%d]: %s", goaway_error, msg);
+ gpr_free (msg);
+ gpr_slice_unref (goaway_text);
transport_global->seen_goaway = 1;
- connectivity_state_set(transport_global, GRPC_CHANNEL_FATAL_FAILURE,
- "got_goaway", closure_list);
+ connectivity_state_set (transport_global, GRPC_CHANNEL_FATAL_FAILURE, "got_goaway", closure_list);
}
-static void maybe_start_some_streams(
- grpc_chttp2_transport_global *transport_global,
- grpc_closure_list *closure_list) {
+static void
+maybe_start_some_streams (grpc_chttp2_transport_global * transport_global, grpc_closure_list * closure_list)
+{
grpc_chttp2_stream_global *stream_global;
/* start streams where we have free grpc_chttp2_stream ids and free
* concurrency */
- while (transport_global->next_stream_id <= MAX_CLIENT_STREAM_ID &&
- transport_global->concurrent_stream_count <
- transport_global
- ->settings[GRPC_PEER_SETTINGS]
- [GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] &&
- grpc_chttp2_list_pop_waiting_for_concurrency(transport_global,
- &stream_global)) {
- GRPC_CHTTP2_IF_TRACING(gpr_log(
- GPR_DEBUG, "HTTP:%s: Allocating new grpc_chttp2_stream %p to id %d",
- transport_global->is_client ? "CLI" : "SVR", stream_global,
- transport_global->next_stream_id));
-
- GPR_ASSERT(stream_global->id == 0);
- stream_global->id = transport_global->next_stream_id;
- transport_global->next_stream_id += 2;
-
- if (transport_global->next_stream_id >= MAX_CLIENT_STREAM_ID) {
- connectivity_state_set(transport_global, GRPC_CHANNEL_TRANSIENT_FAILURE,
- "no_more_stream_ids", closure_list);
+ while (transport_global->next_stream_id <= MAX_CLIENT_STREAM_ID && transport_global->concurrent_stream_count < transport_global->settings[GRPC_PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] && grpc_chttp2_list_pop_waiting_for_concurrency (transport_global, &stream_global))
+ {
+ GRPC_CHTTP2_IF_TRACING (gpr_log (GPR_DEBUG, "HTTP:%s: Allocating new grpc_chttp2_stream %p to id %d", transport_global->is_client ? "CLI" : "SVR", stream_global, transport_global->next_stream_id));
+
+ GPR_ASSERT (stream_global->id == 0);
+ stream_global->id = transport_global->next_stream_id;
+ transport_global->next_stream_id += 2;
+
+ if (transport_global->next_stream_id >= MAX_CLIENT_STREAM_ID)
+ {
+ connectivity_state_set (transport_global, GRPC_CHANNEL_TRANSIENT_FAILURE, "no_more_stream_ids", closure_list);
+ }
+
+ stream_global->outgoing_window = transport_global->settings[GRPC_PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
+ stream_global->incoming_window = transport_global->settings[GRPC_SENT_SETTINGS][GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
+ stream_global->max_recv_bytes = GPR_MAX (stream_global->incoming_window, stream_global->max_recv_bytes);
+ grpc_chttp2_stream_map_add (&TRANSPORT_FROM_GLOBAL (transport_global)->new_stream_map, stream_global->id, STREAM_FROM_GLOBAL (stream_global));
+ stream_global->in_stream_map = 1;
+ transport_global->concurrent_stream_count++;
+ grpc_chttp2_list_add_incoming_window_updated (transport_global, stream_global);
+ grpc_chttp2_list_add_writable_stream (transport_global, stream_global);
}
-
- stream_global->outgoing_window =
- transport_global->settings[GRPC_PEER_SETTINGS]
- [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
- stream_global->incoming_window =
- transport_global->settings[GRPC_SENT_SETTINGS]
- [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
- stream_global->max_recv_bytes =
- GPR_MAX(stream_global->incoming_window, stream_global->max_recv_bytes);
- grpc_chttp2_stream_map_add(
- &TRANSPORT_FROM_GLOBAL(transport_global)->new_stream_map,
- stream_global->id, STREAM_FROM_GLOBAL(stream_global));
- stream_global->in_stream_map = 1;
- transport_global->concurrent_stream_count++;
- grpc_chttp2_list_add_incoming_window_updated(transport_global,
- stream_global);
- grpc_chttp2_list_add_writable_stream(transport_global, stream_global);
- }
/* cancel out streams that will never be started */
- while (transport_global->next_stream_id >= MAX_CLIENT_STREAM_ID &&
- grpc_chttp2_list_pop_waiting_for_concurrency(transport_global,
- &stream_global)) {
- cancel_from_api(transport_global, stream_global, GRPC_STATUS_UNAVAILABLE);
- }
+ while (transport_global->next_stream_id >= MAX_CLIENT_STREAM_ID && grpc_chttp2_list_pop_waiting_for_concurrency (transport_global, &stream_global))
+ {
+ cancel_from_api (transport_global, stream_global, GRPC_STATUS_UNAVAILABLE);
+ }
}
-static void perform_stream_op_locked(
- grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global, grpc_transport_stream_op *op,
- grpc_closure_list *closure_list) {
- if (op->cancel_with_status != GRPC_STATUS_OK) {
- cancel_from_api(transport_global, stream_global, op->cancel_with_status);
- }
-
- if (op->close_with_status != GRPC_STATUS_OK) {
- close_from_api(transport_global, stream_global, op->close_with_status,
- op->optional_close_message);
- }
-
- if (op->send_ops) {
- GPR_ASSERT(stream_global->outgoing_sopb == NULL);
- stream_global->send_done_closure = op->on_done_send;
- if (!stream_global->cancelled) {
- stream_global->written_anything = 1;
- stream_global->outgoing_sopb = op->send_ops;
- if (op->is_last_send &&
- stream_global->write_state == GRPC_WRITE_STATE_OPEN) {
- stream_global->write_state = GRPC_WRITE_STATE_QUEUED_CLOSE;
- }
- if (stream_global->id == 0) {
- GRPC_CHTTP2_IF_TRACING(gpr_log(
- GPR_DEBUG,
- "HTTP:%s: New grpc_chttp2_stream %p waiting for concurrency",
- transport_global->is_client ? "CLI" : "SVR", stream_global));
- grpc_chttp2_list_add_waiting_for_concurrency(transport_global,
- stream_global);
- maybe_start_some_streams(transport_global, closure_list);
- } else if (stream_global->outgoing_window > 0) {
- grpc_chttp2_list_add_writable_stream(transport_global, stream_global);
- }
- } else {
- grpc_sopb_reset(op->send_ops);
- grpc_closure_list_add(closure_list, stream_global->send_done_closure, 0);
+static void
+perform_stream_op_locked (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global, grpc_transport_stream_op * op, grpc_closure_list * closure_list)
+{
+ if (op->cancel_with_status != GRPC_STATUS_OK)
+ {
+ cancel_from_api (transport_global, stream_global, op->cancel_with_status);
+ }
+
+ if (op->close_with_status != GRPC_STATUS_OK)
+ {
+ close_from_api (transport_global, stream_global, op->close_with_status, op->optional_close_message);
}
- }
-
- if (op->recv_ops) {
- GPR_ASSERT(stream_global->publish_sopb == NULL);
- GPR_ASSERT(stream_global->published_state != GRPC_STREAM_CLOSED);
- stream_global->recv_done_closure = op->on_done_recv;
- stream_global->publish_sopb = op->recv_ops;
- stream_global->publish_sopb->nops = 0;
- stream_global->publish_state = op->recv_state;
- /* clamp max recv bytes */
- op->max_recv_bytes = GPR_MIN(op->max_recv_bytes, GPR_UINT32_MAX);
- if (stream_global->max_recv_bytes < op->max_recv_bytes) {
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "op", transport_global, stream_global, max_recv_bytes,
- op->max_recv_bytes - stream_global->max_recv_bytes);
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
- "op", transport_global, stream_global, unannounced_incoming_window,
- op->max_recv_bytes - stream_global->max_recv_bytes);
- stream_global->unannounced_incoming_window +=
- (gpr_uint32)op->max_recv_bytes - stream_global->max_recv_bytes;
- stream_global->max_recv_bytes = (gpr_uint32)op->max_recv_bytes;
+
+ if (op->send_ops)
+ {
+ GPR_ASSERT (stream_global->outgoing_sopb == NULL);
+ stream_global->send_done_closure = op->on_done_send;
+ if (!stream_global->cancelled)
+ {
+ stream_global->written_anything = 1;
+ stream_global->outgoing_sopb = op->send_ops;
+ if (op->is_last_send && stream_global->write_state == GRPC_WRITE_STATE_OPEN)
+ {
+ stream_global->write_state = GRPC_WRITE_STATE_QUEUED_CLOSE;
+ }
+ if (stream_global->id == 0)
+ {
+ GRPC_CHTTP2_IF_TRACING (gpr_log (GPR_DEBUG, "HTTP:%s: New grpc_chttp2_stream %p waiting for concurrency", transport_global->is_client ? "CLI" : "SVR", stream_global));
+ grpc_chttp2_list_add_waiting_for_concurrency (transport_global, stream_global);
+ maybe_start_some_streams (transport_global, closure_list);
+ }
+ else if (stream_global->outgoing_window > 0)
+ {
+ grpc_chttp2_list_add_writable_stream (transport_global, stream_global);
+ }
+ }
+ else
+ {
+ grpc_sopb_reset (op->send_ops);
+ grpc_closure_list_add (closure_list, stream_global->send_done_closure, 0);
+ }
}
- grpc_chttp2_incoming_metadata_live_op_buffer_end(
- &stream_global->outstanding_metadata);
- grpc_chttp2_list_add_read_write_state_changed(transport_global,
- stream_global);
- if (stream_global->id != 0) {
- grpc_chttp2_list_add_writable_stream(transport_global, stream_global);
+
+ if (op->recv_ops)
+ {
+ GPR_ASSERT (stream_global->publish_sopb == NULL);
+ GPR_ASSERT (stream_global->published_state != GRPC_STREAM_CLOSED);
+ stream_global->recv_done_closure = op->on_done_recv;
+ stream_global->publish_sopb = op->recv_ops;
+ stream_global->publish_sopb->nops = 0;
+ stream_global->publish_state = op->recv_state;
+ /* clamp max recv bytes */
+ op->max_recv_bytes = GPR_MIN (op->max_recv_bytes, GPR_UINT32_MAX);
+ if (stream_global->max_recv_bytes < op->max_recv_bytes)
+ {
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("op", transport_global, stream_global, max_recv_bytes, op->max_recv_bytes - stream_global->max_recv_bytes);
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("op", transport_global, stream_global, unannounced_incoming_window, op->max_recv_bytes - stream_global->max_recv_bytes);
+ stream_global->unannounced_incoming_window += (gpr_uint32) op->max_recv_bytes - stream_global->max_recv_bytes;
+ stream_global->max_recv_bytes = (gpr_uint32) op->max_recv_bytes;
+ }
+ grpc_chttp2_incoming_metadata_live_op_buffer_end (&stream_global->outstanding_metadata);
+ grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global);
+ if (stream_global->id != 0)
+ {
+ grpc_chttp2_list_add_writable_stream (transport_global, stream_global);
+ }
}
- }
- if (op->bind_pollset) {
- add_to_pollset_locked(TRANSPORT_FROM_GLOBAL(transport_global),
- op->bind_pollset, closure_list);
- }
+ if (op->bind_pollset)
+ {
+ add_to_pollset_locked (TRANSPORT_FROM_GLOBAL (transport_global), op->bind_pollset, closure_list);
+ }
- grpc_closure_list_add(closure_list, op->on_consumed, 1);
+ grpc_closure_list_add (closure_list, op->on_consumed, 1);
}
-static void perform_stream_op(grpc_transport *gt, grpc_stream *gs,
- grpc_transport_stream_op *op,
- grpc_closure_list *closure_list) {
- grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
- grpc_chttp2_stream *s = (grpc_chttp2_stream *)gs;
+static void
+perform_stream_op (grpc_transport * gt, grpc_stream * gs, grpc_transport_stream_op * op, grpc_closure_list * closure_list)
+{
+ grpc_chttp2_transport *t = (grpc_chttp2_transport *) gt;
+ grpc_chttp2_stream *s = (grpc_chttp2_stream *) gs;
- lock(t);
- perform_stream_op_locked(&t->global, &s->global, op, closure_list);
- unlock(t, closure_list);
+ lock (t);
+ perform_stream_op_locked (&t->global, &s->global, op, closure_list);
+ unlock (t, closure_list);
}
-static void send_ping_locked(grpc_chttp2_transport *t, grpc_closure *on_recv) {
- grpc_chttp2_outstanding_ping *p = gpr_malloc(sizeof(*p));
+static void
+send_ping_locked (grpc_chttp2_transport * t, grpc_closure * on_recv)
+{
+ grpc_chttp2_outstanding_ping *p = gpr_malloc (sizeof (*p));
p->next = &t->global.pings;
p->prev = p->next->prev;
p->prev->next = p->next->prev = p;
- p->id[0] = (gpr_uint8)((t->global.ping_counter >> 56) & 0xff);
- p->id[1] = (gpr_uint8)((t->global.ping_counter >> 48) & 0xff);
- p->id[2] = (gpr_uint8)((t->global.ping_counter >> 40) & 0xff);
- p->id[3] = (gpr_uint8)((t->global.ping_counter >> 32) & 0xff);
- p->id[4] = (gpr_uint8)((t->global.ping_counter >> 24) & 0xff);
- p->id[5] = (gpr_uint8)((t->global.ping_counter >> 16) & 0xff);
- p->id[6] = (gpr_uint8)((t->global.ping_counter >> 8) & 0xff);
- p->id[7] = (gpr_uint8)(t->global.ping_counter & 0xff);
+ p->id[0] = (gpr_uint8) ((t->global.ping_counter >> 56) &0xff);
+ p->id[1] = (gpr_uint8) ((t->global.ping_counter >> 48) &0xff);
+ p->id[2] = (gpr_uint8) ((t->global.ping_counter >> 40) &0xff);
+ p->id[3] = (gpr_uint8) ((t->global.ping_counter >> 32) &0xff);
+ p->id[4] = (gpr_uint8) ((t->global.ping_counter >> 24) &0xff);
+ p->id[5] = (gpr_uint8) ((t->global.ping_counter >> 16) &0xff);
+ p->id[6] = (gpr_uint8) ((t->global.ping_counter >> 8) &0xff);
+ p->id[7] = (gpr_uint8) (t->global.ping_counter & 0xff);
p->on_recv = on_recv;
- gpr_slice_buffer_add(&t->global.qbuf, grpc_chttp2_ping_create(0, p->id));
+ gpr_slice_buffer_add (&t->global.qbuf, grpc_chttp2_ping_create (0, p->id));
}
-static void perform_transport_op(grpc_transport *gt, grpc_transport_op *op,
- grpc_closure_list *closure_list) {
- grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
+static void
+perform_transport_op (grpc_transport * gt, grpc_transport_op * op, grpc_closure_list * closure_list)
+{
+ grpc_chttp2_transport *t = (grpc_chttp2_transport *) gt;
int close_transport = 0;
- lock(t);
-
- grpc_closure_list_add(closure_list, op->on_consumed, 1);
-
- if (op->on_connectivity_state_change) {
- grpc_connectivity_state_notify_on_state_change(
- &t->channel_callback.state_tracker, op->connectivity_state,
- op->on_connectivity_state_change, closure_list);
- }
-
- if (op->send_goaway) {
- t->global.sent_goaway = 1;
- grpc_chttp2_goaway_append(
- t->global.last_incoming_stream_id,
- (gpr_uint32)grpc_chttp2_grpc_status_to_http2_error(op->goaway_status),
- gpr_slice_ref(*op->goaway_message), &t->global.qbuf);
- close_transport = !grpc_chttp2_has_streams(t);
- }
-
- if (op->set_accept_stream != NULL) {
- t->channel_callback.accept_stream = op->set_accept_stream;
- t->channel_callback.accept_stream_user_data =
- op->set_accept_stream_user_data;
- }
-
- if (op->bind_pollset) {
- add_to_pollset_locked(t, op->bind_pollset, closure_list);
- }
-
- if (op->bind_pollset_set) {
- add_to_pollset_set_locked(t, op->bind_pollset_set, closure_list);
- }
-
- if (op->send_ping) {
- send_ping_locked(t, op->send_ping);
- }
-
- if (op->disconnect) {
- close_transport_locked(t, closure_list);
- }
-
- unlock(t, closure_list);
-
- if (close_transport) {
- lock(t);
- close_transport_locked(t, closure_list);
- unlock(t, closure_list);
- }
+ lock (t);
+
+ grpc_closure_list_add (closure_list, op->on_consumed, 1);
+
+ if (op->on_connectivity_state_change)
+ {
+ grpc_connectivity_state_notify_on_state_change (&t->channel_callback.state_tracker, op->connectivity_state, op->on_connectivity_state_change, closure_list);
+ }
+
+ if (op->send_goaway)
+ {
+ t->global.sent_goaway = 1;
+ grpc_chttp2_goaway_append (t->global.last_incoming_stream_id, (gpr_uint32) grpc_chttp2_grpc_status_to_http2_error (op->goaway_status), gpr_slice_ref (*op->goaway_message), &t->global.qbuf);
+ close_transport = !grpc_chttp2_has_streams (t);
+ }
+
+ if (op->set_accept_stream != NULL)
+ {
+ t->channel_callback.accept_stream = op->set_accept_stream;
+ t->channel_callback.accept_stream_user_data = op->set_accept_stream_user_data;
+ }
+
+ if (op->bind_pollset)
+ {
+ add_to_pollset_locked (t, op->bind_pollset, closure_list);
+ }
+
+ if (op->bind_pollset_set)
+ {
+ add_to_pollset_set_locked (t, op->bind_pollset_set, closure_list);
+ }
+
+ if (op->send_ping)
+ {
+ send_ping_locked (t, op->send_ping);
+ }
+
+ if (op->disconnect)
+ {
+ close_transport_locked (t, closure_list);
+ }
+
+ unlock (t, closure_list);
+
+ if (close_transport)
+ {
+ lock (t);
+ close_transport_locked (t, closure_list);
+ unlock (t, closure_list);
+ }
}
/*
* INPUT PROCESSING
*/
-static grpc_stream_state compute_state(gpr_uint8 write_closed,
- gpr_uint8 read_closed) {
- if (write_closed && read_closed) return GRPC_STREAM_CLOSED;
- if (write_closed) return GRPC_STREAM_SEND_CLOSED;
- if (read_closed) return GRPC_STREAM_RECV_CLOSED;
+static grpc_stream_state
+compute_state (gpr_uint8 write_closed, gpr_uint8 read_closed)
+{
+ if (write_closed && read_closed)
+ return GRPC_STREAM_CLOSED;
+ if (write_closed)
+ return GRPC_STREAM_SEND_CLOSED;
+ if (read_closed)
+ return GRPC_STREAM_RECV_CLOSED;
return GRPC_STREAM_OPEN;
}
-static void remove_stream(grpc_chttp2_transport *t, gpr_uint32 id,
- grpc_closure_list *closure_list) {
+static void
+remove_stream (grpc_chttp2_transport * t, gpr_uint32 id, grpc_closure_list * closure_list)
+{
size_t new_stream_count;
- grpc_chttp2_stream *s =
- grpc_chttp2_stream_map_delete(&t->parsing_stream_map, id);
- if (!s) {
- s = grpc_chttp2_stream_map_delete(&t->new_stream_map, id);
- }
- grpc_chttp2_list_remove_writable_stream(&t->global, &s->global);
- GPR_ASSERT(s);
+ grpc_chttp2_stream *s = grpc_chttp2_stream_map_delete (&t->parsing_stream_map, id);
+ if (!s)
+ {
+ s = grpc_chttp2_stream_map_delete (&t->new_stream_map, id);
+ }
+ grpc_chttp2_list_remove_writable_stream (&t->global, &s->global);
+ GPR_ASSERT (s);
s->global.in_stream_map = 0;
- if (t->parsing.incoming_stream == &s->parsing) {
- t->parsing.incoming_stream = NULL;
- grpc_chttp2_parsing_become_skip_parser(&t->parsing);
- }
- if (grpc_chttp2_unregister_stream(t, s) && t->global.sent_goaway) {
- close_transport_locked(t, closure_list);
- }
-
- new_stream_count = grpc_chttp2_stream_map_size(&t->parsing_stream_map) +
- grpc_chttp2_stream_map_size(&t->new_stream_map);
- GPR_ASSERT(new_stream_count <= GPR_UINT32_MAX);
- if (new_stream_count != t->global.concurrent_stream_count) {
- t->global.concurrent_stream_count = (gpr_uint32)new_stream_count;
- maybe_start_some_streams(&t->global, closure_list);
- }
+ if (t->parsing.incoming_stream == &s->parsing)
+ {
+ t->parsing.incoming_stream = NULL;
+ grpc_chttp2_parsing_become_skip_parser (&t->parsing);
+ }
+ if (grpc_chttp2_unregister_stream (t, s) && t->global.sent_goaway)
+ {
+ close_transport_locked (t, closure_list);
+ }
+
+ new_stream_count = grpc_chttp2_stream_map_size (&t->parsing_stream_map) + grpc_chttp2_stream_map_size (&t->new_stream_map);
+ GPR_ASSERT (new_stream_count <= GPR_UINT32_MAX);
+ if (new_stream_count != t->global.concurrent_stream_count)
+ {
+ t->global.concurrent_stream_count = (gpr_uint32) new_stream_count;
+ maybe_start_some_streams (&t->global, closure_list);
+ }
}
-static void unlock_check_read_write_state(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list) {
+static void
+unlock_check_read_write_state (grpc_chttp2_transport * t, grpc_closure_list * closure_list)
+{
grpc_chttp2_transport_global *transport_global = &t->global;
grpc_chttp2_stream_global *stream_global;
grpc_stream_state state;
- if (!t->parsing_active) {
- /* if a stream is in the stream map, and gets cancelled, we need to ensure
- we are not parsing before continuing the cancellation to keep things in
- a sane state */
- while (grpc_chttp2_list_pop_closed_waiting_for_parsing(transport_global,
- &stream_global)) {
- GPR_ASSERT(stream_global->in_stream_map);
- GPR_ASSERT(stream_global->write_state != GRPC_WRITE_STATE_OPEN);
- GPR_ASSERT(stream_global->read_closed);
- remove_stream(t, stream_global->id, closure_list);
- grpc_chttp2_list_add_read_write_state_changed(transport_global,
- stream_global);
+ if (!t->parsing_active)
+ {
+ /* if a stream is in the stream map, and gets cancelled, we need to ensure
+ we are not parsing before continuing the cancellation to keep things in
+ a sane state */
+ while (grpc_chttp2_list_pop_closed_waiting_for_parsing (transport_global, &stream_global))
+ {
+ GPR_ASSERT (stream_global->in_stream_map);
+ GPR_ASSERT (stream_global->write_state != GRPC_WRITE_STATE_OPEN);
+ GPR_ASSERT (stream_global->read_closed);
+ remove_stream (t, stream_global->id, closure_list);
+ grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global);
+ }
}
- }
- if (!t->writing_active) {
- while (grpc_chttp2_list_pop_cancelled_waiting_for_writing(transport_global,
- &stream_global)) {
- grpc_chttp2_list_add_read_write_state_changed(transport_global,
- stream_global);
- }
- }
-
- while (grpc_chttp2_list_pop_read_write_state_changed(transport_global,
- &stream_global)) {
- if (stream_global->cancelled) {
- if (t->writing_active &&
- stream_global->write_state != GRPC_WRITE_STATE_SENT_CLOSE) {
- grpc_chttp2_list_add_cancelled_waiting_for_writing(transport_global,
- stream_global);
- } else {
- stream_global->write_state = GRPC_WRITE_STATE_SENT_CLOSE;
- if (stream_global->outgoing_sopb != NULL) {
- grpc_sopb_reset(stream_global->outgoing_sopb);
- stream_global->outgoing_sopb = NULL;
- grpc_closure_list_add(closure_list, stream_global->send_done_closure,
- 1);
- }
- stream_global->read_closed = 1;
- if (!stream_global->published_cancelled) {
- char buffer[GPR_LTOA_MIN_BUFSIZE];
- gpr_ltoa(stream_global->cancelled_status, buffer);
- grpc_chttp2_incoming_metadata_buffer_add(
- &stream_global->incoming_metadata,
- grpc_mdelem_from_strings(t->metadata_context, "grpc-status",
- buffer));
- grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into(
- &stream_global->incoming_metadata, &stream_global->incoming_sopb);
- stream_global->published_cancelled = 1;
- }
- }
- }
- if (stream_global->write_state == GRPC_WRITE_STATE_SENT_CLOSE &&
- stream_global->read_closed && stream_global->in_stream_map) {
- if (t->parsing_active) {
- grpc_chttp2_list_add_closed_waiting_for_parsing(transport_global,
- stream_global);
- } else {
- remove_stream(t, stream_global->id, closure_list);
- }
- }
- if (!stream_global->publish_sopb) {
- continue;
+ if (!t->writing_active)
+ {
+ while (grpc_chttp2_list_pop_cancelled_waiting_for_writing (transport_global, &stream_global))
+ {
+ grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global);
+ }
}
- if (stream_global->writing_now != 0) {
- continue;
- }
- /* FIXME(ctiller): we include in_stream_map in our computation of
- whether the stream is write-closed. This is completely bogus,
- but has the effect of delaying stream-closed until the stream
- is indeed evicted from the stream map, making it safe to delete.
- To fix this will require having an edge after stream-closed
- indicating that the stream is closed AND safe to delete. */
- state = compute_state(
- stream_global->write_state == GRPC_WRITE_STATE_SENT_CLOSE &&
- !stream_global->in_stream_map,
- stream_global->read_closed);
- if (stream_global->incoming_sopb.nops == 0 &&
- state == stream_global->published_state) {
- continue;
+
+ while (grpc_chttp2_list_pop_read_write_state_changed (transport_global, &stream_global))
+ {
+ if (stream_global->cancelled)
+ {
+ if (t->writing_active && stream_global->write_state != GRPC_WRITE_STATE_SENT_CLOSE)
+ {
+ grpc_chttp2_list_add_cancelled_waiting_for_writing (transport_global, stream_global);
+ }
+ else
+ {
+ stream_global->write_state = GRPC_WRITE_STATE_SENT_CLOSE;
+ if (stream_global->outgoing_sopb != NULL)
+ {
+ grpc_sopb_reset (stream_global->outgoing_sopb);
+ stream_global->outgoing_sopb = NULL;
+ grpc_closure_list_add (closure_list, stream_global->send_done_closure, 1);
+ }
+ stream_global->read_closed = 1;
+ if (!stream_global->published_cancelled)
+ {
+ char buffer[GPR_LTOA_MIN_BUFSIZE];
+ gpr_ltoa (stream_global->cancelled_status, buffer);
+ grpc_chttp2_incoming_metadata_buffer_add (&stream_global->incoming_metadata, grpc_mdelem_from_strings (t->metadata_context, "grpc-status", buffer));
+ grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into (&stream_global->incoming_metadata, &stream_global->incoming_sopb);
+ stream_global->published_cancelled = 1;
+ }
+ }
+ }
+ if (stream_global->write_state == GRPC_WRITE_STATE_SENT_CLOSE && stream_global->read_closed && stream_global->in_stream_map)
+ {
+ if (t->parsing_active)
+ {
+ grpc_chttp2_list_add_closed_waiting_for_parsing (transport_global, stream_global);
+ }
+ else
+ {
+ remove_stream (t, stream_global->id, closure_list);
+ }
+ }
+ if (!stream_global->publish_sopb)
+ {
+ continue;
+ }
+ if (stream_global->writing_now != 0)
+ {
+ continue;
+ }
+ /* FIXME(ctiller): we include in_stream_map in our computation of
+ whether the stream is write-closed. This is completely bogus,
+ but has the effect of delaying stream-closed until the stream
+ is indeed evicted from the stream map, making it safe to delete.
+ To fix this will require having an edge after stream-closed
+ indicating that the stream is closed AND safe to delete. */
+ state = compute_state (stream_global->write_state == GRPC_WRITE_STATE_SENT_CLOSE && !stream_global->in_stream_map, stream_global->read_closed);
+ if (stream_global->incoming_sopb.nops == 0 && state == stream_global->published_state)
+ {
+ continue;
+ }
+ grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op (&stream_global->incoming_metadata, &stream_global->incoming_sopb, &stream_global->outstanding_metadata);
+ grpc_sopb_swap (stream_global->publish_sopb, &stream_global->incoming_sopb);
+ stream_global->published_state = *stream_global->publish_state = state;
+ grpc_closure_list_add (closure_list, stream_global->recv_done_closure, 1);
+ stream_global->recv_done_closure = NULL;
+ stream_global->publish_sopb = NULL;
+ stream_global->publish_state = NULL;
}
- grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op(
- &stream_global->incoming_metadata, &stream_global->incoming_sopb,
- &stream_global->outstanding_metadata);
- grpc_sopb_swap(stream_global->publish_sopb, &stream_global->incoming_sopb);
- stream_global->published_state = *stream_global->publish_state = state;
- grpc_closure_list_add(closure_list, stream_global->recv_done_closure, 1);
- stream_global->recv_done_closure = NULL;
- stream_global->publish_sopb = NULL;
- stream_global->publish_state = NULL;
- }
}
-static void cancel_from_api(grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global,
- grpc_status_code status) {
+static void
+cancel_from_api (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global, grpc_status_code status)
+{
stream_global->cancelled = 1;
stream_global->cancelled_status = status;
- if (stream_global->id != 0) {
- gpr_slice_buffer_add(
- &transport_global->qbuf,
- grpc_chttp2_rst_stream_create(
- stream_global->id,
- (gpr_uint32)grpc_chttp2_grpc_status_to_http2_error(status)));
- }
- grpc_chttp2_list_add_read_write_state_changed(transport_global,
- stream_global);
+ if (stream_global->id != 0)
+ {
+ gpr_slice_buffer_add (&transport_global->qbuf, grpc_chttp2_rst_stream_create (stream_global->id, (gpr_uint32) grpc_chttp2_grpc_status_to_http2_error (status)));
+ }
+ grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global);
}
-static void close_from_api(grpc_chttp2_transport_global *transport_global,
- grpc_chttp2_stream_global *stream_global,
- grpc_status_code status,
- gpr_slice *optional_message) {
+static void
+close_from_api (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global, grpc_status_code status, gpr_slice * optional_message)
+{
gpr_slice hdr;
gpr_slice status_hdr;
gpr_slice message_pfx;
gpr_uint8 *p;
gpr_uint32 len = 0;
- GPR_ASSERT(status >= 0 && (int)status < 100);
+ GPR_ASSERT (status >= 0 && (int) status < 100);
stream_global->cancelled = 1;
stream_global->cancelled_status = status;
- GPR_ASSERT(stream_global->id != 0);
- GPR_ASSERT(!stream_global->written_anything);
+ GPR_ASSERT (stream_global->id != 0);
+ GPR_ASSERT (!stream_global->written_anything);
/* Hand roll a header block.
This is unnecessarily ugly - at some point we should find a more elegant
@@ -987,10 +977,10 @@ static void close_from_api(grpc_chttp2_transport_global *transport_global,
It's complicated by the fact that our send machinery would be dead by the
time we got around to sending this, so instead we ignore HPACK compression
and just write the uncompressed bytes onto the wire. */
- status_hdr = gpr_slice_malloc(15 + (status >= 10));
- p = GPR_SLICE_START_PTR(status_hdr);
- *p++ = 0x40; /* literal header */
- *p++ = 11; /* len(grpc-status) */
+ status_hdr = gpr_slice_malloc (15 + (status >= 10));
+ p = GPR_SLICE_START_PTR (status_hdr);
+ *p++ = 0x40; /* literal header */
+ *p++ = 11; /* len(grpc-status) */
*p++ = 'g';
*p++ = 'r';
*p++ = 'p';
@@ -1002,88 +992,94 @@ static void close_from_api(grpc_chttp2_transport_global *transport_global,
*p++ = 't';
*p++ = 'u';
*p++ = 's';
- if (status < 10) {
- *p++ = 1;
- *p++ = (gpr_uint8)('0' + status);
- } else {
- *p++ = 2;
- *p++ = (gpr_uint8)('0' + (status / 10));
- *p++ = (gpr_uint8)('0' + (status % 10));
- }
- GPR_ASSERT(p == GPR_SLICE_END_PTR(status_hdr));
- len += (gpr_uint32)GPR_SLICE_LENGTH(status_hdr);
-
- if (optional_message) {
- GPR_ASSERT(GPR_SLICE_LENGTH(*optional_message) < 127);
- message_pfx = gpr_slice_malloc(15);
- p = GPR_SLICE_START_PTR(message_pfx);
- *p++ = 0x40;
- *p++ = 12; /* len(grpc-message) */
- *p++ = 'g';
- *p++ = 'r';
- *p++ = 'p';
- *p++ = 'c';
- *p++ = '-';
- *p++ = 'm';
- *p++ = 'e';
- *p++ = 's';
- *p++ = 's';
- *p++ = 'a';
- *p++ = 'g';
- *p++ = 'e';
- *p++ = (gpr_uint8)GPR_SLICE_LENGTH(*optional_message);
- GPR_ASSERT(p == GPR_SLICE_END_PTR(message_pfx));
- len += (gpr_uint32)GPR_SLICE_LENGTH(message_pfx);
- len += (gpr_uint32)GPR_SLICE_LENGTH(*optional_message);
- }
-
- hdr = gpr_slice_malloc(9);
- p = GPR_SLICE_START_PTR(hdr);
- *p++ = (gpr_uint8)(len >> 16);
- *p++ = (gpr_uint8)(len >> 8);
- *p++ = (gpr_uint8)(len);
+ if (status < 10)
+ {
+ *p++ = 1;
+ *p++ = (gpr_uint8) ('0' + status);
+ }
+ else
+ {
+ *p++ = 2;
+ *p++ = (gpr_uint8) ('0' + (status / 10));
+ *p++ = (gpr_uint8) ('0' + (status % 10));
+ }
+ GPR_ASSERT (p == GPR_SLICE_END_PTR (status_hdr));
+ len += (gpr_uint32) GPR_SLICE_LENGTH (status_hdr);
+
+ if (optional_message)
+ {
+ GPR_ASSERT (GPR_SLICE_LENGTH (*optional_message) < 127);
+ message_pfx = gpr_slice_malloc (15);
+ p = GPR_SLICE_START_PTR (message_pfx);
+ *p++ = 0x40;
+ *p++ = 12; /* len(grpc-message) */
+ *p++ = 'g';
+ *p++ = 'r';
+ *p++ = 'p';
+ *p++ = 'c';
+ *p++ = '-';
+ *p++ = 'm';
+ *p++ = 'e';
+ *p++ = 's';
+ *p++ = 's';
+ *p++ = 'a';
+ *p++ = 'g';
+ *p++ = 'e';
+ *p++ = (gpr_uint8) GPR_SLICE_LENGTH (*optional_message);
+ GPR_ASSERT (p == GPR_SLICE_END_PTR (message_pfx));
+ len += (gpr_uint32) GPR_SLICE_LENGTH (message_pfx);
+ len += (gpr_uint32) GPR_SLICE_LENGTH (*optional_message);
+ }
+
+ hdr = gpr_slice_malloc (9);
+ p = GPR_SLICE_START_PTR (hdr);
+ *p++ = (gpr_uint8) (len >> 16);
+ *p++ = (gpr_uint8) (len >> 8);
+ *p++ = (gpr_uint8) (len);
*p++ = GRPC_CHTTP2_FRAME_HEADER;
*p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS;
- *p++ = (gpr_uint8)(stream_global->id >> 24);
- *p++ = (gpr_uint8)(stream_global->id >> 16);
- *p++ = (gpr_uint8)(stream_global->id >> 8);
- *p++ = (gpr_uint8)(stream_global->id);
- GPR_ASSERT(p == GPR_SLICE_END_PTR(hdr));
-
- gpr_slice_buffer_add(&transport_global->qbuf, hdr);
- gpr_slice_buffer_add(&transport_global->qbuf, status_hdr);
- if (optional_message) {
- gpr_slice_buffer_add(&transport_global->qbuf, message_pfx);
- gpr_slice_buffer_add(&transport_global->qbuf,
- gpr_slice_ref(*optional_message));
- }
-
- gpr_slice_buffer_add(
- &transport_global->qbuf,
- grpc_chttp2_rst_stream_create(stream_global->id, GRPC_CHTTP2_NO_ERROR));
-
- grpc_chttp2_list_add_read_write_state_changed(transport_global,
- stream_global);
+ *p++ = (gpr_uint8) (stream_global->id >> 24);
+ *p++ = (gpr_uint8) (stream_global->id >> 16);
+ *p++ = (gpr_uint8) (stream_global->id >> 8);
+ *p++ = (gpr_uint8) (stream_global->id);
+ GPR_ASSERT (p == GPR_SLICE_END_PTR (hdr));
+
+ gpr_slice_buffer_add (&transport_global->qbuf, hdr);
+ gpr_slice_buffer_add (&transport_global->qbuf, status_hdr);
+ if (optional_message)
+ {
+ gpr_slice_buffer_add (&transport_global->qbuf, message_pfx);
+ gpr_slice_buffer_add (&transport_global->qbuf, gpr_slice_ref (*optional_message));
+ }
+
+ gpr_slice_buffer_add (&transport_global->qbuf, grpc_chttp2_rst_stream_create (stream_global->id, GRPC_CHTTP2_NO_ERROR));
+
+ grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global);
}
-static void cancel_stream_cb(grpc_chttp2_transport_global *transport_global,
- void *user_data,
- grpc_chttp2_stream_global *stream_global) {
- cancel_from_api(transport_global, stream_global, GRPC_STATUS_UNAVAILABLE);
+static void
+cancel_stream_cb (grpc_chttp2_transport_global * transport_global, void *user_data, grpc_chttp2_stream_global * stream_global)
+{
+ cancel_from_api (transport_global, stream_global, GRPC_STATUS_UNAVAILABLE);
}
-static void end_all_the_calls(grpc_chttp2_transport *t) {
- grpc_chttp2_for_all_streams(&t->global, NULL, cancel_stream_cb);
+static void
+end_all_the_calls (grpc_chttp2_transport * t)
+{
+ grpc_chttp2_for_all_streams (&t->global, NULL, cancel_stream_cb);
}
-static void drop_connection(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list) {
- close_transport_locked(t, closure_list);
- end_all_the_calls(t);
+static void
+drop_connection (grpc_chttp2_transport * t, grpc_closure_list * closure_list)
+{
+ close_transport_locked (t, closure_list);
+ end_all_the_calls (t);
}
/** update window from a settings change */
-static void update_global_window(void *args, gpr_uint32 id, void *stream) {
+static void
+update_global_window (void *args, gpr_uint32 id, void *stream)
+{
grpc_chttp2_transport *t = args;
grpc_chttp2_stream *s = stream;
grpc_chttp2_transport_global *transport_global = &t->global;
@@ -1091,181 +1087,184 @@ static void update_global_window(void *args, gpr_uint32 id, void *stream) {
int was_zero;
int is_zero;
- GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("settings", transport_global, stream_global,
- outgoing_window,
- t->parsing.initial_window_update);
+ GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("settings", transport_global, stream_global, outgoing_window, t->parsing.initial_window_update);
was_zero = stream_global->outgoing_window <= 0;
stream_global->outgoing_window += t->parsing.initial_window_update;
is_zero = stream_global->outgoing_window <= 0;
- if (was_zero && !is_zero) {
- grpc_chttp2_list_add_writable_stream(transport_global, stream_global);
- }
+ if (was_zero && !is_zero)
+ {
+ grpc_chttp2_list_add_writable_stream (transport_global, stream_global);
+ }
}
-static void read_error_locked(grpc_chttp2_transport *t,
- grpc_closure_list *closure_list) {
+static void
+read_error_locked (grpc_chttp2_transport * t, grpc_closure_list * closure_list)
+{
t->endpoint_reading = 0;
- if (!t->writing_active && t->ep) {
- destroy_endpoint(t, closure_list);
- }
+ if (!t->writing_active && t->ep)
+ {
+ destroy_endpoint (t, closure_list);
+ }
}
/* tcp read callback */
-static void recv_data(void *tp, int success, grpc_closure_list *closure_list) {
+static void
+recv_data (void *tp, int success, grpc_closure_list * closure_list)
+{
size_t i;
int keep_reading = 0;
grpc_chttp2_transport *t = tp;
- lock(t);
+ lock (t);
i = 0;
- GPR_ASSERT(!t->parsing_active);
- if (!t->closed) {
- t->parsing_active = 1;
- /* merge stream lists */
- grpc_chttp2_stream_map_move_into(&t->new_stream_map,
- &t->parsing_stream_map);
- grpc_chttp2_prepare_to_read(&t->global, &t->parsing);
- gpr_mu_unlock(&t->mu);
- for (; i < t->read_buffer.count &&
- grpc_chttp2_perform_read(&t->parsing, t->read_buffer.slices[i],
- closure_list);
- i++)
- ;
- gpr_mu_lock(&t->mu);
- if (i != t->read_buffer.count) {
- drop_connection(t, closure_list);
+ GPR_ASSERT (!t->parsing_active);
+ if (!t->closed)
+ {
+ t->parsing_active = 1;
+ /* merge stream lists */
+ grpc_chttp2_stream_map_move_into (&t->new_stream_map, &t->parsing_stream_map);
+ grpc_chttp2_prepare_to_read (&t->global, &t->parsing);
+ gpr_mu_unlock (&t->mu);
+ for (; i < t->read_buffer.count && grpc_chttp2_perform_read (&t->parsing, t->read_buffer.slices[i], closure_list); i++)
+ ;
+ gpr_mu_lock (&t->mu);
+ if (i != t->read_buffer.count)
+ {
+ drop_connection (t, closure_list);
+ }
+ /* merge stream lists */
+ grpc_chttp2_stream_map_move_into (&t->new_stream_map, &t->parsing_stream_map);
+ t->global.concurrent_stream_count = (gpr_uint32) grpc_chttp2_stream_map_size (&t->parsing_stream_map);
+ if (t->parsing.initial_window_update != 0)
+ {
+ grpc_chttp2_stream_map_for_each (&t->parsing_stream_map, update_global_window, t);
+ t->parsing.initial_window_update = 0;
+ }
+ /* handle higher level things */
+ grpc_chttp2_publish_reads (&t->global, &t->parsing, closure_list);
+ t->parsing_active = 0;
+ }
+ if (!success || i != t->read_buffer.count)
+ {
+ drop_connection (t, closure_list);
+ read_error_locked (t, closure_list);
+ }
+ else if (!t->closed)
+ {
+ keep_reading = 1;
+ REF_TRANSPORT (t, "keep_reading");
+ prevent_endpoint_shutdown (t);
+ }
+ gpr_slice_buffer_reset_and_unref (&t->read_buffer);
+ unlock (t, closure_list);
+
+ if (keep_reading)
+ {
+ grpc_endpoint_read (t->ep, &t->read_buffer, &t->recv_data, closure_list);
+ allow_endpoint_shutdown_unlocked (t, closure_list);
+ UNREF_TRANSPORT (t, "keep_reading", closure_list);
}
- /* merge stream lists */
- grpc_chttp2_stream_map_move_into(&t->new_stream_map,
- &t->parsing_stream_map);
- t->global.concurrent_stream_count =
- (gpr_uint32)grpc_chttp2_stream_map_size(&t->parsing_stream_map);
- if (t->parsing.initial_window_update != 0) {
- grpc_chttp2_stream_map_for_each(&t->parsing_stream_map,
- update_global_window, t);
- t->parsing.initial_window_update = 0;
+ else
+ {
+ UNREF_TRANSPORT (t, "recv_data", closure_list);
}
- /* handle higher level things */
- grpc_chttp2_publish_reads(&t->global, &t->parsing, closure_list);
- t->parsing_active = 0;
- }
- if (!success || i != t->read_buffer.count) {
- drop_connection(t, closure_list);
- read_error_locked(t, closure_list);
- } else if (!t->closed) {
- keep_reading = 1;
- REF_TRANSPORT(t, "keep_reading");
- prevent_endpoint_shutdown(t);
- }
- gpr_slice_buffer_reset_and_unref(&t->read_buffer);
- unlock(t, closure_list);
-
- if (keep_reading) {
- grpc_endpoint_read(t->ep, &t->read_buffer, &t->recv_data, closure_list);
- allow_endpoint_shutdown_unlocked(t, closure_list);
- UNREF_TRANSPORT(t, "keep_reading", closure_list);
- } else {
- UNREF_TRANSPORT(t, "recv_data", closure_list);
- }
}
/*
* CALLBACK LOOP
*/
-static void connectivity_state_set(
- grpc_chttp2_transport_global *transport_global,
- grpc_connectivity_state state, const char *reason,
- grpc_closure_list *closure_list) {
- GRPC_CHTTP2_IF_TRACING(
- gpr_log(GPR_DEBUG, "set connectivity_state=%d", state));
- grpc_connectivity_state_set(
- &TRANSPORT_FROM_GLOBAL(transport_global)->channel_callback.state_tracker,
- state, reason, closure_list);
+static void
+connectivity_state_set (grpc_chttp2_transport_global * transport_global, grpc_connectivity_state state, const char *reason, grpc_closure_list * closure_list)
+{
+ GRPC_CHTTP2_IF_TRACING (gpr_log (GPR_DEBUG, "set connectivity_state=%d", state));
+ grpc_connectivity_state_set (&TRANSPORT_FROM_GLOBAL (transport_global)->channel_callback.state_tracker, state, reason, closure_list);
}
/*
* POLLSET STUFF
*/
-static void add_to_pollset_locked(grpc_chttp2_transport *t,
- grpc_pollset *pollset,
- grpc_closure_list *closure_list) {
- if (t->ep) {
- grpc_endpoint_add_to_pollset(t->ep, pollset, closure_list);
- }
+static void
+add_to_pollset_locked (grpc_chttp2_transport * t, grpc_pollset * pollset, grpc_closure_list * closure_list)
+{
+ if (t->ep)
+ {
+ grpc_endpoint_add_to_pollset (t->ep, pollset, closure_list);
+ }
}
-static void add_to_pollset_set_locked(grpc_chttp2_transport *t,
- grpc_pollset_set *pollset_set,
- grpc_closure_list *closure_list) {
- if (t->ep) {
- grpc_endpoint_add_to_pollset_set(t->ep, pollset_set, closure_list);
- }
+static void
+add_to_pollset_set_locked (grpc_chttp2_transport * t, grpc_pollset_set * pollset_set, grpc_closure_list * closure_list)
+{
+ if (t->ep)
+ {
+ grpc_endpoint_add_to_pollset_set (t->ep, pollset_set, closure_list);
+ }
}
/*
* TRACING
*/
-void grpc_chttp2_flowctl_trace(const char *file, int line, const char *reason,
- const char *context, const char *var,
- int is_client, gpr_uint32 stream_id,
- gpr_int64 current_value, gpr_int64 delta) {
+void
+grpc_chttp2_flowctl_trace (const char *file, int line, const char *reason, const char *context, const char *var, int is_client, gpr_uint32 stream_id, gpr_int64 current_value, gpr_int64 delta)
+{
char *identifier;
char *context_scope;
char *context_thread;
- char *underscore_pos = strchr(context, '_');
- GPR_ASSERT(underscore_pos);
- context_thread = gpr_strdup(underscore_pos + 1);
- context_scope = gpr_strdup(context);
+ char *underscore_pos = strchr (context, '_');
+ GPR_ASSERT (underscore_pos);
+ context_thread = gpr_strdup (underscore_pos + 1);
+ context_scope = gpr_strdup (context);
context_scope[underscore_pos - context] = 0;
- if (stream_id) {
- gpr_asprintf(&identifier, "%s[%d]", context_scope, stream_id);
- } else {
- identifier = gpr_strdup(context_scope);
- }
- gpr_log(GPR_INFO,
- "FLOWCTL: %s %-10s %8s %-27s %8lld %c %8lld = %8lld %-10s [%s:%d]",
- is_client ? "client" : "server", identifier, context_thread, var,
- current_value, delta < 0 ? '-' : '+', delta < 0 ? -delta : delta,
- current_value + delta, reason, file, line);
- gpr_free(identifier);
- gpr_free(context_thread);
- gpr_free(context_scope);
+ if (stream_id)
+ {
+ gpr_asprintf (&identifier, "%s[%d]", context_scope, stream_id);
+ }
+ else
+ {
+ identifier = gpr_strdup (context_scope);
+ }
+ gpr_log (GPR_INFO, "FLOWCTL: %s %-10s %8s %-27s %8lld %c %8lld = %8lld %-10s [%s:%d]", is_client ? "client" : "server", identifier, context_thread, var, current_value, delta < 0 ? '-' : '+', delta < 0 ? -delta : delta, current_value + delta, reason, file, line);
+ gpr_free (identifier);
+ gpr_free (context_thread);
+ gpr_free (context_scope);
}
/*
* INTEGRATION GLUE
*/
-static char *chttp2_get_peer(grpc_transport *t,
- grpc_closure_list *closure_list) {
- return gpr_strdup(((grpc_chttp2_transport *)t)->peer_string);
+static char *
+chttp2_get_peer (grpc_transport * t, grpc_closure_list * closure_list)
+{
+ return gpr_strdup (((grpc_chttp2_transport *) t)->peer_string);
}
-static const grpc_transport_vtable vtable = {sizeof(grpc_chttp2_stream),
- init_stream,
- perform_stream_op,
- perform_transport_op,
- destroy_stream,
- destroy_transport,
- chttp2_get_peer};
-
-grpc_transport *grpc_create_chttp2_transport(
- const grpc_channel_args *channel_args, grpc_endpoint *ep, grpc_mdctx *mdctx,
- int is_client, grpc_closure_list *closure_list) {
- grpc_chttp2_transport *t = gpr_malloc(sizeof(grpc_chttp2_transport));
- init_transport(t, channel_args, ep, mdctx, is_client != 0, closure_list);
+static const grpc_transport_vtable vtable = { sizeof (grpc_chttp2_stream),
+ init_stream,
+ perform_stream_op,
+ perform_transport_op,
+ destroy_stream,
+ destroy_transport,
+ chttp2_get_peer
+};
+
+grpc_transport *
+grpc_create_chttp2_transport (const grpc_channel_args * channel_args, grpc_endpoint * ep, grpc_mdctx * mdctx, int is_client, grpc_closure_list * closure_list)
+{
+ grpc_chttp2_transport *t = gpr_malloc (sizeof (grpc_chttp2_transport));
+ init_transport (t, channel_args, ep, mdctx, is_client != 0, closure_list);
return &t->base;
}
-void grpc_chttp2_transport_start_reading(grpc_transport *transport,
- gpr_slice *slices, size_t nslices,
- grpc_closure_list *closure_list) {
- grpc_chttp2_transport *t = (grpc_chttp2_transport *)transport;
- REF_TRANSPORT(t, "recv_data"); /* matches unref inside recv_data */
- gpr_slice_buffer_addn(&t->read_buffer, slices, nslices);
- recv_data(t, 1, closure_list);
+void
+grpc_chttp2_transport_start_reading (grpc_transport * transport, gpr_slice * slices, size_t nslices, grpc_closure_list * closure_list)
+{
+ grpc_chttp2_transport *t = (grpc_chttp2_transport *) transport;
+ REF_TRANSPORT (t, "recv_data"); /* matches unref inside recv_data */
+ gpr_slice_buffer_addn (&t->read_buffer, slices, nslices);
+ recv_data (t, 1, closure_list);
}
diff --git a/src/core/transport/chttp2_transport.h b/src/core/transport/chttp2_transport.h
index 93a654bc83..69f98d3489 100644
--- a/src/core/transport/chttp2_transport.h
+++ b/src/core/transport/chttp2_transport.h
@@ -40,13 +40,8 @@
extern int grpc_http_trace;
extern int grpc_flowctl_trace;
-grpc_transport *grpc_create_chttp2_transport(
- const grpc_channel_args *channel_args, grpc_endpoint *ep,
- grpc_mdctx *metadata_context, int is_client,
- grpc_closure_list *closure_list);
+grpc_transport *grpc_create_chttp2_transport (const grpc_channel_args * channel_args, grpc_endpoint * ep, grpc_mdctx * metadata_context, int is_client, grpc_closure_list * closure_list);
-void grpc_chttp2_transport_start_reading(grpc_transport *transport,
- gpr_slice *slices, size_t nslices,
- grpc_closure_list *closure_list);
+void grpc_chttp2_transport_start_reading (grpc_transport * transport, gpr_slice * slices, size_t nslices, grpc_closure_list * closure_list);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_TRANSPORT_H */
diff --git a/src/core/transport/connectivity_state.c b/src/core/transport/connectivity_state.c
index fe80f9b0e9..08ecfb9fd5 100644
--- a/src/core/transport/connectivity_state.c
+++ b/src/core/transport/connectivity_state.c
@@ -41,8 +41,11 @@
int grpc_connectivity_state_trace = 0;
-const char *grpc_connectivity_state_name(grpc_connectivity_state state) {
- switch (state) {
+const char *
+grpc_connectivity_state_name (grpc_connectivity_state state)
+{
+ switch (state)
+ {
case GRPC_CHANNEL_IDLE:
return "IDLE";
case GRPC_CHANNEL_CONNECTING:
@@ -53,87 +56,95 @@ const char *grpc_connectivity_state_name(grpc_connectivity_state state) {
return "TRANSIENT_FAILURE";
case GRPC_CHANNEL_FATAL_FAILURE:
return "FATAL_FAILURE";
- }
- abort();
+ }
+ abort ();
return "UNKNOWN";
}
-void grpc_connectivity_state_init(grpc_connectivity_state_tracker *tracker,
- grpc_connectivity_state init_state,
- const char *name) {
+void
+grpc_connectivity_state_init (grpc_connectivity_state_tracker * tracker, grpc_connectivity_state init_state, const char *name)
+{
tracker->current_state = init_state;
tracker->watchers = NULL;
- tracker->name = gpr_strdup(name);
+ tracker->name = gpr_strdup (name);
}
-void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker *tracker,
- grpc_closure_list *closure_list) {
+void
+grpc_connectivity_state_destroy (grpc_connectivity_state_tracker * tracker, grpc_closure_list * closure_list)
+{
int success;
grpc_connectivity_state_watcher *w;
- while ((w = tracker->watchers)) {
- tracker->watchers = w->next;
+ while ((w = tracker->watchers))
+ {
+ tracker->watchers = w->next;
- if (GRPC_CHANNEL_FATAL_FAILURE != *w->current) {
- *w->current = GRPC_CHANNEL_FATAL_FAILURE;
- success = 1;
- } else {
- success = 0;
+ if (GRPC_CHANNEL_FATAL_FAILURE != *w->current)
+ {
+ *w->current = GRPC_CHANNEL_FATAL_FAILURE;
+ success = 1;
+ }
+ else
+ {
+ success = 0;
+ }
+ grpc_closure_list_add (closure_list, w->notify, success);
+ gpr_free (w);
}
- grpc_closure_list_add(closure_list, w->notify, success);
- gpr_free(w);
- }
- gpr_free(tracker->name);
+ gpr_free (tracker->name);
}
-grpc_connectivity_state grpc_connectivity_state_check(
- grpc_connectivity_state_tracker *tracker) {
- if (grpc_connectivity_state_trace) {
- gpr_log(GPR_DEBUG, "CONWATCH: %s: get %s", tracker->name,
- grpc_connectivity_state_name(tracker->current_state));
- }
+grpc_connectivity_state
+grpc_connectivity_state_check (grpc_connectivity_state_tracker * tracker)
+{
+ if (grpc_connectivity_state_trace)
+ {
+ gpr_log (GPR_DEBUG, "CONWATCH: %s: get %s", tracker->name, grpc_connectivity_state_name (tracker->current_state));
+ }
return tracker->current_state;
}
-int grpc_connectivity_state_notify_on_state_change(
- grpc_connectivity_state_tracker *tracker, grpc_connectivity_state *current,
- grpc_closure *notify, grpc_closure_list *closure_list) {
- if (grpc_connectivity_state_trace) {
- gpr_log(GPR_DEBUG, "CONWATCH: %s: from %s [cur=%s] notify=%p",
- tracker->name, grpc_connectivity_state_name(*current),
- grpc_connectivity_state_name(tracker->current_state), notify);
- }
- if (tracker->current_state != *current) {
- *current = tracker->current_state;
- grpc_closure_list_add(closure_list, notify, 1);
- } else {
- grpc_connectivity_state_watcher *w = gpr_malloc(sizeof(*w));
- w->current = current;
- w->notify = notify;
- w->next = tracker->watchers;
- tracker->watchers = w;
- }
+int
+grpc_connectivity_state_notify_on_state_change (grpc_connectivity_state_tracker * tracker, grpc_connectivity_state * current, grpc_closure * notify, grpc_closure_list * closure_list)
+{
+ if (grpc_connectivity_state_trace)
+ {
+ gpr_log (GPR_DEBUG, "CONWATCH: %s: from %s [cur=%s] notify=%p", tracker->name, grpc_connectivity_state_name (*current), grpc_connectivity_state_name (tracker->current_state), notify);
+ }
+ if (tracker->current_state != *current)
+ {
+ *current = tracker->current_state;
+ grpc_closure_list_add (closure_list, notify, 1);
+ }
+ else
+ {
+ grpc_connectivity_state_watcher *w = gpr_malloc (sizeof (*w));
+ w->current = current;
+ w->notify = notify;
+ w->next = tracker->watchers;
+ tracker->watchers = w;
+ }
return tracker->current_state == GRPC_CHANNEL_IDLE;
}
-void grpc_connectivity_state_set(grpc_connectivity_state_tracker *tracker,
- grpc_connectivity_state state,
- const char *reason,
- grpc_closure_list *closure_list) {
+void
+grpc_connectivity_state_set (grpc_connectivity_state_tracker * tracker, grpc_connectivity_state state, const char *reason, grpc_closure_list * closure_list)
+{
grpc_connectivity_state_watcher *w;
- if (grpc_connectivity_state_trace) {
- gpr_log(GPR_DEBUG, "SET: %s: %s --> %s [%s]", tracker->name,
- grpc_connectivity_state_name(tracker->current_state),
- grpc_connectivity_state_name(state), reason);
- }
- if (tracker->current_state == state) {
- return;
- }
- GPR_ASSERT(tracker->current_state != GRPC_CHANNEL_FATAL_FAILURE);
+ if (grpc_connectivity_state_trace)
+ {
+ gpr_log (GPR_DEBUG, "SET: %s: %s --> %s [%s]", tracker->name, grpc_connectivity_state_name (tracker->current_state), grpc_connectivity_state_name (state), reason);
+ }
+ if (tracker->current_state == state)
+ {
+ return;
+ }
+ GPR_ASSERT (tracker->current_state != GRPC_CHANNEL_FATAL_FAILURE);
tracker->current_state = state;
- while ((w = tracker->watchers) != NULL) {
- *w->current = tracker->current_state;
- tracker->watchers = w->next;
- grpc_closure_list_add(closure_list, w->notify, 1);
- gpr_free(w);
- }
+ while ((w = tracker->watchers) != NULL)
+ {
+ *w->current = tracker->current_state;
+ tracker->watchers = w->next;
+ grpc_closure_list_add (closure_list, w->notify, 1);
+ gpr_free (w);
+ }
}
diff --git a/src/core/transport/connectivity_state.h b/src/core/transport/connectivity_state.h
index 9b4d8da882..81fc8e7e12 100644
--- a/src/core/transport/connectivity_state.h
+++ b/src/core/transport/connectivity_state.h
@@ -37,7 +37,8 @@
#include <grpc/grpc.h>
#include "src/core/iomgr/exec_ctx.h"
-typedef struct grpc_connectivity_state_watcher {
+typedef struct grpc_connectivity_state_watcher
+{
/** we keep watchers in a linked list */
struct grpc_connectivity_state_watcher *next;
/** closure to notify on change */
@@ -46,7 +47,8 @@ typedef struct grpc_connectivity_state_watcher {
grpc_connectivity_state *current;
} grpc_connectivity_state_watcher;
-typedef struct {
+typedef struct
+{
/** current connectivity state */
grpc_connectivity_state current_state;
/** all our watchers */
@@ -57,25 +59,16 @@ typedef struct {
extern int grpc_connectivity_state_trace;
-void grpc_connectivity_state_init(grpc_connectivity_state_tracker *tracker,
- grpc_connectivity_state init_state,
- const char *name);
-void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker *tracker,
- grpc_closure_list *closure_list);
+void grpc_connectivity_state_init (grpc_connectivity_state_tracker * tracker, grpc_connectivity_state init_state, const char *name);
+void grpc_connectivity_state_destroy (grpc_connectivity_state_tracker * tracker, grpc_closure_list * closure_list);
/** Set connectivity state; not thread safe; access must be serialized with an
* external lock */
-void grpc_connectivity_state_set(grpc_connectivity_state_tracker *tracker,
- grpc_connectivity_state state,
- const char *reason,
- grpc_closure_list *closure_list);
+void grpc_connectivity_state_set (grpc_connectivity_state_tracker * tracker, grpc_connectivity_state state, const char *reason, grpc_closure_list * closure_list);
-grpc_connectivity_state grpc_connectivity_state_check(
- grpc_connectivity_state_tracker *tracker);
+grpc_connectivity_state grpc_connectivity_state_check (grpc_connectivity_state_tracker * tracker);
/** Return 1 if the channel should start connecting, 0 otherwise */
-int grpc_connectivity_state_notify_on_state_change(
- grpc_connectivity_state_tracker *tracker, grpc_connectivity_state *current,
- grpc_closure *notify, grpc_closure_list *closure_list);
+int grpc_connectivity_state_notify_on_state_change (grpc_connectivity_state_tracker * tracker, grpc_connectivity_state * current, grpc_closure * notify, grpc_closure_list * closure_list);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CONNECTIVITY_STATE_H */
diff --git a/src/core/transport/metadata.c b/src/core/transport/metadata.c
index 9d135f4356..0ce18712c3 100644
--- a/src/core/transport/metadata.c
+++ b/src/core/transport/metadata.c
@@ -62,7 +62,8 @@
#define REF_MD_LOCKED(s) ref_md_locked((s))
#endif
-typedef struct internal_string {
+typedef struct internal_string
+{
/* must be byte compatible with grpc_mdstr */
gpr_slice slice;
gpr_uint32 hash;
@@ -79,7 +80,8 @@ typedef struct internal_string {
struct internal_string *bucket_next;
} internal_string;
-typedef struct internal_metadata {
+typedef struct internal_metadata
+{
/* must be byte compatible with grpc_mdelem */
internal_string *key;
internal_string *value;
@@ -89,13 +91,14 @@ typedef struct internal_metadata {
/* private only data */
gpr_mu mu_user_data;
void *user_data;
- void (*destroy_user_data)(void *user_data);
+ void (*destroy_user_data) (void *user_data);
grpc_mdctx *context;
struct internal_metadata *bucket_next;
} internal_metadata;
-struct grpc_mdctx {
+struct grpc_mdctx
+{
gpr_uint32 hash_seed;
int refs;
@@ -111,15 +114,21 @@ struct grpc_mdctx {
size_t mdtab_capacity;
};
-static void internal_string_ref(internal_string *s DEBUG_ARGS);
-static void internal_string_unref(internal_string *s DEBUG_ARGS);
-static void discard_metadata(grpc_mdctx *ctx);
-static void gc_mdtab(grpc_mdctx *ctx);
-static void metadata_context_destroy_locked(grpc_mdctx *ctx);
+static void internal_string_ref (internal_string * s DEBUG_ARGS);
+static void internal_string_unref (internal_string * s DEBUG_ARGS);
+static void discard_metadata (grpc_mdctx * ctx);
+static void gc_mdtab (grpc_mdctx * ctx);
+static void metadata_context_destroy_locked (grpc_mdctx * ctx);
-static void lock(grpc_mdctx *ctx) { gpr_mu_lock(&ctx->mu); }
+static void
+lock (grpc_mdctx * ctx)
+{
+ gpr_mu_lock (&ctx->mu);
+}
-static void unlock(grpc_mdctx *ctx) {
+static void
+unlock (grpc_mdctx * ctx)
+{
/* If the context has been orphaned we'd like to delete it soon. We check
conditions in unlock as it signals the end of mutations on a context.
@@ -132,49 +141,52 @@ static void unlock(grpc_mdctx *ctx) {
mdelems on every unlock (instead of the usual 'I'm too loaded' trigger
case), since otherwise we can be stuck waiting for a garbage collection
that will never happen. */
- if (ctx->refs == 0) {
+ if (ctx->refs == 0)
+ {
/* uncomment if you're having trouble diagnosing an mdelem leak to make
things clearer (slows down destruction a lot, however) */
#ifdef GRPC_METADATA_REFCOUNT_DEBUG
- gc_mdtab(ctx);
+ gc_mdtab (ctx);
#endif
- if (ctx->mdtab_count && ctx->mdtab_count == ctx->mdtab_free) {
- discard_metadata(ctx);
- }
- if (ctx->strtab_count == 0) {
- metadata_context_destroy_locked(ctx);
- return;
+ if (ctx->mdtab_count && ctx->mdtab_count == ctx->mdtab_free)
+ {
+ discard_metadata (ctx);
+ }
+ if (ctx->strtab_count == 0)
+ {
+ metadata_context_destroy_locked (ctx);
+ return;
+ }
}
- }
- gpr_mu_unlock(&ctx->mu);
+ gpr_mu_unlock (&ctx->mu);
}
-static void ref_md_locked(internal_metadata *md DEBUG_ARGS) {
+static void
+ref_md_locked (internal_metadata * md DEBUG_ARGS)
+{
#ifdef GRPC_METADATA_REFCOUNT_DEBUG
- gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
- "ELM REF:%p:%d->%d: '%s' = '%s'", md,
- gpr_atm_no_barrier_load(&md->refcnt),
- gpr_atm_no_barrier_load(&md->refcnt) + 1,
- grpc_mdstr_as_c_string((grpc_mdstr *)md->key),
- grpc_mdstr_as_c_string((grpc_mdstr *)md->value));
+ gpr_log (file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%d->%d: '%s' = '%s'", md, gpr_atm_no_barrier_load (&md->refcnt), gpr_atm_no_barrier_load (&md->refcnt) + 1, grpc_mdstr_as_c_string ((grpc_mdstr *) md->key), grpc_mdstr_as_c_string ((grpc_mdstr *) md->value));
#endif
- if (0 == gpr_atm_no_barrier_fetch_add(&md->refcnt, 1)) {
- md->context->mdtab_free--;
- }
+ if (0 == gpr_atm_no_barrier_fetch_add (&md->refcnt, 1))
+ {
+ md->context->mdtab_free--;
+ }
}
-grpc_mdctx *grpc_mdctx_create_with_seed(gpr_uint32 seed) {
- grpc_mdctx *ctx = gpr_malloc(sizeof(grpc_mdctx));
+grpc_mdctx *
+grpc_mdctx_create_with_seed (gpr_uint32 seed)
+{
+ grpc_mdctx *ctx = gpr_malloc (sizeof (grpc_mdctx));
ctx->refs = 1;
ctx->hash_seed = seed;
- gpr_mu_init(&ctx->mu);
- ctx->strtab = gpr_malloc(sizeof(internal_string *) * INITIAL_STRTAB_CAPACITY);
- memset(ctx->strtab, 0, sizeof(grpc_mdstr *) * INITIAL_STRTAB_CAPACITY);
+ gpr_mu_init (&ctx->mu);
+ ctx->strtab = gpr_malloc (sizeof (internal_string *) * INITIAL_STRTAB_CAPACITY);
+ memset (ctx->strtab, 0, sizeof (grpc_mdstr *) * INITIAL_STRTAB_CAPACITY);
ctx->strtab_count = 0;
ctx->strtab_capacity = INITIAL_STRTAB_CAPACITY;
- ctx->mdtab = gpr_malloc(sizeof(internal_metadata *) * INITIAL_MDTAB_CAPACITY);
- memset(ctx->mdtab, 0, sizeof(grpc_mdelem *) * INITIAL_MDTAB_CAPACITY);
+ ctx->mdtab = gpr_malloc (sizeof (internal_metadata *) * INITIAL_MDTAB_CAPACITY);
+ memset (ctx->mdtab, 0, sizeof (grpc_mdelem *) * INITIAL_MDTAB_CAPACITY);
ctx->mdtab_count = 0;
ctx->mdtab_capacity = INITIAL_MDTAB_CAPACITY;
ctx->mdtab_free = 0;
@@ -182,218 +194,258 @@ grpc_mdctx *grpc_mdctx_create_with_seed(gpr_uint32 seed) {
return ctx;
}
-grpc_mdctx *grpc_mdctx_create(void) {
+grpc_mdctx *
+grpc_mdctx_create (void)
+{
/* This seed is used to prevent remote connections from controlling hash table
* collisions. It needs to be somewhat unpredictable to a remote connection.
*/
- return grpc_mdctx_create_with_seed(
- (gpr_uint32)gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
+ return grpc_mdctx_create_with_seed ((gpr_uint32) gpr_now (GPR_CLOCK_REALTIME).tv_nsec);
}
-static void discard_metadata(grpc_mdctx *ctx) {
+static void
+discard_metadata (grpc_mdctx * ctx)
+{
size_t i;
internal_metadata *next, *cur;
- for (i = 0; i < ctx->mdtab_capacity; i++) {
- cur = ctx->mdtab[i];
- while (cur) {
- GPR_ASSERT(gpr_atm_acq_load(&cur->refcnt) == 0);
- next = cur->bucket_next;
- INTERNAL_STRING_UNREF(cur->key);
- INTERNAL_STRING_UNREF(cur->value);
- if (cur->user_data) {
- cur->destroy_user_data(cur->user_data);
- }
- gpr_mu_destroy(&cur->mu_user_data);
- gpr_free(cur);
- cur = next;
- ctx->mdtab_free--;
- ctx->mdtab_count--;
+ for (i = 0; i < ctx->mdtab_capacity; i++)
+ {
+ cur = ctx->mdtab[i];
+ while (cur)
+ {
+ GPR_ASSERT (gpr_atm_acq_load (&cur->refcnt) == 0);
+ next = cur->bucket_next;
+ INTERNAL_STRING_UNREF (cur->key);
+ INTERNAL_STRING_UNREF (cur->value);
+ if (cur->user_data)
+ {
+ cur->destroy_user_data (cur->user_data);
+ }
+ gpr_mu_destroy (&cur->mu_user_data);
+ gpr_free (cur);
+ cur = next;
+ ctx->mdtab_free--;
+ ctx->mdtab_count--;
+ }
+ ctx->mdtab[i] = NULL;
}
- ctx->mdtab[i] = NULL;
- }
-}
-
-static void metadata_context_destroy_locked(grpc_mdctx *ctx) {
- GPR_ASSERT(ctx->strtab_count == 0);
- GPR_ASSERT(ctx->mdtab_count == 0);
- GPR_ASSERT(ctx->mdtab_free == 0);
- gpr_free(ctx->strtab);
- gpr_free(ctx->mdtab);
- gpr_mu_unlock(&ctx->mu);
- gpr_mu_destroy(&ctx->mu);
- gpr_free(ctx);
}
-void grpc_mdctx_ref(grpc_mdctx *ctx) {
- lock(ctx);
- GPR_ASSERT(ctx->refs > 0);
+static void
+metadata_context_destroy_locked (grpc_mdctx * ctx)
+{
+ GPR_ASSERT (ctx->strtab_count == 0);
+ GPR_ASSERT (ctx->mdtab_count == 0);
+ GPR_ASSERT (ctx->mdtab_free == 0);
+ gpr_free (ctx->strtab);
+ gpr_free (ctx->mdtab);
+ gpr_mu_unlock (&ctx->mu);
+ gpr_mu_destroy (&ctx->mu);
+ gpr_free (ctx);
+}
+
+void
+grpc_mdctx_ref (grpc_mdctx * ctx)
+{
+ lock (ctx);
+ GPR_ASSERT (ctx->refs > 0);
ctx->refs++;
- unlock(ctx);
+ unlock (ctx);
}
-void grpc_mdctx_unref(grpc_mdctx *ctx) {
- lock(ctx);
- GPR_ASSERT(ctx->refs > 0);
+void
+grpc_mdctx_unref (grpc_mdctx * ctx)
+{
+ lock (ctx);
+ GPR_ASSERT (ctx->refs > 0);
ctx->refs--;
- unlock(ctx);
+ unlock (ctx);
}
-static void grow_strtab(grpc_mdctx *ctx) {
+static void
+grow_strtab (grpc_mdctx * ctx)
+{
size_t capacity = ctx->strtab_capacity * 2;
size_t i;
- internal_string **strtab = gpr_malloc(sizeof(internal_string *) * capacity);
+ internal_string **strtab = gpr_malloc (sizeof (internal_string *) * capacity);
internal_string *s, *next;
- memset(strtab, 0, sizeof(internal_string *) * capacity);
-
- for (i = 0; i < ctx->strtab_capacity; i++) {
- for (s = ctx->strtab[i]; s; s = next) {
- next = s->bucket_next;
- s->bucket_next = strtab[s->hash % capacity];
- strtab[s->hash % capacity] = s;
+ memset (strtab, 0, sizeof (internal_string *) * capacity);
+
+ for (i = 0; i < ctx->strtab_capacity; i++)
+ {
+ for (s = ctx->strtab[i]; s; s = next)
+ {
+ next = s->bucket_next;
+ s->bucket_next = strtab[s->hash % capacity];
+ strtab[s->hash % capacity] = s;
+ }
}
- }
- gpr_free(ctx->strtab);
+ gpr_free (ctx->strtab);
ctx->strtab = strtab;
ctx->strtab_capacity = capacity;
}
-static void internal_destroy_string(internal_string *is) {
+static void
+internal_destroy_string (internal_string * is)
+{
internal_string **prev_next;
internal_string *cur;
grpc_mdctx *ctx = is->context;
- if (is->has_base64_and_huffman_encoded) {
- gpr_slice_unref(is->base64_and_huffman);
- }
- for (prev_next = &ctx->strtab[is->hash % ctx->strtab_capacity],
- cur = *prev_next;
- cur != is; prev_next = &cur->bucket_next, cur = cur->bucket_next)
+ if (is->has_base64_and_huffman_encoded)
+ {
+ gpr_slice_unref (is->base64_and_huffman);
+ }
+ for (prev_next = &ctx->strtab[is->hash % ctx->strtab_capacity], cur = *prev_next; cur != is; prev_next = &cur->bucket_next, cur = cur->bucket_next)
;
*prev_next = cur->bucket_next;
ctx->strtab_count--;
- gpr_free(is);
+ gpr_free (is);
}
-static void internal_string_ref(internal_string *s DEBUG_ARGS) {
+static void
+internal_string_ref (internal_string * s DEBUG_ARGS)
+{
#ifdef GRPC_METADATA_REFCOUNT_DEBUG
- gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "STR REF:%p:%d->%d: '%s'", s,
- s->refs, s->refs + 1, grpc_mdstr_as_c_string((grpc_mdstr *)s));
+ gpr_log (file, line, GPR_LOG_SEVERITY_DEBUG, "STR REF:%p:%d->%d: '%s'", s, s->refs, s->refs + 1, grpc_mdstr_as_c_string ((grpc_mdstr *) s));
#endif
++s->refs;
}
-static void internal_string_unref(internal_string *s DEBUG_ARGS) {
+static void
+internal_string_unref (internal_string * s DEBUG_ARGS)
+{
#ifdef GRPC_METADATA_REFCOUNT_DEBUG
- gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "STR UNREF:%p:%d->%d: '%s'", s,
- s->refs, s->refs - 1, grpc_mdstr_as_c_string((grpc_mdstr *)s));
+ gpr_log (file, line, GPR_LOG_SEVERITY_DEBUG, "STR UNREF:%p:%d->%d: '%s'", s, s->refs, s->refs - 1, grpc_mdstr_as_c_string ((grpc_mdstr *) s));
#endif
- GPR_ASSERT(s->refs > 0);
- if (0 == --s->refs) {
- internal_destroy_string(s);
- }
+ GPR_ASSERT (s->refs > 0);
+ if (0 == --s->refs)
+ {
+ internal_destroy_string (s);
+ }
}
-static void slice_ref(void *p) {
- internal_string *is =
- (internal_string *)((char *)p - offsetof(internal_string, refcount));
+static void
+slice_ref (void *p)
+{
+ internal_string *is = (internal_string *) ((char *) p - offsetof (internal_string, refcount));
grpc_mdctx *ctx = is->context;
- lock(ctx);
- INTERNAL_STRING_REF(is);
- unlock(ctx);
+ lock (ctx);
+ INTERNAL_STRING_REF (is);
+ unlock (ctx);
}
-static void slice_unref(void *p) {
- internal_string *is =
- (internal_string *)((char *)p - offsetof(internal_string, refcount));
+static void
+slice_unref (void *p)
+{
+ internal_string *is = (internal_string *) ((char *) p - offsetof (internal_string, refcount));
grpc_mdctx *ctx = is->context;
- lock(ctx);
- INTERNAL_STRING_UNREF(is);
- unlock(ctx);
-}
-
-grpc_mdstr *grpc_mdstr_from_string(grpc_mdctx *ctx, const char *str,
- int canonicalize_key) {
- if (canonicalize_key) {
- size_t len;
- size_t i;
- int canonical = 1;
-
- for (i = 0; str[i]; i++) {
- if (str[i] >= 'A' && str[i] <= 'Z') {
- canonical = 0;
- /* Keep going in loop just to get string length */
- }
+ lock (ctx);
+ INTERNAL_STRING_UNREF (is);
+ unlock (ctx);
+}
+
+grpc_mdstr *
+grpc_mdstr_from_string (grpc_mdctx * ctx, const char *str, int canonicalize_key)
+{
+ if (canonicalize_key)
+ {
+ size_t len;
+ size_t i;
+ int canonical = 1;
+
+ for (i = 0; str[i]; i++)
+ {
+ if (str[i] >= 'A' && str[i] <= 'Z')
+ {
+ canonical = 0;
+ /* Keep going in loop just to get string length */
+ }
+ }
+ len = i;
+
+ if (canonical)
+ {
+ return grpc_mdstr_from_buffer (ctx, (const gpr_uint8 *) str, len);
+ }
+ else
+ {
+ char *copy = gpr_malloc (len);
+ grpc_mdstr *ret;
+ for (i = 0; i < len; i++)
+ {
+ if (str[i] >= 'A' && str[i] <= 'Z')
+ {
+ copy[i] = (char) (str[i] - 'A' + 'a');
+ }
+ else
+ {
+ copy[i] = str[i];
+ }
+ }
+ ret = grpc_mdstr_from_buffer (ctx, (const gpr_uint8 *) copy, len);
+ gpr_free (copy);
+ return ret;
+ }
}
- len = i;
-
- if (canonical) {
- return grpc_mdstr_from_buffer(ctx, (const gpr_uint8 *)str, len);
- } else {
- char *copy = gpr_malloc(len);
- grpc_mdstr *ret;
- for (i = 0; i < len; i++) {
- if (str[i] >= 'A' && str[i] <= 'Z') {
- copy[i] = (char)(str[i] - 'A' + 'a');
- } else {
- copy[i] = str[i];
- }
- }
- ret = grpc_mdstr_from_buffer(ctx, (const gpr_uint8 *)copy, len);
- gpr_free(copy);
- return ret;
- }
- }
- return grpc_mdstr_from_buffer(ctx, (const gpr_uint8 *)str, strlen(str));
+ return grpc_mdstr_from_buffer (ctx, (const gpr_uint8 *) str, strlen (str));
}
-grpc_mdstr *grpc_mdstr_from_slice(grpc_mdctx *ctx, gpr_slice slice) {
- grpc_mdstr *result = grpc_mdstr_from_buffer(ctx, GPR_SLICE_START_PTR(slice),
- GPR_SLICE_LENGTH(slice));
- gpr_slice_unref(slice);
+grpc_mdstr *
+grpc_mdstr_from_slice (grpc_mdctx * ctx, gpr_slice slice)
+{
+ grpc_mdstr *result = grpc_mdstr_from_buffer (ctx, GPR_SLICE_START_PTR (slice),
+ GPR_SLICE_LENGTH (slice));
+ gpr_slice_unref (slice);
return result;
}
-grpc_mdstr *grpc_mdstr_from_buffer(grpc_mdctx *ctx, const gpr_uint8 *buf,
- size_t length) {
- gpr_uint32 hash = gpr_murmur_hash3(buf, length, ctx->hash_seed);
+grpc_mdstr *
+grpc_mdstr_from_buffer (grpc_mdctx * ctx, const gpr_uint8 * buf, size_t length)
+{
+ gpr_uint32 hash = gpr_murmur_hash3 (buf, length, ctx->hash_seed);
internal_string *s;
- lock(ctx);
+ lock (ctx);
/* search for an existing string */
- for (s = ctx->strtab[hash % ctx->strtab_capacity]; s; s = s->bucket_next) {
- if (s->hash == hash && GPR_SLICE_LENGTH(s->slice) == length &&
- 0 == memcmp(buf, GPR_SLICE_START_PTR(s->slice), length)) {
- INTERNAL_STRING_REF(s);
- unlock(ctx);
- return (grpc_mdstr *)s;
+ for (s = ctx->strtab[hash % ctx->strtab_capacity]; s; s = s->bucket_next)
+ {
+ if (s->hash == hash && GPR_SLICE_LENGTH (s->slice) == length && 0 == memcmp (buf, GPR_SLICE_START_PTR (s->slice), length))
+ {
+ INTERNAL_STRING_REF (s);
+ unlock (ctx);
+ return (grpc_mdstr *) s;
+ }
}
- }
/* not found: create a new string */
- if (length + 1 < GPR_SLICE_INLINED_SIZE) {
- /* string data goes directly into the slice */
- s = gpr_malloc(sizeof(internal_string));
- s->refs = 1;
- s->slice.refcount = NULL;
- memcpy(s->slice.data.inlined.bytes, buf, length);
- s->slice.data.inlined.bytes[length] = 0;
- s->slice.data.inlined.length = (gpr_uint8)length;
- } else {
- /* string data goes after the internal_string header, and we +1 for null
- terminator */
- s = gpr_malloc(sizeof(internal_string) + length + 1);
- s->refs = 1;
- s->refcount.ref = slice_ref;
- s->refcount.unref = slice_unref;
- s->slice.refcount = &s->refcount;
- s->slice.data.refcounted.bytes = (gpr_uint8 *)(s + 1);
- s->slice.data.refcounted.length = length;
- memcpy(s->slice.data.refcounted.bytes, buf, length);
- /* add a null terminator for cheap c string conversion when desired */
- s->slice.data.refcounted.bytes[length] = 0;
- }
+ if (length + 1 < GPR_SLICE_INLINED_SIZE)
+ {
+ /* string data goes directly into the slice */
+ s = gpr_malloc (sizeof (internal_string));
+ s->refs = 1;
+ s->slice.refcount = NULL;
+ memcpy (s->slice.data.inlined.bytes, buf, length);
+ s->slice.data.inlined.bytes[length] = 0;
+ s->slice.data.inlined.length = (gpr_uint8) length;
+ }
+ else
+ {
+ /* string data goes after the internal_string header, and we +1 for null
+ terminator */
+ s = gpr_malloc (sizeof (internal_string) + length + 1);
+ s->refs = 1;
+ s->refcount.ref = slice_ref;
+ s->refcount.unref = slice_unref;
+ s->slice.refcount = &s->refcount;
+ s->slice.data.refcounted.bytes = (gpr_uint8 *) (s + 1);
+ s->slice.data.refcounted.length = length;
+ memcpy (s->slice.data.refcounted.bytes, buf, length);
+ /* add a null terminator for cheap c string conversion when desired */
+ s->slice.data.refcounted.bytes[length] = 0;
+ }
s->has_base64_and_huffman_encoded = 0;
s->hash = hash;
s->context = ctx;
@@ -402,316 +454,357 @@ grpc_mdstr *grpc_mdstr_from_buffer(grpc_mdctx *ctx, const gpr_uint8 *buf,
ctx->strtab_count++;
- if (ctx->strtab_count > ctx->strtab_capacity * 2) {
- grow_strtab(ctx);
- }
+ if (ctx->strtab_count > ctx->strtab_capacity * 2)
+ {
+ grow_strtab (ctx);
+ }
- unlock(ctx);
+ unlock (ctx);
- return (grpc_mdstr *)s;
+ return (grpc_mdstr *) s;
}
-static void gc_mdtab(grpc_mdctx *ctx) {
+static void
+gc_mdtab (grpc_mdctx * ctx)
+{
size_t i;
internal_metadata **prev_next;
internal_metadata *md, *next;
- for (i = 0; i < ctx->mdtab_capacity; i++) {
- prev_next = &ctx->mdtab[i];
- for (md = ctx->mdtab[i]; md; md = next) {
- next = md->bucket_next;
- if (gpr_atm_acq_load(&md->refcnt) == 0) {
- INTERNAL_STRING_UNREF(md->key);
- INTERNAL_STRING_UNREF(md->value);
- if (md->user_data) {
- md->destroy_user_data(md->user_data);
- }
- gpr_free(md);
- *prev_next = next;
- ctx->mdtab_free--;
- ctx->mdtab_count--;
- } else {
- prev_next = &md->bucket_next;
- }
+ for (i = 0; i < ctx->mdtab_capacity; i++)
+ {
+ prev_next = &ctx->mdtab[i];
+ for (md = ctx->mdtab[i]; md; md = next)
+ {
+ next = md->bucket_next;
+ if (gpr_atm_acq_load (&md->refcnt) == 0)
+ {
+ INTERNAL_STRING_UNREF (md->key);
+ INTERNAL_STRING_UNREF (md->value);
+ if (md->user_data)
+ {
+ md->destroy_user_data (md->user_data);
+ }
+ gpr_free (md);
+ *prev_next = next;
+ ctx->mdtab_free--;
+ ctx->mdtab_count--;
+ }
+ else
+ {
+ prev_next = &md->bucket_next;
+ }
+ }
}
- }
- GPR_ASSERT(ctx->mdtab_free == 0);
+ GPR_ASSERT (ctx->mdtab_free == 0);
}
-static void grow_mdtab(grpc_mdctx *ctx) {
+static void
+grow_mdtab (grpc_mdctx * ctx)
+{
size_t capacity = ctx->mdtab_capacity * 2;
size_t i;
- internal_metadata **mdtab =
- gpr_malloc(sizeof(internal_metadata *) * capacity);
+ internal_metadata **mdtab = gpr_malloc (sizeof (internal_metadata *) * capacity);
internal_metadata *md, *next;
gpr_uint32 hash;
- memset(mdtab, 0, sizeof(internal_metadata *) * capacity);
-
- for (i = 0; i < ctx->mdtab_capacity; i++) {
- for (md = ctx->mdtab[i]; md; md = next) {
- hash = GRPC_MDSTR_KV_HASH(md->key->hash, md->value->hash);
- next = md->bucket_next;
- md->bucket_next = mdtab[hash % capacity];
- mdtab[hash % capacity] = md;
+ memset (mdtab, 0, sizeof (internal_metadata *) * capacity);
+
+ for (i = 0; i < ctx->mdtab_capacity; i++)
+ {
+ for (md = ctx->mdtab[i]; md; md = next)
+ {
+ hash = GRPC_MDSTR_KV_HASH (md->key->hash, md->value->hash);
+ next = md->bucket_next;
+ md->bucket_next = mdtab[hash % capacity];
+ mdtab[hash % capacity] = md;
+ }
}
- }
- gpr_free(ctx->mdtab);
+ gpr_free (ctx->mdtab);
ctx->mdtab = mdtab;
ctx->mdtab_capacity = capacity;
}
-static void rehash_mdtab(grpc_mdctx *ctx) {
- if (ctx->mdtab_free > ctx->mdtab_capacity / 4) {
- gc_mdtab(ctx);
- } else {
- grow_mdtab(ctx);
- }
+static void
+rehash_mdtab (grpc_mdctx * ctx)
+{
+ if (ctx->mdtab_free > ctx->mdtab_capacity / 4)
+ {
+ gc_mdtab (ctx);
+ }
+ else
+ {
+ grow_mdtab (ctx);
+ }
}
-grpc_mdelem *grpc_mdelem_from_metadata_strings(grpc_mdctx *ctx,
- grpc_mdstr *mkey,
- grpc_mdstr *mvalue) {
- internal_string *key = (internal_string *)mkey;
- internal_string *value = (internal_string *)mvalue;
- gpr_uint32 hash = GRPC_MDSTR_KV_HASH(mkey->hash, mvalue->hash);
+grpc_mdelem *
+grpc_mdelem_from_metadata_strings (grpc_mdctx * ctx, grpc_mdstr * mkey, grpc_mdstr * mvalue)
+{
+ internal_string *key = (internal_string *) mkey;
+ internal_string *value = (internal_string *) mvalue;
+ gpr_uint32 hash = GRPC_MDSTR_KV_HASH (mkey->hash, mvalue->hash);
internal_metadata *md;
- GPR_ASSERT(key->context == ctx);
- GPR_ASSERT(value->context == ctx);
+ GPR_ASSERT (key->context == ctx);
+ GPR_ASSERT (value->context == ctx);
- lock(ctx);
+ lock (ctx);
/* search for an existing pair */
- for (md = ctx->mdtab[hash % ctx->mdtab_capacity]; md; md = md->bucket_next) {
- if (md->key == key && md->value == value) {
- REF_MD_LOCKED(md);
- INTERNAL_STRING_UNREF(key);
- INTERNAL_STRING_UNREF(value);
- unlock(ctx);
- return (grpc_mdelem *)md;
+ for (md = ctx->mdtab[hash % ctx->mdtab_capacity]; md; md = md->bucket_next)
+ {
+ if (md->key == key && md->value == value)
+ {
+ REF_MD_LOCKED (md);
+ INTERNAL_STRING_UNREF (key);
+ INTERNAL_STRING_UNREF (value);
+ unlock (ctx);
+ return (grpc_mdelem *) md;
+ }
}
- }
/* not found: create a new pair */
- md = gpr_malloc(sizeof(internal_metadata));
- gpr_atm_rel_store(&md->refcnt, 1);
+ md = gpr_malloc (sizeof (internal_metadata));
+ gpr_atm_rel_store (&md->refcnt, 1);
md->context = ctx;
md->key = key;
md->value = value;
md->user_data = NULL;
md->destroy_user_data = NULL;
md->bucket_next = ctx->mdtab[hash % ctx->mdtab_capacity];
- gpr_mu_init(&md->mu_user_data);
+ gpr_mu_init (&md->mu_user_data);
#ifdef GRPC_METADATA_REFCOUNT_DEBUG
- gpr_log(GPR_DEBUG, "ELM NEW:%p:%d: '%s' = '%s'", md,
- gpr_atm_no_barrier_load(&md->refcnt),
- grpc_mdstr_as_c_string((grpc_mdstr *)md->key),
- grpc_mdstr_as_c_string((grpc_mdstr *)md->value));
+ gpr_log (GPR_DEBUG, "ELM NEW:%p:%d: '%s' = '%s'", md, gpr_atm_no_barrier_load (&md->refcnt), grpc_mdstr_as_c_string ((grpc_mdstr *) md->key), grpc_mdstr_as_c_string ((grpc_mdstr *) md->value));
#endif
ctx->mdtab[hash % ctx->mdtab_capacity] = md;
ctx->mdtab_count++;
- if (ctx->mdtab_count > ctx->mdtab_capacity * 2) {
- rehash_mdtab(ctx);
- }
+ if (ctx->mdtab_count > ctx->mdtab_capacity * 2)
+ {
+ rehash_mdtab (ctx);
+ }
- unlock(ctx);
+ unlock (ctx);
- return (grpc_mdelem *)md;
+ return (grpc_mdelem *) md;
}
-grpc_mdelem *grpc_mdelem_from_strings(grpc_mdctx *ctx, const char *key,
- const char *value) {
- return grpc_mdelem_from_metadata_strings(
- ctx, grpc_mdstr_from_string(ctx, key, 0),
- grpc_mdstr_from_string(ctx, value, 0));
+grpc_mdelem *
+grpc_mdelem_from_strings (grpc_mdctx * ctx, const char *key, const char *value)
+{
+ return grpc_mdelem_from_metadata_strings (ctx, grpc_mdstr_from_string (ctx, key, 0), grpc_mdstr_from_string (ctx, value, 0));
}
-grpc_mdelem *grpc_mdelem_from_slices(grpc_mdctx *ctx, gpr_slice key,
- gpr_slice value) {
- return grpc_mdelem_from_metadata_strings(ctx, grpc_mdstr_from_slice(ctx, key),
- grpc_mdstr_from_slice(ctx, value));
+grpc_mdelem *
+grpc_mdelem_from_slices (grpc_mdctx * ctx, gpr_slice key, gpr_slice value)
+{
+ return grpc_mdelem_from_metadata_strings (ctx, grpc_mdstr_from_slice (ctx, key), grpc_mdstr_from_slice (ctx, value));
}
-grpc_mdelem *grpc_mdelem_from_string_and_buffer(grpc_mdctx *ctx,
- const char *key,
- const gpr_uint8 *value,
- size_t value_length,
- int canonicalize_key) {
- return grpc_mdelem_from_metadata_strings(
- ctx, grpc_mdstr_from_string(ctx, key, canonicalize_key),
- grpc_mdstr_from_buffer(ctx, value, value_length));
+grpc_mdelem *
+grpc_mdelem_from_string_and_buffer (grpc_mdctx * ctx, const char *key, const gpr_uint8 * value, size_t value_length, int canonicalize_key)
+{
+ return grpc_mdelem_from_metadata_strings (ctx, grpc_mdstr_from_string (ctx, key, canonicalize_key), grpc_mdstr_from_buffer (ctx, value, value_length));
}
-grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *gmd DEBUG_ARGS) {
- internal_metadata *md = (internal_metadata *)gmd;
+grpc_mdelem *
+grpc_mdelem_ref (grpc_mdelem * gmd DEBUG_ARGS)
+{
+ internal_metadata *md = (internal_metadata *) gmd;
#ifdef GRPC_METADATA_REFCOUNT_DEBUG
- gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
- "ELM REF:%p:%d->%d: '%s' = '%s'", md,
- gpr_atm_no_barrier_load(&md->refcnt),
- gpr_atm_no_barrier_load(&md->refcnt) + 1,
- grpc_mdstr_as_c_string((grpc_mdstr *)md->key),
- grpc_mdstr_as_c_string((grpc_mdstr *)md->value));
+ gpr_log (file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%d->%d: '%s' = '%s'", md, gpr_atm_no_barrier_load (&md->refcnt), gpr_atm_no_barrier_load (&md->refcnt) + 1, grpc_mdstr_as_c_string ((grpc_mdstr *) md->key), grpc_mdstr_as_c_string ((grpc_mdstr *) md->value));
#endif
/* we can assume the ref count is >= 1 as the application is calling
this function - meaning that no adjustment to mdtab_free is necessary,
simplifying the logic here to be just an atomic increment */
/* use C assert to have this removed in opt builds */
- assert(gpr_atm_no_barrier_load(&md->refcnt) >= 1);
- gpr_atm_no_barrier_fetch_add(&md->refcnt, 1);
+ assert (gpr_atm_no_barrier_load (&md->refcnt) >= 1);
+ gpr_atm_no_barrier_fetch_add (&md->refcnt, 1);
return gmd;
}
-void grpc_mdelem_unref(grpc_mdelem *gmd DEBUG_ARGS) {
- internal_metadata *md = (internal_metadata *)gmd;
+void
+grpc_mdelem_unref (grpc_mdelem * gmd DEBUG_ARGS)
+{
+ internal_metadata *md = (internal_metadata *) gmd;
grpc_mdctx *ctx = md->context;
- lock(ctx);
+ lock (ctx);
#ifdef GRPC_METADATA_REFCOUNT_DEBUG
- gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
- "ELM UNREF:%p:%d->%d: '%s' = '%s'", md,
- gpr_atm_no_barrier_load(&md->refcnt),
- gpr_atm_no_barrier_load(&md->refcnt) - 1,
- grpc_mdstr_as_c_string((grpc_mdstr *)md->key),
- grpc_mdstr_as_c_string((grpc_mdstr *)md->value));
+ gpr_log (file, line, GPR_LOG_SEVERITY_DEBUG, "ELM UNREF:%p:%d->%d: '%s' = '%s'", md, gpr_atm_no_barrier_load (&md->refcnt), gpr_atm_no_barrier_load (&md->refcnt) - 1, grpc_mdstr_as_c_string ((grpc_mdstr *) md->key), grpc_mdstr_as_c_string ((grpc_mdstr *) md->value));
#endif
- assert(gpr_atm_no_barrier_load(&md->refcnt) >= 1);
- if (1 == gpr_atm_full_fetch_add(&md->refcnt, -1)) {
- ctx->mdtab_free++;
- }
- unlock(ctx);
+ assert (gpr_atm_no_barrier_load (&md->refcnt) >= 1);
+ if (1 == gpr_atm_full_fetch_add (&md->refcnt, -1))
+ {
+ ctx->mdtab_free++;
+ }
+ unlock (ctx);
}
-const char *grpc_mdstr_as_c_string(grpc_mdstr *s) {
- return (const char *)GPR_SLICE_START_PTR(s->slice);
+const char *
+grpc_mdstr_as_c_string (grpc_mdstr * s)
+{
+ return (const char *) GPR_SLICE_START_PTR (s->slice);
}
-grpc_mdstr *grpc_mdstr_ref(grpc_mdstr *gs DEBUG_ARGS) {
- internal_string *s = (internal_string *)gs;
+grpc_mdstr *
+grpc_mdstr_ref (grpc_mdstr * gs DEBUG_ARGS)
+{
+ internal_string *s = (internal_string *) gs;
grpc_mdctx *ctx = s->context;
- lock(ctx);
- internal_string_ref(s FWD_DEBUG_ARGS);
- unlock(ctx);
+ lock (ctx);
+ internal_string_ref (s FWD_DEBUG_ARGS);
+ unlock (ctx);
return gs;
}
-void grpc_mdstr_unref(grpc_mdstr *gs DEBUG_ARGS) {
- internal_string *s = (internal_string *)gs;
+void
+grpc_mdstr_unref (grpc_mdstr * gs DEBUG_ARGS)
+{
+ internal_string *s = (internal_string *) gs;
grpc_mdctx *ctx = s->context;
- lock(ctx);
- internal_string_unref(s FWD_DEBUG_ARGS);
- unlock(ctx);
+ lock (ctx);
+ internal_string_unref (s FWD_DEBUG_ARGS);
+ unlock (ctx);
}
-size_t grpc_mdctx_get_mdtab_capacity_test_only(grpc_mdctx *ctx) {
+size_t
+grpc_mdctx_get_mdtab_capacity_test_only (grpc_mdctx * ctx)
+{
return ctx->mdtab_capacity;
}
-size_t grpc_mdctx_get_mdtab_count_test_only(grpc_mdctx *ctx) {
+size_t
+grpc_mdctx_get_mdtab_count_test_only (grpc_mdctx * ctx)
+{
return ctx->mdtab_count;
}
-size_t grpc_mdctx_get_mdtab_free_test_only(grpc_mdctx *ctx) {
+size_t
+grpc_mdctx_get_mdtab_free_test_only (grpc_mdctx * ctx)
+{
return ctx->mdtab_free;
}
-void *grpc_mdelem_get_user_data(grpc_mdelem *md,
- void (*if_destroy_func)(void *)) {
- internal_metadata *im = (internal_metadata *)md;
+void *
+grpc_mdelem_get_user_data (grpc_mdelem * md, void (*if_destroy_func) (void *))
+{
+ internal_metadata *im = (internal_metadata *) md;
void *result;
- gpr_mu_lock(&im->mu_user_data);
+ gpr_mu_lock (&im->mu_user_data);
result = im->destroy_user_data == if_destroy_func ? im->user_data : NULL;
- gpr_mu_unlock(&im->mu_user_data);
+ gpr_mu_unlock (&im->mu_user_data);
return result;
}
-void grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *),
- void *user_data) {
- internal_metadata *im = (internal_metadata *)md;
- GPR_ASSERT((user_data == NULL) == (destroy_func == NULL));
- gpr_mu_lock(&im->mu_user_data);
- if (im->destroy_user_data) {
- /* user data can only be set once */
- gpr_mu_unlock(&im->mu_user_data);
- if (destroy_func != NULL) {
- destroy_func(user_data);
+void
+grpc_mdelem_set_user_data (grpc_mdelem * md, void (*destroy_func) (void *), void *user_data)
+{
+ internal_metadata *im = (internal_metadata *) md;
+ GPR_ASSERT ((user_data == NULL) == (destroy_func == NULL));
+ gpr_mu_lock (&im->mu_user_data);
+ if (im->destroy_user_data)
+ {
+ /* user data can only be set once */
+ gpr_mu_unlock (&im->mu_user_data);
+ if (destroy_func != NULL)
+ {
+ destroy_func (user_data);
+ }
+ return;
}
- return;
- }
im->destroy_user_data = destroy_func;
im->user_data = user_data;
- gpr_mu_unlock(&im->mu_user_data);
+ gpr_mu_unlock (&im->mu_user_data);
}
-gpr_slice grpc_mdstr_as_base64_encoded_and_huffman_compressed(grpc_mdstr *gs) {
- internal_string *s = (internal_string *)gs;
+gpr_slice
+grpc_mdstr_as_base64_encoded_and_huffman_compressed (grpc_mdstr * gs)
+{
+ internal_string *s = (internal_string *) gs;
gpr_slice slice;
grpc_mdctx *ctx = s->context;
- lock(ctx);
- if (!s->has_base64_and_huffman_encoded) {
- s->base64_and_huffman =
- grpc_chttp2_base64_encode_and_huffman_compress(s->slice);
- s->has_base64_and_huffman_encoded = 1;
- }
+ lock (ctx);
+ if (!s->has_base64_and_huffman_encoded)
+ {
+ s->base64_and_huffman = grpc_chttp2_base64_encode_and_huffman_compress (s->slice);
+ s->has_base64_and_huffman_encoded = 1;
+ }
slice = s->base64_and_huffman;
- unlock(ctx);
+ unlock (ctx);
return slice;
}
-void grpc_mdctx_lock(grpc_mdctx *ctx) { lock(ctx); }
+void
+grpc_mdctx_lock (grpc_mdctx * ctx)
+{
+ lock (ctx);
+}
-void grpc_mdctx_locked_mdelem_unref(grpc_mdctx *ctx,
- grpc_mdelem *gmd DEBUG_ARGS) {
- internal_metadata *md = (internal_metadata *)gmd;
+void
+grpc_mdctx_locked_mdelem_unref (grpc_mdctx * ctx, grpc_mdelem * gmd DEBUG_ARGS)
+{
+ internal_metadata *md = (internal_metadata *) gmd;
grpc_mdctx *elem_ctx = md->context;
- GPR_ASSERT(ctx == elem_ctx);
+ GPR_ASSERT (ctx == elem_ctx);
#ifdef GRPC_METADATA_REFCOUNT_DEBUG
- gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
- "ELM UNREF:%p:%d->%d: '%s' = '%s'", md,
- gpr_atm_no_barrier_load(&md->refcnt),
- gpr_atm_no_barrier_load(&md->refcnt) - 1,
- grpc_mdstr_as_c_string((grpc_mdstr *)md->key),
- grpc_mdstr_as_c_string((grpc_mdstr *)md->value));
+ gpr_log (file, line, GPR_LOG_SEVERITY_DEBUG, "ELM UNREF:%p:%d->%d: '%s' = '%s'", md, gpr_atm_no_barrier_load (&md->refcnt), gpr_atm_no_barrier_load (&md->refcnt) - 1, grpc_mdstr_as_c_string ((grpc_mdstr *) md->key), grpc_mdstr_as_c_string ((grpc_mdstr *) md->value));
#endif
- assert(gpr_atm_no_barrier_load(&md->refcnt) >= 1);
- if (1 == gpr_atm_full_fetch_add(&md->refcnt, -1)) {
- ctx->mdtab_free++;
- }
-}
-
-void grpc_mdctx_unlock(grpc_mdctx *ctx) { unlock(ctx); }
-
-static int conforms_to(grpc_mdstr *s, const gpr_uint8 *legal_bits) {
- const gpr_uint8 *p = GPR_SLICE_START_PTR(s->slice);
- const gpr_uint8 *e = GPR_SLICE_END_PTR(s->slice);
- for (; p != e; p++) {
- int idx = *p;
- int byte = idx / 8;
- int bit = idx % 8;
- if ((legal_bits[byte] & (1 << bit)) == 0) return 0;
- }
+ assert (gpr_atm_no_barrier_load (&md->refcnt) >= 1);
+ if (1 == gpr_atm_full_fetch_add (&md->refcnt, -1))
+ {
+ ctx->mdtab_free++;
+ }
+}
+
+void
+grpc_mdctx_unlock (grpc_mdctx * ctx)
+{
+ unlock (ctx);
+}
+
+static int
+conforms_to (grpc_mdstr * s, const gpr_uint8 * legal_bits)
+{
+ const gpr_uint8 *p = GPR_SLICE_START_PTR (s->slice);
+ const gpr_uint8 *e = GPR_SLICE_END_PTR (s->slice);
+ for (; p != e; p++)
+ {
+ int idx = *p;
+ int byte = idx / 8;
+ int bit = idx % 8;
+ if ((legal_bits[byte] & (1 << bit)) == 0)
+ return 0;
+ }
return 1;
}
-int grpc_mdstr_is_legal_header(grpc_mdstr *s) {
+int
+grpc_mdstr_is_legal_header (grpc_mdstr * s)
+{
static const gpr_uint8 legal_header_bits[256 / 8] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xff, 0x03, 0x00, 0x00, 0x00,
- 0x80, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- return conforms_to(s, legal_header_bits);
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xff, 0x03, 0x00, 0x00, 0x00,
+ 0x80, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+ return conforms_to (s, legal_header_bits);
}
-int grpc_mdstr_is_legal_nonbin_header(grpc_mdstr *s) {
+int
+grpc_mdstr_is_legal_nonbin_header (grpc_mdstr * s)
+{
static const gpr_uint8 legal_header_bits[256 / 8] = {
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- return conforms_to(s, legal_header_bits);
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+ return conforms_to (s, legal_header_bits);
}
-int grpc_mdstr_is_bin_suffixed(grpc_mdstr *s) {
+int
+grpc_mdstr_is_bin_suffixed (grpc_mdstr * s)
+{
/* TODO(ctiller): consider caching this */
- return grpc_is_binary_header((const char *)GPR_SLICE_START_PTR(s->slice),
- GPR_SLICE_LENGTH(s->slice));
+ return grpc_is_binary_header ((const char *) GPR_SLICE_START_PTR (s->slice), GPR_SLICE_LENGTH (s->slice));
}
diff --git a/src/core/transport/metadata.h b/src/core/transport/metadata.h
index eb17747be7..75d456eeb6 100644
--- a/src/core/transport/metadata.h
+++ b/src/core/transport/metadata.h
@@ -67,7 +67,8 @@ typedef struct grpc_mdstr grpc_mdstr;
typedef struct grpc_mdelem grpc_mdelem;
/* if changing this, make identical changes in internal_string in metadata.c */
-struct grpc_mdstr {
+struct grpc_mdstr
+{
const gpr_slice slice;
const gpr_uint32 hash;
/* there is a private part to this in metadata.c */
@@ -75,58 +76,48 @@ struct grpc_mdstr {
/* if changing this, make identical changes in internal_metadata in
metadata.c */
-struct grpc_mdelem {
+struct grpc_mdelem
+{
grpc_mdstr *const key;
grpc_mdstr *const value;
/* there is a private part to this in metadata.c */
};
/* Create/orphan a metadata context */
-grpc_mdctx *grpc_mdctx_create(void);
-grpc_mdctx *grpc_mdctx_create_with_seed(gpr_uint32 seed);
-void grpc_mdctx_ref(grpc_mdctx *mdctx);
-void grpc_mdctx_unref(grpc_mdctx *mdctx);
+grpc_mdctx *grpc_mdctx_create (void);
+grpc_mdctx *grpc_mdctx_create_with_seed (gpr_uint32 seed);
+void grpc_mdctx_ref (grpc_mdctx * mdctx);
+void grpc_mdctx_unref (grpc_mdctx * mdctx);
/* Test only accessors to internal state - only for testing this code - do not
rely on it outside of metadata_test.c */
-size_t grpc_mdctx_get_mdtab_capacity_test_only(grpc_mdctx *mdctx);
-size_t grpc_mdctx_get_mdtab_count_test_only(grpc_mdctx *mdctx);
-size_t grpc_mdctx_get_mdtab_free_test_only(grpc_mdctx *mdctx);
+size_t grpc_mdctx_get_mdtab_capacity_test_only (grpc_mdctx * mdctx);
+size_t grpc_mdctx_get_mdtab_count_test_only (grpc_mdctx * mdctx);
+size_t grpc_mdctx_get_mdtab_free_test_only (grpc_mdctx * mdctx);
/* Constructors for grpc_mdstr instances; take a variety of data types that
clients may have handy */
-grpc_mdstr *grpc_mdstr_from_string(grpc_mdctx *ctx, const char *str,
- int perform_key_canonicalization);
+grpc_mdstr *grpc_mdstr_from_string (grpc_mdctx * ctx, const char *str, int perform_key_canonicalization);
/* Unrefs the slice. */
-grpc_mdstr *grpc_mdstr_from_slice(grpc_mdctx *ctx, gpr_slice slice);
-grpc_mdstr *grpc_mdstr_from_buffer(grpc_mdctx *ctx, const gpr_uint8 *str,
- size_t length);
+grpc_mdstr *grpc_mdstr_from_slice (grpc_mdctx * ctx, gpr_slice slice);
+grpc_mdstr *grpc_mdstr_from_buffer (grpc_mdctx * ctx, const gpr_uint8 * str, size_t length);
/* Returns a borrowed slice from the mdstr with its contents base64 encoded
and huffman compressed */
-gpr_slice grpc_mdstr_as_base64_encoded_and_huffman_compressed(grpc_mdstr *str);
+gpr_slice grpc_mdstr_as_base64_encoded_and_huffman_compressed (grpc_mdstr * str);
/* Constructors for grpc_mdelem instances; take a variety of data types that
clients may have handy */
-grpc_mdelem *grpc_mdelem_from_metadata_strings(grpc_mdctx *ctx, grpc_mdstr *key,
- grpc_mdstr *value);
-grpc_mdelem *grpc_mdelem_from_strings(grpc_mdctx *ctx, const char *key,
- const char *value);
+grpc_mdelem *grpc_mdelem_from_metadata_strings (grpc_mdctx * ctx, grpc_mdstr * key, grpc_mdstr * value);
+grpc_mdelem *grpc_mdelem_from_strings (grpc_mdctx * ctx, const char *key, const char *value);
/* Unrefs the slices. */
-grpc_mdelem *grpc_mdelem_from_slices(grpc_mdctx *ctx, gpr_slice key,
- gpr_slice value);
-grpc_mdelem *grpc_mdelem_from_string_and_buffer(grpc_mdctx *ctx,
- const char *key,
- const gpr_uint8 *value,
- size_t value_length,
- int canonicalize_key);
+grpc_mdelem *grpc_mdelem_from_slices (grpc_mdctx * ctx, gpr_slice key, gpr_slice value);
+grpc_mdelem *grpc_mdelem_from_string_and_buffer (grpc_mdctx * ctx, const char *key, const gpr_uint8 * value, size_t value_length, int canonicalize_key);
/* Mutator and accessor for grpc_mdelem user data. The destructor function
is used as a type tag and is checked during user_data fetch. */
-void *grpc_mdelem_get_user_data(grpc_mdelem *md,
- void (*if_destroy_func)(void *));
-void grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *),
- void *user_data);
+void *grpc_mdelem_get_user_data (grpc_mdelem * md, void (*if_destroy_func) (void *));
+void grpc_mdelem_set_user_data (grpc_mdelem * md, void (*destroy_func) (void *), void *user_data);
/* Reference counting */
#ifdef GRPC_METADATA_REFCOUNT_DEBUG
@@ -134,28 +125,28 @@ void grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *),
#define GRPC_MDSTR_UNREF(s) grpc_mdstr_unref((s), __FILE__, __LINE__)
#define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s), __FILE__, __LINE__)
#define GRPC_MDELEM_UNREF(s) grpc_mdelem_unref((s), __FILE__, __LINE__)
-grpc_mdstr *grpc_mdstr_ref(grpc_mdstr *s, const char *file, int line);
-void grpc_mdstr_unref(grpc_mdstr *s, const char *file, int line);
-grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *md, const char *file, int line);
-void grpc_mdelem_unref(grpc_mdelem *md, const char *file, int line);
+grpc_mdstr *grpc_mdstr_ref (grpc_mdstr * s, const char *file, int line);
+void grpc_mdstr_unref (grpc_mdstr * s, const char *file, int line);
+grpc_mdelem *grpc_mdelem_ref (grpc_mdelem * md, const char *file, int line);
+void grpc_mdelem_unref (grpc_mdelem * md, const char *file, int line);
#else
#define GRPC_MDSTR_REF(s) grpc_mdstr_ref((s))
#define GRPC_MDSTR_UNREF(s) grpc_mdstr_unref((s))
#define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s))
#define GRPC_MDELEM_UNREF(s) grpc_mdelem_unref((s))
-grpc_mdstr *grpc_mdstr_ref(grpc_mdstr *s);
-void grpc_mdstr_unref(grpc_mdstr *s);
-grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *md);
-void grpc_mdelem_unref(grpc_mdelem *md);
+grpc_mdstr *grpc_mdstr_ref (grpc_mdstr * s);
+void grpc_mdstr_unref (grpc_mdstr * s);
+grpc_mdelem *grpc_mdelem_ref (grpc_mdelem * md);
+void grpc_mdelem_unref (grpc_mdelem * md);
#endif
/* Recover a char* from a grpc_mdstr. The returned string is null terminated.
Does not promise that the returned string has no embedded nulls however. */
-const char *grpc_mdstr_as_c_string(grpc_mdstr *s);
+const char *grpc_mdstr_as_c_string (grpc_mdstr * s);
-int grpc_mdstr_is_legal_header(grpc_mdstr *s);
-int grpc_mdstr_is_legal_nonbin_header(grpc_mdstr *s);
-int grpc_mdstr_is_bin_suffixed(grpc_mdstr *s);
+int grpc_mdstr_is_legal_header (grpc_mdstr * s);
+int grpc_mdstr_is_legal_nonbin_header (grpc_mdstr * s);
+int grpc_mdstr_is_bin_suffixed (grpc_mdstr * s);
/* Batch mode metadata functions.
These API's have equivalents above, but allow taking the mdctx just once,
@@ -163,21 +154,20 @@ int grpc_mdstr_is_bin_suffixed(grpc_mdstr *s);
/* Lock the metadata context: it's only safe to call _locked_ functions against
this context from the calling thread until grpc_mdctx_unlock is called */
-void grpc_mdctx_lock(grpc_mdctx *ctx);
+void grpc_mdctx_lock (grpc_mdctx * ctx);
#ifdef GRPC_METADATA_REFCOUNT_DEBUG
#define GRPC_MDCTX_LOCKED_MDELEM_UNREF(ctx, elem) \
grpc_mdctx_locked_mdelem_unref((ctx), (elem), __FILE__, __LINE__)
/* Unref a metadata element */
-void grpc_mdctx_locked_mdelem_unref(grpc_mdctx *ctx, grpc_mdelem *elem,
- const char *file, int line);
+void grpc_mdctx_locked_mdelem_unref (grpc_mdctx * ctx, grpc_mdelem * elem, const char *file, int line);
#else
#define GRPC_MDCTX_LOCKED_MDELEM_UNREF(ctx, elem) \
grpc_mdctx_locked_mdelem_unref((ctx), (elem))
/* Unref a metadata element */
-void grpc_mdctx_locked_mdelem_unref(grpc_mdctx *ctx, grpc_mdelem *elem);
+void grpc_mdctx_locked_mdelem_unref (grpc_mdctx * ctx, grpc_mdelem * elem);
#endif
/* Unlock the metadata context */
-void grpc_mdctx_unlock(grpc_mdctx *ctx);
+void grpc_mdctx_unlock (grpc_mdctx * ctx);
#define GRPC_MDSTR_KV_HASH(k_hash, v_hash) (GPR_ROTL((k_hash), 2) ^ (v_hash))
diff --git a/src/core/transport/stream_op.c b/src/core/transport/stream_op.c
index 038586d48e..f188c7d1ae 100644
--- a/src/core/transport/stream_op.c
+++ b/src/core/transport/stream_op.c
@@ -42,290 +42,367 @@
Currently we grow by 1.5 times upon reallocation. */
#define GROW(x) (3 * (x) / 2)
-void grpc_sopb_init(grpc_stream_op_buffer *sopb) {
+void
+grpc_sopb_init (grpc_stream_op_buffer * sopb)
+{
sopb->ops = sopb->inlined_ops;
sopb->nops = 0;
sopb->capacity = GRPC_SOPB_INLINE_ELEMENTS;
}
-void grpc_sopb_destroy(grpc_stream_op_buffer *sopb) {
- grpc_stream_ops_unref_owned_objects(sopb->ops, sopb->nops);
- if (sopb->ops != sopb->inlined_ops) gpr_free(sopb->ops);
+void
+grpc_sopb_destroy (grpc_stream_op_buffer * sopb)
+{
+ grpc_stream_ops_unref_owned_objects (sopb->ops, sopb->nops);
+ if (sopb->ops != sopb->inlined_ops)
+ gpr_free (sopb->ops);
}
-void grpc_sopb_reset(grpc_stream_op_buffer *sopb) {
- grpc_stream_ops_unref_owned_objects(sopb->ops, sopb->nops);
+void
+grpc_sopb_reset (grpc_stream_op_buffer * sopb)
+{
+ grpc_stream_ops_unref_owned_objects (sopb->ops, sopb->nops);
sopb->nops = 0;
}
-void grpc_sopb_swap(grpc_stream_op_buffer *a, grpc_stream_op_buffer *b) {
- GPR_SWAP(size_t, a->nops, b->nops);
- GPR_SWAP(size_t, a->capacity, b->capacity);
-
- if (a->ops == a->inlined_ops) {
- if (b->ops == b->inlined_ops) {
- /* swap contents of inlined buffer */
- grpc_stream_op temp[GRPC_SOPB_INLINE_ELEMENTS];
- memcpy(temp, a->ops, b->nops * sizeof(grpc_stream_op));
- memcpy(a->ops, b->ops, a->nops * sizeof(grpc_stream_op));
- memcpy(b->ops, temp, b->nops * sizeof(grpc_stream_op));
- } else {
- /* a is inlined, b is not - copy a inlined into b, fix pointers */
- a->ops = b->ops;
- b->ops = b->inlined_ops;
- memcpy(b->ops, a->inlined_ops, b->nops * sizeof(grpc_stream_op));
+void
+grpc_sopb_swap (grpc_stream_op_buffer * a, grpc_stream_op_buffer * b)
+{
+ GPR_SWAP (size_t, a->nops, b->nops);
+ GPR_SWAP (size_t, a->capacity, b->capacity);
+
+ if (a->ops == a->inlined_ops)
+ {
+ if (b->ops == b->inlined_ops)
+ {
+ /* swap contents of inlined buffer */
+ grpc_stream_op temp[GRPC_SOPB_INLINE_ELEMENTS];
+ memcpy (temp, a->ops, b->nops * sizeof (grpc_stream_op));
+ memcpy (a->ops, b->ops, a->nops * sizeof (grpc_stream_op));
+ memcpy (b->ops, temp, b->nops * sizeof (grpc_stream_op));
+ }
+ else
+ {
+ /* a is inlined, b is not - copy a inlined into b, fix pointers */
+ a->ops = b->ops;
+ b->ops = b->inlined_ops;
+ memcpy (b->ops, a->inlined_ops, b->nops * sizeof (grpc_stream_op));
+ }
+ }
+ else if (b->ops == b->inlined_ops)
+ {
+ /* b is inlined, a is not - copy b inlined int a, fix pointers */
+ b->ops = a->ops;
+ a->ops = a->inlined_ops;
+ memcpy (a->ops, b->inlined_ops, a->nops * sizeof (grpc_stream_op));
+ }
+ else
+ {
+ /* no inlining: easy swap */
+ GPR_SWAP (grpc_stream_op *, a->ops, b->ops);
}
- } else if (b->ops == b->inlined_ops) {
- /* b is inlined, a is not - copy b inlined int a, fix pointers */
- b->ops = a->ops;
- a->ops = a->inlined_ops;
- memcpy(a->ops, b->inlined_ops, a->nops * sizeof(grpc_stream_op));
- } else {
- /* no inlining: easy swap */
- GPR_SWAP(grpc_stream_op *, a->ops, b->ops);
- }
}
-void grpc_stream_ops_unref_owned_objects(grpc_stream_op *ops, size_t nops) {
+void
+grpc_stream_ops_unref_owned_objects (grpc_stream_op * ops, size_t nops)
+{
size_t i;
- for (i = 0; i < nops; i++) {
- switch (ops[i].type) {
- case GRPC_OP_SLICE:
- gpr_slice_unref(ops[i].data.slice);
- break;
- case GRPC_OP_METADATA:
- grpc_metadata_batch_destroy(&ops[i].data.metadata);
- break;
- case GRPC_NO_OP:
- case GRPC_OP_BEGIN_MESSAGE:
- break;
+ for (i = 0; i < nops; i++)
+ {
+ switch (ops[i].type)
+ {
+ case GRPC_OP_SLICE:
+ gpr_slice_unref (ops[i].data.slice);
+ break;
+ case GRPC_OP_METADATA:
+ grpc_metadata_batch_destroy (&ops[i].data.metadata);
+ break;
+ case GRPC_NO_OP:
+ case GRPC_OP_BEGIN_MESSAGE:
+ break;
+ }
}
- }
}
-static void expandto(grpc_stream_op_buffer *sopb, size_t new_capacity) {
+static void
+expandto (grpc_stream_op_buffer * sopb, size_t new_capacity)
+{
sopb->capacity = new_capacity;
- if (sopb->ops == sopb->inlined_ops) {
- sopb->ops = gpr_malloc(sizeof(grpc_stream_op) * new_capacity);
- memcpy(sopb->ops, sopb->inlined_ops, sopb->nops * sizeof(grpc_stream_op));
- } else {
- sopb->ops = gpr_realloc(sopb->ops, sizeof(grpc_stream_op) * new_capacity);
- }
+ if (sopb->ops == sopb->inlined_ops)
+ {
+ sopb->ops = gpr_malloc (sizeof (grpc_stream_op) * new_capacity);
+ memcpy (sopb->ops, sopb->inlined_ops, sopb->nops * sizeof (grpc_stream_op));
+ }
+ else
+ {
+ sopb->ops = gpr_realloc (sopb->ops, sizeof (grpc_stream_op) * new_capacity);
+ }
}
-static grpc_stream_op *add(grpc_stream_op_buffer *sopb) {
+static grpc_stream_op *
+add (grpc_stream_op_buffer * sopb)
+{
grpc_stream_op *out;
- GPR_ASSERT(sopb->nops <= sopb->capacity);
- if (sopb->nops == sopb->capacity) {
- expandto(sopb, GROW(sopb->capacity));
- }
+ GPR_ASSERT (sopb->nops <= sopb->capacity);
+ if (sopb->nops == sopb->capacity)
+ {
+ expandto (sopb, GROW (sopb->capacity));
+ }
out = sopb->ops + sopb->nops;
sopb->nops++;
return out;
}
-void grpc_sopb_add_no_op(grpc_stream_op_buffer *sopb) {
- add(sopb)->type = GRPC_NO_OP;
+void
+grpc_sopb_add_no_op (grpc_stream_op_buffer * sopb)
+{
+ add (sopb)->type = GRPC_NO_OP;
}
-void grpc_sopb_add_begin_message(grpc_stream_op_buffer *sopb, gpr_uint32 length,
- gpr_uint32 flags) {
- grpc_stream_op *op = add(sopb);
+void
+grpc_sopb_add_begin_message (grpc_stream_op_buffer * sopb, gpr_uint32 length, gpr_uint32 flags)
+{
+ grpc_stream_op *op = add (sopb);
op->type = GRPC_OP_BEGIN_MESSAGE;
op->data.begin_message.length = length;
op->data.begin_message.flags = flags;
}
-void grpc_sopb_add_metadata(grpc_stream_op_buffer *sopb,
- grpc_metadata_batch b) {
- grpc_stream_op *op = add(sopb);
+void
+grpc_sopb_add_metadata (grpc_stream_op_buffer * sopb, grpc_metadata_batch b)
+{
+ grpc_stream_op *op = add (sopb);
op->type = GRPC_OP_METADATA;
op->data.metadata = b;
}
-void grpc_sopb_add_slice(grpc_stream_op_buffer *sopb, gpr_slice slice) {
- grpc_stream_op *op = add(sopb);
+void
+grpc_sopb_add_slice (grpc_stream_op_buffer * sopb, gpr_slice slice)
+{
+ grpc_stream_op *op = add (sopb);
op->type = GRPC_OP_SLICE;
op->data.slice = slice;
}
-void grpc_sopb_append(grpc_stream_op_buffer *sopb, grpc_stream_op *ops,
- size_t nops) {
+void
+grpc_sopb_append (grpc_stream_op_buffer * sopb, grpc_stream_op * ops, size_t nops)
+{
size_t orig_nops = sopb->nops;
size_t new_nops = orig_nops + nops;
- if (new_nops > sopb->capacity) {
- expandto(sopb, GPR_MAX(GROW(sopb->capacity), new_nops));
- }
+ if (new_nops > sopb->capacity)
+ {
+ expandto (sopb, GPR_MAX (GROW (sopb->capacity), new_nops));
+ }
- memcpy(sopb->ops + orig_nops, ops, sizeof(grpc_stream_op) * nops);
+ memcpy (sopb->ops + orig_nops, ops, sizeof (grpc_stream_op) * nops);
sopb->nops = new_nops;
}
-void grpc_sopb_move_to(grpc_stream_op_buffer *src, grpc_stream_op_buffer *dst) {
- if (src->nops == 0) {
- return;
- }
- if (dst->nops == 0) {
- grpc_sopb_swap(src, dst);
- return;
- }
- grpc_sopb_append(dst, src->ops, src->nops);
+void
+grpc_sopb_move_to (grpc_stream_op_buffer * src, grpc_stream_op_buffer * dst)
+{
+ if (src->nops == 0)
+ {
+ return;
+ }
+ if (dst->nops == 0)
+ {
+ grpc_sopb_swap (src, dst);
+ return;
+ }
+ grpc_sopb_append (dst, src->ops, src->nops);
src->nops = 0;
}
-static void assert_valid_list(grpc_mdelem_list *list) {
+static void
+assert_valid_list (grpc_mdelem_list * list)
+{
#ifndef NDEBUG
grpc_linked_mdelem *l;
- GPR_ASSERT((list->head == NULL) == (list->tail == NULL));
- if (!list->head) return;
- GPR_ASSERT(list->head->prev == NULL);
- GPR_ASSERT(list->tail->next == NULL);
- GPR_ASSERT((list->head == list->tail) == (list->head->next == NULL));
-
- for (l = list->head; l; l = l->next) {
- GPR_ASSERT(l->md);
- GPR_ASSERT((l->prev == NULL) == (l == list->head));
- GPR_ASSERT((l->next == NULL) == (l == list->tail));
- if (l->next) GPR_ASSERT(l->next->prev == l);
- if (l->prev) GPR_ASSERT(l->prev->next == l);
- }
+ GPR_ASSERT ((list->head == NULL) == (list->tail == NULL));
+ if (!list->head)
+ return;
+ GPR_ASSERT (list->head->prev == NULL);
+ GPR_ASSERT (list->tail->next == NULL);
+ GPR_ASSERT ((list->head == list->tail) == (list->head->next == NULL));
+
+ for (l = list->head; l; l = l->next)
+ {
+ GPR_ASSERT (l->md);
+ GPR_ASSERT ((l->prev == NULL) == (l == list->head));
+ GPR_ASSERT ((l->next == NULL) == (l == list->tail));
+ if (l->next)
+ GPR_ASSERT (l->next->prev == l);
+ if (l->prev)
+ GPR_ASSERT (l->prev->next == l);
+ }
#endif /* NDEBUG */
}
#ifndef NDEBUG
-void grpc_metadata_batch_assert_ok(grpc_metadata_batch *batch) {
- assert_valid_list(&batch->list);
- assert_valid_list(&batch->garbage);
+void
+grpc_metadata_batch_assert_ok (grpc_metadata_batch * batch)
+{
+ assert_valid_list (&batch->list);
+ assert_valid_list (&batch->garbage);
}
#endif /* NDEBUG */
-void grpc_metadata_batch_init(grpc_metadata_batch *batch) {
- batch->list.head = batch->list.tail = batch->garbage.head =
- batch->garbage.tail = NULL;
- batch->deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
+void
+grpc_metadata_batch_init (grpc_metadata_batch * batch)
+{
+ batch->list.head = batch->list.tail = batch->garbage.head = batch->garbage.tail = NULL;
+ batch->deadline = gpr_inf_future (GPR_CLOCK_REALTIME);
}
-void grpc_metadata_batch_destroy(grpc_metadata_batch *batch) {
+void
+grpc_metadata_batch_destroy (grpc_metadata_batch * batch)
+{
grpc_linked_mdelem *l;
- for (l = batch->list.head; l; l = l->next) {
- GRPC_MDELEM_UNREF(l->md);
- }
- for (l = batch->garbage.head; l; l = l->next) {
- GRPC_MDELEM_UNREF(l->md);
- }
+ for (l = batch->list.head; l; l = l->next)
+ {
+ GRPC_MDELEM_UNREF (l->md);
+ }
+ for (l = batch->garbage.head; l; l = l->next)
+ {
+ GRPC_MDELEM_UNREF (l->md);
+ }
}
-void grpc_metadata_batch_add_head(grpc_metadata_batch *batch,
- grpc_linked_mdelem *storage,
- grpc_mdelem *elem_to_add) {
- GPR_ASSERT(elem_to_add);
+void
+grpc_metadata_batch_add_head (grpc_metadata_batch * batch, grpc_linked_mdelem * storage, grpc_mdelem * elem_to_add)
+{
+ GPR_ASSERT (elem_to_add);
storage->md = elem_to_add;
- grpc_metadata_batch_link_head(batch, storage);
+ grpc_metadata_batch_link_head (batch, storage);
}
-static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) {
- assert_valid_list(list);
- GPR_ASSERT(storage->md);
+static void
+link_head (grpc_mdelem_list * list, grpc_linked_mdelem * storage)
+{
+ assert_valid_list (list);
+ GPR_ASSERT (storage->md);
storage->prev = NULL;
storage->next = list->head;
- if (list->head != NULL) {
- list->head->prev = storage;
- } else {
- list->tail = storage;
- }
+ if (list->head != NULL)
+ {
+ list->head->prev = storage;
+ }
+ else
+ {
+ list->tail = storage;
+ }
list->head = storage;
- assert_valid_list(list);
+ assert_valid_list (list);
}
-void grpc_metadata_batch_link_head(grpc_metadata_batch *batch,
- grpc_linked_mdelem *storage) {
- link_head(&batch->list, storage);
+void
+grpc_metadata_batch_link_head (grpc_metadata_batch * batch, grpc_linked_mdelem * storage)
+{
+ link_head (&batch->list, storage);
}
-void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch,
- grpc_linked_mdelem *storage,
- grpc_mdelem *elem_to_add) {
- GPR_ASSERT(elem_to_add);
+void
+grpc_metadata_batch_add_tail (grpc_metadata_batch * batch, grpc_linked_mdelem * storage, grpc_mdelem * elem_to_add)
+{
+ GPR_ASSERT (elem_to_add);
storage->md = elem_to_add;
- grpc_metadata_batch_link_tail(batch, storage);
+ grpc_metadata_batch_link_tail (batch, storage);
}
-static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) {
- assert_valid_list(list);
- GPR_ASSERT(storage->md);
+static void
+link_tail (grpc_mdelem_list * list, grpc_linked_mdelem * storage)
+{
+ assert_valid_list (list);
+ GPR_ASSERT (storage->md);
storage->prev = list->tail;
storage->next = NULL;
storage->reserved = NULL;
- if (list->tail != NULL) {
- list->tail->next = storage;
- } else {
- list->head = storage;
- }
+ if (list->tail != NULL)
+ {
+ list->tail->next = storage;
+ }
+ else
+ {
+ list->head = storage;
+ }
list->tail = storage;
- assert_valid_list(list);
+ assert_valid_list (list);
}
-void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch,
- grpc_linked_mdelem *storage) {
- link_tail(&batch->list, storage);
+void
+grpc_metadata_batch_link_tail (grpc_metadata_batch * batch, grpc_linked_mdelem * storage)
+{
+ link_tail (&batch->list, storage);
}
-void grpc_metadata_batch_merge(grpc_metadata_batch *target,
- grpc_metadata_batch *add) {
+void
+grpc_metadata_batch_merge (grpc_metadata_batch * target, grpc_metadata_batch * add)
+{
grpc_linked_mdelem *l;
grpc_linked_mdelem *next;
- for (l = add->list.head; l; l = next) {
- next = l->next;
- link_tail(&target->list, l);
- }
- for (l = add->garbage.head; l; l = next) {
- next = l->next;
- link_tail(&target->garbage, l);
- }
+ for (l = add->list.head; l; l = next)
+ {
+ next = l->next;
+ link_tail (&target->list, l);
+ }
+ for (l = add->garbage.head; l; l = next)
+ {
+ next = l->next;
+ link_tail (&target->garbage, l);
+ }
}
-void grpc_metadata_batch_move(grpc_metadata_batch *dst,
- grpc_metadata_batch *src) {
+void
+grpc_metadata_batch_move (grpc_metadata_batch * dst, grpc_metadata_batch * src)
+{
*dst = *src;
- memset(src, 0, sizeof(grpc_metadata_batch));
+ memset (src, 0, sizeof (grpc_metadata_batch));
}
-void grpc_metadata_batch_filter(grpc_metadata_batch *batch,
- grpc_mdelem *(*filter)(void *user_data,
- grpc_mdelem *elem),
- void *user_data) {
+void
+grpc_metadata_batch_filter (grpc_metadata_batch * batch, grpc_mdelem * (*filter) (void *user_data, grpc_mdelem * elem), void *user_data)
+{
grpc_linked_mdelem *l;
grpc_linked_mdelem *next;
- assert_valid_list(&batch->list);
- assert_valid_list(&batch->garbage);
- for (l = batch->list.head; l; l = next) {
- grpc_mdelem *orig = l->md;
- grpc_mdelem *filt = filter(user_data, orig);
- next = l->next;
- if (filt == NULL) {
- if (l->prev) {
- l->prev->next = l->next;
- }
- if (l->next) {
- l->next->prev = l->prev;
- }
- if (batch->list.head == l) {
- batch->list.head = l->next;
- }
- if (batch->list.tail == l) {
- batch->list.tail = l->prev;
- }
- assert_valid_list(&batch->list);
- link_head(&batch->garbage, l);
- } else if (filt != orig) {
- GRPC_MDELEM_UNREF(orig);
- l->md = filt;
+ assert_valid_list (&batch->list);
+ assert_valid_list (&batch->garbage);
+ for (l = batch->list.head; l; l = next)
+ {
+ grpc_mdelem *orig = l->md;
+ grpc_mdelem *filt = filter (user_data, orig);
+ next = l->next;
+ if (filt == NULL)
+ {
+ if (l->prev)
+ {
+ l->prev->next = l->next;
+ }
+ if (l->next)
+ {
+ l->next->prev = l->prev;
+ }
+ if (batch->list.head == l)
+ {
+ batch->list.head = l->next;
+ }
+ if (batch->list.tail == l)
+ {
+ batch->list.tail = l->prev;
+ }
+ assert_valid_list (&batch->list);
+ link_head (&batch->garbage, l);
+ }
+ else if (filt != orig)
+ {
+ GRPC_MDELEM_UNREF (orig);
+ l->md = filt;
+ }
}
- }
- assert_valid_list(&batch->list);
- assert_valid_list(&batch->garbage);
+ assert_valid_list (&batch->list);
+ assert_valid_list (&batch->garbage);
}
diff --git a/src/core/transport/stream_op.h b/src/core/transport/stream_op.h
index 37f18b02d9..e37ab09f71 100644
--- a/src/core/transport/stream_op.h
+++ b/src/core/transport/stream_op.h
@@ -45,7 +45,8 @@
/* Operations that can be performed on a stream.
Used by grpc_stream_op. */
-typedef enum grpc_stream_op_code {
+typedef enum grpc_stream_op_code
+{
/* Do nothing code. Useful if rewriting a batch to exclude some operations.
Must be ignored by receivers */
GRPC_NO_OP,
@@ -65,7 +66,8 @@ typedef enum grpc_stream_op_code {
#define GRPC_WRITE_INTERNAL_USED_MASK (GRPC_WRITE_INTERNAL_COMPRESS)
/* Arguments for GRPC_OP_BEGIN_MESSAGE */
-typedef struct grpc_begin_message {
+typedef struct grpc_begin_message
+{
/* How many bytes of data will this message contain */
gpr_uint32 length;
/* Write flags for the message: see grpc.h GRPC_WRITE_* for the public bits,
@@ -73,19 +75,22 @@ typedef struct grpc_begin_message {
gpr_uint32 flags;
} grpc_begin_message;
-typedef struct grpc_linked_mdelem {
+typedef struct grpc_linked_mdelem
+{
grpc_mdelem *md;
struct grpc_linked_mdelem *next;
struct grpc_linked_mdelem *prev;
void *reserved;
} grpc_linked_mdelem;
-typedef struct grpc_mdelem_list {
+typedef struct grpc_mdelem_list
+{
grpc_linked_mdelem *head;
grpc_linked_mdelem *tail;
} grpc_mdelem_list;
-typedef struct grpc_metadata_batch {
+typedef struct grpc_metadata_batch
+{
/** Metadata elements in this batch */
grpc_mdelem_list list;
/** Elements that have been removed from the batch, but have
@@ -98,30 +103,26 @@ typedef struct grpc_metadata_batch {
gpr_timespec deadline;
} grpc_metadata_batch;
-void grpc_metadata_batch_init(grpc_metadata_batch *batch);
-void grpc_metadata_batch_destroy(grpc_metadata_batch *batch);
-void grpc_metadata_batch_merge(grpc_metadata_batch *target,
- grpc_metadata_batch *add);
+void grpc_metadata_batch_init (grpc_metadata_batch * batch);
+void grpc_metadata_batch_destroy (grpc_metadata_batch * batch);
+void grpc_metadata_batch_merge (grpc_metadata_batch * target, grpc_metadata_batch * add);
/** Moves the metadata information from \a src to \a dst. Upon return, \a src is
* zeroed. */
-void grpc_metadata_batch_move(grpc_metadata_batch *dst,
- grpc_metadata_batch *src);
+void grpc_metadata_batch_move (grpc_metadata_batch * dst, grpc_metadata_batch * src);
/** Add \a storage to the beginning of \a batch. storage->md is
assumed to be valid.
\a storage is owned by the caller and must survive for the
lifetime of batch. This usually means it should be around
for the lifetime of the call. */
-void grpc_metadata_batch_link_head(grpc_metadata_batch *batch,
- grpc_linked_mdelem *storage);
+void grpc_metadata_batch_link_head (grpc_metadata_batch * batch, grpc_linked_mdelem * storage);
/** Add \a storage to the end of \a batch. storage->md is
assumed to be valid.
\a storage is owned by the caller and must survive for the
lifetime of batch. This usually means it should be around
for the lifetime of the call. */
-void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch,
- grpc_linked_mdelem *storage);
+void grpc_metadata_batch_link_tail (grpc_metadata_batch * batch, grpc_linked_mdelem * storage);
/** Add \a elem_to_add as the first element in \a batch, using
\a storage as backing storage for the linked list element.
@@ -129,30 +130,23 @@ void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch,
lifetime of batch. This usually means it should be around
for the lifetime of the call.
Takes ownership of \a elem_to_add */
-void grpc_metadata_batch_add_head(grpc_metadata_batch *batch,
- grpc_linked_mdelem *storage,
- grpc_mdelem *elem_to_add);
+void grpc_metadata_batch_add_head (grpc_metadata_batch * batch, grpc_linked_mdelem * storage, grpc_mdelem * elem_to_add);
/** Add \a elem_to_add as the last element in \a batch, using
\a storage as backing storage for the linked list element.
\a storage is owned by the caller and must survive for the
lifetime of batch. This usually means it should be around
for the lifetime of the call.
Takes ownership of \a elem_to_add */
-void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch,
- grpc_linked_mdelem *storage,
- grpc_mdelem *elem_to_add);
+void grpc_metadata_batch_add_tail (grpc_metadata_batch * batch, grpc_linked_mdelem * storage, grpc_mdelem * elem_to_add);
/** For each element in \a batch, execute \a filter.
The return value from \a filter will be substituted for the
grpc_mdelem passed to \a filter. If \a filter returns NULL,
the element will be moved to the garbage list. */
-void grpc_metadata_batch_filter(grpc_metadata_batch *batch,
- grpc_mdelem *(*filter)(void *user_data,
- grpc_mdelem *elem),
- void *user_data);
+void grpc_metadata_batch_filter (grpc_metadata_batch * batch, grpc_mdelem * (*filter) (void *user_data, grpc_mdelem * elem), void *user_data);
#ifndef NDEBUG
-void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd);
+void grpc_metadata_batch_assert_ok (grpc_metadata_batch * comd);
#else
#define grpc_metadata_batch_assert_ok(comd) \
do { \
@@ -160,12 +154,14 @@ void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd);
#endif
/* Represents a single operation performed on a stream/transport */
-typedef struct grpc_stream_op {
+typedef struct grpc_stream_op
+{
/* the operation to be applied */
enum grpc_stream_op_code type;
/* the arguments to this operation. union fields are named according to the
associated op-code */
- union {
+ union
+ {
grpc_begin_message begin_message;
grpc_metadata_batch metadata;
gpr_slice slice;
@@ -174,7 +170,8 @@ typedef struct grpc_stream_op {
/** A stream op buffer is a wrapper around stream operations that is
* dynamically extendable. */
-typedef struct grpc_stream_op_buffer {
+typedef struct grpc_stream_op_buffer
+{
grpc_stream_op *ops;
size_t nops;
size_t capacity;
@@ -182,31 +179,28 @@ typedef struct grpc_stream_op_buffer {
} grpc_stream_op_buffer;
/* Initialize a stream op buffer */
-void grpc_sopb_init(grpc_stream_op_buffer *sopb);
+void grpc_sopb_init (grpc_stream_op_buffer * sopb);
/* Destroy a stream op buffer */
-void grpc_sopb_destroy(grpc_stream_op_buffer *sopb);
+void grpc_sopb_destroy (grpc_stream_op_buffer * sopb);
/* Reset a sopb to no elements */
-void grpc_sopb_reset(grpc_stream_op_buffer *sopb);
+void grpc_sopb_reset (grpc_stream_op_buffer * sopb);
/* Swap two sopbs */
-void grpc_sopb_swap(grpc_stream_op_buffer *a, grpc_stream_op_buffer *b);
+void grpc_sopb_swap (grpc_stream_op_buffer * a, grpc_stream_op_buffer * b);
-void grpc_stream_ops_unref_owned_objects(grpc_stream_op *ops, size_t nops);
+void grpc_stream_ops_unref_owned_objects (grpc_stream_op * ops, size_t nops);
/* Append a GRPC_NO_OP to a buffer */
-void grpc_sopb_add_no_op(grpc_stream_op_buffer *sopb);
+void grpc_sopb_add_no_op (grpc_stream_op_buffer * sopb);
/* Append a GRPC_OP_BEGIN to a buffer */
-void grpc_sopb_add_begin_message(grpc_stream_op_buffer *sopb, gpr_uint32 length,
- gpr_uint32 flags);
-void grpc_sopb_add_metadata(grpc_stream_op_buffer *sopb,
- grpc_metadata_batch metadata);
+void grpc_sopb_add_begin_message (grpc_stream_op_buffer * sopb, gpr_uint32 length, gpr_uint32 flags);
+void grpc_sopb_add_metadata (grpc_stream_op_buffer * sopb, grpc_metadata_batch metadata);
/* Append a GRPC_SLICE to a buffer - does not ref/unref the slice */
-void grpc_sopb_add_slice(grpc_stream_op_buffer *sopb, gpr_slice slice);
+void grpc_sopb_add_slice (grpc_stream_op_buffer * sopb, gpr_slice slice);
/* Append a buffer to a buffer - does not ref/unref any internal objects */
-void grpc_sopb_append(grpc_stream_op_buffer *sopb, grpc_stream_op *ops,
- size_t nops);
+void grpc_sopb_append (grpc_stream_op_buffer * sopb, grpc_stream_op * ops, size_t nops);
-void grpc_sopb_move_to(grpc_stream_op_buffer *src, grpc_stream_op_buffer *dst);
+void grpc_sopb_move_to (grpc_stream_op_buffer * src, grpc_stream_op_buffer * dst);
-char *grpc_sopb_string(grpc_stream_op_buffer *sopb);
+char *grpc_sopb_string (grpc_stream_op_buffer * sopb);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_STREAM_OP_H */
diff --git a/src/core/transport/transport.c b/src/core/transport/transport.c
index 24d549a29b..1288d6d04d 100644
--- a/src/core/transport/transport.c
+++ b/src/core/transport/transport.c
@@ -36,103 +36,115 @@
#include <grpc/support/log.h>
#include "src/core/transport/transport_impl.h"
-size_t grpc_transport_stream_size(grpc_transport *transport) {
+size_t
+grpc_transport_stream_size (grpc_transport * transport)
+{
return transport->vtable->sizeof_stream;
}
-void grpc_transport_destroy(grpc_transport *transport,
- grpc_closure_list *closure_list) {
- transport->vtable->destroy(transport, closure_list);
+void
+grpc_transport_destroy (grpc_transport * transport, grpc_closure_list * closure_list)
+{
+ transport->vtable->destroy (transport, closure_list);
}
-int grpc_transport_init_stream(grpc_transport *transport, grpc_stream *stream,
- const void *server_data,
- grpc_transport_stream_op *initial_op,
- grpc_closure_list *closure_list) {
- return transport->vtable->init_stream(transport, stream, server_data,
- initial_op, closure_list);
+int
+grpc_transport_init_stream (grpc_transport * transport, grpc_stream * stream, const void *server_data, grpc_transport_stream_op * initial_op, grpc_closure_list * closure_list)
+{
+ return transport->vtable->init_stream (transport, stream, server_data, initial_op, closure_list);
}
-void grpc_transport_perform_stream_op(grpc_transport *transport,
- grpc_stream *stream,
- grpc_transport_stream_op *op,
- grpc_closure_list *closure_list) {
- transport->vtable->perform_stream_op(transport, stream, op, closure_list);
+void
+grpc_transport_perform_stream_op (grpc_transport * transport, grpc_stream * stream, grpc_transport_stream_op * op, grpc_closure_list * closure_list)
+{
+ transport->vtable->perform_stream_op (transport, stream, op, closure_list);
}
-void grpc_transport_perform_op(grpc_transport *transport, grpc_transport_op *op,
- grpc_closure_list *closure_list) {
- transport->vtable->perform_op(transport, op, closure_list);
+void
+grpc_transport_perform_op (grpc_transport * transport, grpc_transport_op * op, grpc_closure_list * closure_list)
+{
+ transport->vtable->perform_op (transport, op, closure_list);
}
-void grpc_transport_destroy_stream(grpc_transport *transport,
- grpc_stream *stream,
- grpc_closure_list *closure_list) {
- transport->vtable->destroy_stream(transport, stream, closure_list);
+void
+grpc_transport_destroy_stream (grpc_transport * transport, grpc_stream * stream, grpc_closure_list * closure_list)
+{
+ transport->vtable->destroy_stream (transport, stream, closure_list);
}
-char *grpc_transport_get_peer(grpc_transport *transport,
- grpc_closure_list *closure_list) {
- return transport->vtable->get_peer(transport, closure_list);
+char *
+grpc_transport_get_peer (grpc_transport * transport, grpc_closure_list * closure_list)
+{
+ return transport->vtable->get_peer (transport, closure_list);
}
-void grpc_transport_stream_op_finish_with_failure(
- grpc_transport_stream_op *op, grpc_closure_list *closure_list) {
- grpc_closure_list_add(closure_list, op->on_done_recv, 0);
- grpc_closure_list_add(closure_list, op->on_done_send, 0);
- grpc_closure_list_add(closure_list, op->on_consumed, 0);
+void
+grpc_transport_stream_op_finish_with_failure (grpc_transport_stream_op * op, grpc_closure_list * closure_list)
+{
+ grpc_closure_list_add (closure_list, op->on_done_recv, 0);
+ grpc_closure_list_add (closure_list, op->on_done_send, 0);
+ grpc_closure_list_add (closure_list, op->on_consumed, 0);
}
-void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op,
- grpc_status_code status) {
- GPR_ASSERT(status != GRPC_STATUS_OK);
- if (op->cancel_with_status == GRPC_STATUS_OK) {
- op->cancel_with_status = status;
- }
- if (op->close_with_status != GRPC_STATUS_OK) {
- op->close_with_status = GRPC_STATUS_OK;
- if (op->optional_close_message != NULL) {
- gpr_slice_unref(*op->optional_close_message);
- op->optional_close_message = NULL;
+void
+grpc_transport_stream_op_add_cancellation (grpc_transport_stream_op * op, grpc_status_code status)
+{
+ GPR_ASSERT (status != GRPC_STATUS_OK);
+ if (op->cancel_with_status == GRPC_STATUS_OK)
+ {
+ op->cancel_with_status = status;
+ }
+ if (op->close_with_status != GRPC_STATUS_OK)
+ {
+ op->close_with_status = GRPC_STATUS_OK;
+ if (op->optional_close_message != NULL)
+ {
+ gpr_slice_unref (*op->optional_close_message);
+ op->optional_close_message = NULL;
+ }
}
- }
}
-typedef struct {
+typedef struct
+{
gpr_slice message;
grpc_closure *then_call;
grpc_closure closure;
} close_message_data;
-static void free_message(void *p, int iomgr_success,
- grpc_closure_list *closure_list) {
+static void
+free_message (void *p, int iomgr_success, grpc_closure_list * closure_list)
+{
close_message_data *cmd = p;
- gpr_slice_unref(cmd->message);
- if (cmd->then_call != NULL) {
- cmd->then_call->cb(cmd->then_call->cb_arg, iomgr_success, closure_list);
- }
- gpr_free(cmd);
+ gpr_slice_unref (cmd->message);
+ if (cmd->then_call != NULL)
+ {
+ cmd->then_call->cb (cmd->then_call->cb_arg, iomgr_success, closure_list);
+ }
+ gpr_free (cmd);
}
-void grpc_transport_stream_op_add_close(grpc_transport_stream_op *op,
- grpc_status_code status,
- gpr_slice *optional_message) {
+void
+grpc_transport_stream_op_add_close (grpc_transport_stream_op * op, grpc_status_code status, gpr_slice * optional_message)
+{
close_message_data *cmd;
- GPR_ASSERT(status != GRPC_STATUS_OK);
- if (op->cancel_with_status != GRPC_STATUS_OK ||
- op->close_with_status != GRPC_STATUS_OK) {
- if (optional_message) {
- gpr_slice_unref(*optional_message);
+ GPR_ASSERT (status != GRPC_STATUS_OK);
+ if (op->cancel_with_status != GRPC_STATUS_OK || op->close_with_status != GRPC_STATUS_OK)
+ {
+ if (optional_message)
+ {
+ gpr_slice_unref (*optional_message);
+ }
+ return;
+ }
+ if (optional_message)
+ {
+ cmd = gpr_malloc (sizeof (*cmd));
+ cmd->message = *optional_message;
+ cmd->then_call = op->on_consumed;
+ grpc_closure_init (&cmd->closure, free_message, cmd);
+ op->on_consumed = &cmd->closure;
+ op->optional_close_message = &cmd->message;
}
- return;
- }
- if (optional_message) {
- cmd = gpr_malloc(sizeof(*cmd));
- cmd->message = *optional_message;
- cmd->then_call = op->on_consumed;
- grpc_closure_init(&cmd->closure, free_message, cmd);
- op->on_consumed = &cmd->closure;
- op->optional_close_message = &cmd->message;
- }
op->close_with_status = status;
}
diff --git a/src/core/transport/transport.h b/src/core/transport/transport.h
index 1d6dd1e735..c28dc0c2a6 100644
--- a/src/core/transport/transport.h
+++ b/src/core/transport/transport.h
@@ -50,7 +50,8 @@ typedef struct grpc_transport grpc_transport;
typedef struct grpc_stream grpc_stream;
/* Represents the send/recv closed state of a stream. */
-typedef enum grpc_stream_state {
+typedef enum grpc_stream_state
+{
/* the stream is open for sends and receives */
GRPC_STREAM_OPEN,
/* the stream is closed for sends, but may still receive data */
@@ -63,7 +64,8 @@ typedef enum grpc_stream_state {
/* Transport stream op: a set of operations to perform on a transport
against a single stream */
-typedef struct grpc_transport_stream_op {
+typedef struct grpc_transport_stream_op
+{
grpc_closure *on_consumed;
grpc_stream_op_buffer *send_ops;
@@ -93,7 +95,8 @@ typedef struct grpc_transport_stream_op {
} grpc_transport_stream_op;
/** Transport op: a set of operations to perform on a transport as a whole */
-typedef struct grpc_transport_op {
+typedef struct grpc_transport_op
+{
/** called when processing of this op is done */
grpc_closure *on_consumed;
/** connectivity monitoring */
@@ -110,8 +113,7 @@ typedef struct grpc_transport_op {
gpr_slice *goaway_message;
/** set the callback for accepting new streams;
this is a permanent callback, unlike the other one-shot closures */
- void (*set_accept_stream)(void *user_data, grpc_transport *transport,
- const void *server_data);
+ void (*set_accept_stream) (void *user_data, grpc_transport * transport, const void *server_data);
void *set_accept_stream_user_data;
/** add this transport to a pollset */
grpc_pollset *bind_pollset;
@@ -123,7 +125,7 @@ typedef struct grpc_transport_op {
/* Returns the amount of memory required to store a grpc_stream for this
transport */
-size_t grpc_transport_stream_size(grpc_transport *transport);
+size_t grpc_transport_stream_size (grpc_transport * transport);
/* Initialize transport data for a stream.
@@ -134,10 +136,7 @@ size_t grpc_transport_stream_size(grpc_transport *transport);
stream - a pointer to uninitialized memory to initialize
server_data - either NULL for a client initiated stream, or a pointer
supplied from the accept_stream callback function */
-int grpc_transport_init_stream(grpc_transport *transport, grpc_stream *stream,
- const void *server_data,
- grpc_transport_stream_op *initial_op,
- grpc_closure_list *closure_list);
+int grpc_transport_init_stream (grpc_transport * transport, grpc_stream * stream, const void *server_data, grpc_transport_stream_op * initial_op, grpc_closure_list * closure_list);
/* Destroy transport data for a stream.
@@ -149,21 +148,15 @@ int grpc_transport_init_stream(grpc_transport *transport, grpc_stream *stream,
transport - the transport on which to create this stream
stream - the grpc_stream to destroy (memory is still owned by the
caller, but any child memory must be cleaned up) */
-void grpc_transport_destroy_stream(grpc_transport *transport,
- grpc_stream *stream,
- grpc_closure_list *closure_list);
+void grpc_transport_destroy_stream (grpc_transport * transport, grpc_stream * stream, grpc_closure_list * closure_list);
-void grpc_transport_stream_op_finish_with_failure(
- grpc_transport_stream_op *op, grpc_closure_list *closure_list);
+void grpc_transport_stream_op_finish_with_failure (grpc_transport_stream_op * op, grpc_closure_list * closure_list);
-void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op,
- grpc_status_code status);
+void grpc_transport_stream_op_add_cancellation (grpc_transport_stream_op * op, grpc_status_code status);
-void grpc_transport_stream_op_add_close(grpc_transport_stream_op *op,
- grpc_status_code status,
- gpr_slice *optional_message);
+void grpc_transport_stream_op_add_close (grpc_transport_stream_op * op, grpc_status_code status, gpr_slice * optional_message);
-char *grpc_transport_stream_op_string(grpc_transport_stream_op *op);
+char *grpc_transport_stream_op_string (grpc_transport_stream_op * op);
/* Send a batch of operations on a transport
@@ -174,32 +167,25 @@ char *grpc_transport_stream_op_string(grpc_transport_stream_op *op);
stream - the stream on which to send the operations. This must be
non-NULL and previously initialized by the same transport.
op - a grpc_transport_stream_op specifying the op to perform */
-void grpc_transport_perform_stream_op(grpc_transport *transport,
- grpc_stream *stream,
- grpc_transport_stream_op *op,
- grpc_closure_list *closure_list);
+void grpc_transport_perform_stream_op (grpc_transport * transport, grpc_stream * stream, grpc_transport_stream_op * op, grpc_closure_list * closure_list);
-void grpc_transport_perform_op(grpc_transport *transport, grpc_transport_op *op,
- grpc_closure_list *closure_list);
+void grpc_transport_perform_op (grpc_transport * transport, grpc_transport_op * op, grpc_closure_list * closure_list);
/* Send a ping on a transport
Calls cb with user data when a response is received. */
-void grpc_transport_ping(grpc_transport *transport, grpc_closure *cb);
+void grpc_transport_ping (grpc_transport * transport, grpc_closure * cb);
/* Advise peer of pending connection termination. */
-void grpc_transport_goaway(grpc_transport *transport, grpc_status_code status,
- gpr_slice debug_data);
+void grpc_transport_goaway (grpc_transport * transport, grpc_status_code status, gpr_slice debug_data);
/* Close a transport. Aborts all open streams. */
-void grpc_transport_close(grpc_transport *transport);
+void grpc_transport_close (grpc_transport * transport);
/* Destroy the transport */
-void grpc_transport_destroy(grpc_transport *transport,
- grpc_closure_list *closure_list);
+void grpc_transport_destroy (grpc_transport * transport, grpc_closure_list * closure_list);
/* Get the transports peer */
-char *grpc_transport_get_peer(grpc_transport *transport,
- grpc_closure_list *closure_list);
+char *grpc_transport_get_peer (grpc_transport * transport, grpc_closure_list * closure_list);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_TRANSPORT_H */
diff --git a/src/core/transport/transport_impl.h b/src/core/transport/transport_impl.h
index c7eebc9bb2..97f4c4c8c7 100644
--- a/src/core/transport/transport_impl.h
+++ b/src/core/transport/transport_impl.h
@@ -36,39 +36,34 @@
#include "src/core/transport/transport.h"
-typedef struct grpc_transport_vtable {
+typedef struct grpc_transport_vtable
+{
/* Memory required for a single stream element - this is allocated by upper
layers and initialized by the transport */
- size_t sizeof_stream; /* = sizeof(transport stream) */
+ size_t sizeof_stream; /* = sizeof(transport stream) */
/* implementation of grpc_transport_init_stream */
- int (*init_stream)(grpc_transport *self, grpc_stream *stream,
- const void *server_data,
- grpc_transport_stream_op *initial_op,
- grpc_closure_list *closure_list);
+ int (*init_stream) (grpc_transport * self, grpc_stream * stream, const void *server_data, grpc_transport_stream_op * initial_op, grpc_closure_list * closure_list);
/* implementation of grpc_transport_perform_stream_op */
- void (*perform_stream_op)(grpc_transport *self, grpc_stream *stream,
- grpc_transport_stream_op *op,
- grpc_closure_list *closure_list);
+ void (*perform_stream_op) (grpc_transport * self, grpc_stream * stream, grpc_transport_stream_op * op, grpc_closure_list * closure_list);
/* implementation of grpc_transport_perform_op */
- void (*perform_op)(grpc_transport *self, grpc_transport_op *op,
- grpc_closure_list *closure_list);
+ void (*perform_op) (grpc_transport * self, grpc_transport_op * op, grpc_closure_list * closure_list);
/* implementation of grpc_transport_destroy_stream */
- void (*destroy_stream)(grpc_transport *self, grpc_stream *stream,
- grpc_closure_list *closure_list);
+ void (*destroy_stream) (grpc_transport * self, grpc_stream * stream, grpc_closure_list * closure_list);
/* implementation of grpc_transport_destroy */
- void (*destroy)(grpc_transport *self, grpc_closure_list *closure_list);
+ void (*destroy) (grpc_transport * self, grpc_closure_list * closure_list);
/* implementation of grpc_transport_get_peer */
- char *(*get_peer)(grpc_transport *self, grpc_closure_list *closure_list);
+ char *(*get_peer) (grpc_transport * self, grpc_closure_list * closure_list);
} grpc_transport_vtable;
/* an instance of a grpc transport */
-struct grpc_transport {
+struct grpc_transport
+{
/* pointer to a vtable defining operations on this transport */
const grpc_transport_vtable *vtable;
};
diff --git a/src/core/transport/transport_op_string.c b/src/core/transport/transport_op_string.c
index f62c340e97..f963413310 100644
--- a/src/core/transport/transport_op_string.c
+++ b/src/core/transport/transport_op_string.c
@@ -45,122 +45,142 @@
/* These routines are here to facilitate debugging - they produce string
representations of various transport data structures */
-static void put_metadata(gpr_strvec *b, grpc_mdelem *md) {
- gpr_strvec_add(b, gpr_strdup("key="));
- gpr_strvec_add(b,
- gpr_dump_slice(md->key->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII));
-
- gpr_strvec_add(b, gpr_strdup(" value="));
- gpr_strvec_add(
- b, gpr_dump_slice(md->value->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII));
+static void
+put_metadata (gpr_strvec * b, grpc_mdelem * md)
+{
+ gpr_strvec_add (b, gpr_strdup ("key="));
+ gpr_strvec_add (b, gpr_dump_slice (md->key->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII));
+
+ gpr_strvec_add (b, gpr_strdup (" value="));
+ gpr_strvec_add (b, gpr_dump_slice (md->value->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII));
}
-static void put_metadata_list(gpr_strvec *b, grpc_metadata_batch md) {
+static void
+put_metadata_list (gpr_strvec * b, grpc_metadata_batch md)
+{
grpc_linked_mdelem *m;
- for (m = md.list.head; m != NULL; m = m->next) {
- if (m != md.list.head) gpr_strvec_add(b, gpr_strdup(", "));
- put_metadata(b, m->md);
- }
- if (gpr_time_cmp(md.deadline, gpr_inf_future(md.deadline.clock_type)) != 0) {
- char *tmp;
- gpr_asprintf(&tmp, " deadline=%d.%09d", md.deadline.tv_sec,
- md.deadline.tv_nsec);
- gpr_strvec_add(b, tmp);
- }
+ for (m = md.list.head; m != NULL; m = m->next)
+ {
+ if (m != md.list.head)
+ gpr_strvec_add (b, gpr_strdup (", "));
+ put_metadata (b, m->md);
+ }
+ if (gpr_time_cmp (md.deadline, gpr_inf_future (md.deadline.clock_type)) != 0)
+ {
+ char *tmp;
+ gpr_asprintf (&tmp, " deadline=%d.%09d", md.deadline.tv_sec, md.deadline.tv_nsec);
+ gpr_strvec_add (b, tmp);
+ }
}
-char *grpc_sopb_string(grpc_stream_op_buffer *sopb) {
+char *
+grpc_sopb_string (grpc_stream_op_buffer * sopb)
+{
char *out;
char *tmp;
size_t i;
gpr_strvec b;
- gpr_strvec_init(&b);
-
- for (i = 0; i < sopb->nops; i++) {
- grpc_stream_op *op = &sopb->ops[i];
- if (i > 0) gpr_strvec_add(&b, gpr_strdup(", "));
- switch (op->type) {
- case GRPC_NO_OP:
- gpr_strvec_add(&b, gpr_strdup("NO_OP"));
- break;
- case GRPC_OP_BEGIN_MESSAGE:
- gpr_asprintf(&tmp, "BEGIN_MESSAGE:%d", op->data.begin_message.length);
- gpr_strvec_add(&b, tmp);
- break;
- case GRPC_OP_SLICE:
- gpr_asprintf(&tmp, "SLICE:%d", GPR_SLICE_LENGTH(op->data.slice));
- gpr_strvec_add(&b, tmp);
- break;
- case GRPC_OP_METADATA:
- gpr_strvec_add(&b, gpr_strdup("METADATA{"));
- put_metadata_list(&b, op->data.metadata);
- gpr_strvec_add(&b, gpr_strdup("}"));
- break;
+ gpr_strvec_init (&b);
+
+ for (i = 0; i < sopb->nops; i++)
+ {
+ grpc_stream_op *op = &sopb->ops[i];
+ if (i > 0)
+ gpr_strvec_add (&b, gpr_strdup (", "));
+ switch (op->type)
+ {
+ case GRPC_NO_OP:
+ gpr_strvec_add (&b, gpr_strdup ("NO_OP"));
+ break;
+ case GRPC_OP_BEGIN_MESSAGE:
+ gpr_asprintf (&tmp, "BEGIN_MESSAGE:%d", op->data.begin_message.length);
+ gpr_strvec_add (&b, tmp);
+ break;
+ case GRPC_OP_SLICE:
+ gpr_asprintf (&tmp, "SLICE:%d", GPR_SLICE_LENGTH (op->data.slice));
+ gpr_strvec_add (&b, tmp);
+ break;
+ case GRPC_OP_METADATA:
+ gpr_strvec_add (&b, gpr_strdup ("METADATA{"));
+ put_metadata_list (&b, op->data.metadata);
+ gpr_strvec_add (&b, gpr_strdup ("}"));
+ break;
+ }
}
- }
- out = gpr_strvec_flatten(&b, NULL);
- gpr_strvec_destroy(&b);
+ out = gpr_strvec_flatten (&b, NULL);
+ gpr_strvec_destroy (&b);
return out;
}
-char *grpc_transport_stream_op_string(grpc_transport_stream_op *op) {
+char *
+grpc_transport_stream_op_string (grpc_transport_stream_op * op)
+{
char *tmp;
char *out;
int first = 1;
gpr_strvec b;
- gpr_strvec_init(&b);
-
- if (op->send_ops) {
- if (!first) gpr_strvec_add(&b, gpr_strdup(" "));
- first = 0;
- gpr_asprintf(&tmp, "SEND%s:%p", op->is_last_send ? "_LAST" : "",
- op->on_done_send);
- gpr_strvec_add(&b, tmp);
- gpr_strvec_add(&b, gpr_strdup("["));
- gpr_strvec_add(&b, grpc_sopb_string(op->send_ops));
- gpr_strvec_add(&b, gpr_strdup("]"));
- }
-
- if (op->recv_ops) {
- if (!first) gpr_strvec_add(&b, gpr_strdup(" "));
- first = 0;
- gpr_asprintf(&tmp, "RECV:%p:max_recv_bytes=%d", op->on_done_recv,
- op->max_recv_bytes);
- gpr_strvec_add(&b, tmp);
- }
-
- if (op->bind_pollset) {
- if (!first) gpr_strvec_add(&b, gpr_strdup(" "));
- first = 0;
- gpr_strvec_add(&b, gpr_strdup("BIND"));
- }
-
- if (op->cancel_with_status != GRPC_STATUS_OK) {
- if (!first) gpr_strvec_add(&b, gpr_strdup(" "));
- first = 0;
- gpr_asprintf(&tmp, "CANCEL:%d", op->cancel_with_status);
- gpr_strvec_add(&b, tmp);
- }
-
- if (op->on_consumed != NULL) {
- if (!first) gpr_strvec_add(&b, gpr_strdup(" "));
- first = 0;
- gpr_asprintf(&tmp, "ON_CONSUMED:%p", op->on_consumed);
- gpr_strvec_add(&b, tmp);
- }
-
- out = gpr_strvec_flatten(&b, NULL);
- gpr_strvec_destroy(&b);
+ gpr_strvec_init (&b);
+
+ if (op->send_ops)
+ {
+ if (!first)
+ gpr_strvec_add (&b, gpr_strdup (" "));
+ first = 0;
+ gpr_asprintf (&tmp, "SEND%s:%p", op->is_last_send ? "_LAST" : "", op->on_done_send);
+ gpr_strvec_add (&b, tmp);
+ gpr_strvec_add (&b, gpr_strdup ("["));
+ gpr_strvec_add (&b, grpc_sopb_string (op->send_ops));
+ gpr_strvec_add (&b, gpr_strdup ("]"));
+ }
+
+ if (op->recv_ops)
+ {
+ if (!first)
+ gpr_strvec_add (&b, gpr_strdup (" "));
+ first = 0;
+ gpr_asprintf (&tmp, "RECV:%p:max_recv_bytes=%d", op->on_done_recv, op->max_recv_bytes);
+ gpr_strvec_add (&b, tmp);
+ }
+
+ if (op->bind_pollset)
+ {
+ if (!first)
+ gpr_strvec_add (&b, gpr_strdup (" "));
+ first = 0;
+ gpr_strvec_add (&b, gpr_strdup ("BIND"));
+ }
+
+ if (op->cancel_with_status != GRPC_STATUS_OK)
+ {
+ if (!first)
+ gpr_strvec_add (&b, gpr_strdup (" "));
+ first = 0;
+ gpr_asprintf (&tmp, "CANCEL:%d", op->cancel_with_status);
+ gpr_strvec_add (&b, tmp);
+ }
+
+ if (op->on_consumed != NULL)
+ {
+ if (!first)
+ gpr_strvec_add (&b, gpr_strdup (" "));
+ first = 0;
+ gpr_asprintf (&tmp, "ON_CONSUMED:%p", op->on_consumed);
+ gpr_strvec_add (&b, tmp);
+ }
+
+ out = gpr_strvec_flatten (&b, NULL);
+ gpr_strvec_destroy (&b);
return out;
}
-void grpc_call_log_op(char *file, int line, gpr_log_severity severity,
- grpc_call_element *elem, grpc_transport_stream_op *op) {
- char *str = grpc_transport_stream_op_string(op);
- gpr_log(file, line, severity, "OP[%s:%p]: %s", elem->filter->name, elem, str);
- gpr_free(str);
+void
+grpc_call_log_op (char *file, int line, gpr_log_severity severity, grpc_call_element * elem, grpc_transport_stream_op * op)
+{
+ char *str = grpc_transport_stream_op_string (op);
+ gpr_log (file, line, severity, "OP[%s:%p]: %s", elem->filter->name, elem, str);
+ gpr_free (str);
}