aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/transport/chttp2
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/transport/chttp2')
-rw-r--r--src/core/transport/chttp2/bin_encoder.c33
-rw-r--r--src/core/transport/chttp2/frame_data.c19
-rw-r--r--src/core/transport/chttp2/frame_goaway.c33
-rw-r--r--src/core/transport/chttp2/frame_rst_stream.c16
-rw-r--r--src/core/transport/chttp2/frame_settings.c28
-rw-r--r--src/core/transport/chttp2/frame_window_update.c16
-rw-r--r--src/core/transport/chttp2/hpack_parser.c25
-rw-r--r--src/core/transport/chttp2/hpack_parser.h2
-rw-r--r--src/core/transport/chttp2/hpack_table.c33
-rw-r--r--src/core/transport/chttp2/incoming_metadata.c2
-rw-r--r--src/core/transport/chttp2/internal.h44
-rw-r--r--src/core/transport/chttp2/parsing.c35
-rw-r--r--src/core/transport/chttp2/stream_encoder.c106
-rw-r--r--src/core/transport/chttp2/timeout_encoding.c8
-rw-r--r--src/core/transport/chttp2/varint.c5
-rw-r--r--src/core/transport/chttp2/varint.h11
-rw-r--r--src/core/transport/chttp2/writing.c46
17 files changed, 255 insertions, 207 deletions
diff --git a/src/core/transport/chttp2/bin_encoder.c b/src/core/transport/chttp2/bin_encoder.c
index dee6dbec8b..e21d800083 100644
--- a/src/core/transport/chttp2/bin_encoder.c
+++ b/src/core/transport/chttp2/bin_encoder.c
@@ -68,7 +68,7 @@ gpr_slice grpc_chttp2_base64_encode(gpr_slice input) {
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);
- gpr_uint8 *out = GPR_SLICE_START_PTR(output);
+ char *out = (char *)GPR_SLICE_START_PTR(output);
size_t i;
/* encode full triplets */
@@ -100,7 +100,7 @@ gpr_slice grpc_chttp2_base64_encode(gpr_slice input) {
break;
}
- GPR_ASSERT(out == GPR_SLICE_END_PTR(output));
+ GPR_ASSERT(out == (char *)GPR_SLICE_END_PTR(output));
GPR_ASSERT(in == GPR_SLICE_END_PTR(input));
return output;
}
@@ -128,12 +128,13 @@ gpr_slice grpc_chttp2_huffman_compress(gpr_slice input) {
while (temp_length > 8) {
temp_length -= 8;
- *out++ = temp >> temp_length;
+ *out++ = (gpr_uint8)(temp >> temp_length);
}
}
if (temp_length) {
- *out++ = (temp << (8 - temp_length)) | (0xff >> temp_length);
+ *out++ = (gpr_uint8)(temp << (8u - temp_length)) |
+ (gpr_uint8)(0xffu >> temp_length);
}
GPR_ASSERT(out == GPR_SLICE_END_PTR(output));
@@ -150,16 +151,16 @@ typedef struct {
static void enc_flush_some(huff_out *out) {
while (out->temp_length > 8) {
out->temp_length -= 8;
- *out->out++ = out->temp >> out->temp_length;
+ *out->out++ = (gpr_uint8)(out->temp >> out->temp_length);
}
}
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)) | (sa.bits << sb.length) | sb.bits;
- out->temp_length += sa.length + sb.length;
+ 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);
}
@@ -189,8 +190,9 @@ gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) {
/* encode full triplets */
for (i = 0; i < input_triplets; i++) {
- enc_add2(&out, in[0] >> 2, ((in[0] & 0x3) << 4) | (in[1] >> 4));
- enc_add2(&out, ((in[1] & 0xf) << 2) | (in[2] >> 6), in[2] & 0x3f);
+ 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;
}
@@ -199,19 +201,20 @@ gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) {
case 0:
break;
case 1:
- enc_add2(&out, in[0] >> 2, (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, ((in[0] & 0x3) << 4) | (in[1] >> 4));
- enc_add1(&out, (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++ =
- (out.temp << (8 - out.temp_length)) | (0xff >> 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));
diff --git a/src/core/transport/chttp2/frame_data.c b/src/core/transport/chttp2/frame_data.c
index 474c3d5ee6..403358016d 100644
--- a/src/core/transport/chttp2/frame_data.c
+++ b/src/core/transport/chttp2/frame_data.c
@@ -146,20 +146,23 @@ grpc_chttp2_parse_error grpc_chttp2_data_parser_parse(
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, cur - beg, end - beg));
+ 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, cur - beg, cur + p->frame_size - beg));
+ 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, cur - beg, end - beg));
- p->frame_size -= (end - cur);
+ 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;
}
}
diff --git a/src/core/transport/chttp2/frame_goaway.c b/src/core/transport/chttp2/frame_goaway.c
index 1ccbba840c..09d4da234c 100644
--- a/src/core/transport/chttp2/frame_goaway.c
+++ b/src/core/transport/chttp2/frame_goaway.c
@@ -136,14 +136,15 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
++cur;
/* fallthrough */
case GRPC_CHTTP2_GOAWAY_DEBUG:
- memcpy(p->debug_data + p->debug_pos, cur, end - cur);
- p->debug_pos += 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 = p->error_code;
+ 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;
@@ -160,12 +161,14 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code,
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 = 4 + 4 + GPR_SLICE_LENGTH(debug_data);
+ 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);
/* frame header: length */
- *p++ = frame_length >> 16;
- *p++ = frame_length >> 8;
- *p++ = 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 */
@@ -176,15 +179,15 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code,
*p++ = 0;
*p++ = 0;
/* payload: last stream id */
- *p++ = last_stream_id >> 24;
- *p++ = last_stream_id >> 16;
- *p++ = last_stream_id >> 8;
- *p++ = 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++ = error_code >> 24;
- *p++ = error_code >> 16;
- *p++ = error_code >> 8;
- *p++ = 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);
diff --git a/src/core/transport/chttp2/frame_rst_stream.c b/src/core/transport/chttp2/frame_rst_stream.c
index a878d936c1..67da245239 100644
--- a/src/core/transport/chttp2/frame_rst_stream.c
+++ b/src/core/transport/chttp2/frame_rst_stream.c
@@ -47,14 +47,14 @@ gpr_slice grpc_chttp2_rst_stream_create(gpr_uint32 id, gpr_uint32 code) {
*p++ = 4;
*p++ = GRPC_CHTTP2_FRAME_RST_STREAM;
*p++ = 0;
- *p++ = id >> 24;
- *p++ = id >> 16;
- *p++ = id >> 8;
- *p++ = id;
- *p++ = code >> 24;
- *p++ = code >> 16;
- *p++ = code >> 8;
- *p++ = 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;
}
diff --git a/src/core/transport/chttp2/frame_settings.c b/src/core/transport/chttp2/frame_settings.c
index d42bc000ae..54d3694a5c 100644
--- a/src/core/transport/chttp2/frame_settings.c
+++ b/src/core/transport/chttp2/frame_settings.c
@@ -61,9 +61,9 @@ const grpc_chttp2_setting_parameters
static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length,
gpr_uint8 flags) {
- *out++ = length >> 16;
- *out++ = length >> 8;
- *out++ = length;
+ *out++ = (gpr_uint8)(length >> 16);
+ *out++ = (gpr_uint8)(length >> 8);
+ *out++ = (gpr_uint8)(length);
*out++ = GRPC_CHTTP2_FRAME_SETTINGS;
*out++ = flags;
*out++ = 0;
@@ -76,26 +76,26 @@ static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length,
gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new,
gpr_uint32 force_mask, size_t count) {
size_t i;
- size_t n = 0;
+ gpr_uint32 n = 0;
gpr_slice output;
gpr_uint8 *p;
for (i = 0; i < count; i++) {
- n += (new[i] != old[i] || (force_mask & (1 << i)) != 0);
+ 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 & (1 << i)) != 0) {
+ if (new[i] != old[i] || (force_mask & (1u << i)) != 0) {
GPR_ASSERT(i);
- *p++ = i >> 8;
- *p++ = i;
- *p++ = new[i] >> 24;
- *p++ = new[i] >> 16;
- *p++ = new[i] >> 8;
- *p++ = new[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];
}
}
@@ -162,7 +162,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
}
return GRPC_CHTTP2_PARSE_OK;
}
- parser->id = ((gpr_uint16)*cur) << 8;
+ parser->id = (gpr_uint16)(((gpr_uint16)*cur) << 8);
cur++;
/* fallthrough */
case GRPC_CHTTP2_SPS_ID1:
@@ -170,7 +170,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
parser->state = GRPC_CHTTP2_SPS_ID1;
return GRPC_CHTTP2_PARSE_OK;
}
- parser->id |= (*cur);
+ parser->id = (gpr_uint16)(parser->id | (*cur));
cur++;
/* fallthrough */
case GRPC_CHTTP2_SPS_VAL0:
diff --git a/src/core/transport/chttp2/frame_window_update.c b/src/core/transport/chttp2/frame_window_update.c
index d624298ad2..ea13969e8c 100644
--- a/src/core/transport/chttp2/frame_window_update.c
+++ b/src/core/transport/chttp2/frame_window_update.c
@@ -48,14 +48,14 @@ gpr_slice grpc_chttp2_window_update_create(gpr_uint32 id,
*p++ = 4;
*p++ = GRPC_CHTTP2_FRAME_WINDOW_UPDATE;
*p++ = 0;
- *p++ = id >> 24;
- *p++ = id >> 16;
- *p++ = id >> 8;
- *p++ = id;
- *p++ = window_update >> 24;
- *p++ = window_update >> 16;
- *p++ = window_update >> 8;
- *p++ = 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;
}
diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c
index f8bff42ed6..9c40e8a4e6 100644
--- a/src/core/transport/chttp2/hpack_parser.c
+++ b/src/core/transport/chttp2/hpack_parser.c
@@ -1085,11 +1085,13 @@ static int parse_string_prefix(grpc_chttp2_hpack_parser *p,
static void append_bytes(grpc_chttp2_hpack_parser_string *str,
const gpr_uint8 *data, size_t length) {
if (length + str->length > str->capacity) {
- str->capacity = str->length + length;
+ 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);
- str->length += 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,
@@ -1099,7 +1101,7 @@ static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
gpr_uint8 decoded[3];
switch ((binary_state)p->binary) {
case NOT_BINARY:
- append_bytes(str, cur, end - cur);
+ append_bytes(str, cur, (size_t)(end - cur));
return 1;
b64_byte0:
case B64_BYTE0:
@@ -1157,9 +1159,9 @@ static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
goto b64_byte3;
p->base64_buffer |= bits;
bits = p->base64_buffer;
- decoded[0] = bits >> 16;
- decoded[1] = bits >> 8;
- decoded[2] = bits;
+ 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;
}
@@ -1189,7 +1191,7 @@ static int finish_str(grpc_chttp2_hpack_parser *p) {
bits & 0xffff);
return 0;
}
- decoded[0] = bits >> 16;
+ decoded[0] = (gpr_uint8)(bits >> 16);
append_bytes(str, decoded, 1);
break;
case B64_BYTE3:
@@ -1199,8 +1201,8 @@ static int finish_str(grpc_chttp2_hpack_parser *p) {
bits & 0xff);
return 0;
}
- decoded[0] = bits >> 16;
- decoded[1] = bits >> 8;
+ decoded[0] = (gpr_uint8)(bits >> 16);
+ decoded[1] = (gpr_uint8)(bits >> 8);
append_bytes(str, decoded, 2);
break;
}
@@ -1249,13 +1251,14 @@ static int add_str_bytes(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
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 = end - cur;
+ 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;
- p->strgot += given;
+ GPR_ASSERT(given <= GPR_UINT32_MAX - p->strgot);
+ p->strgot += (gpr_uint32)given;
p->state = parse_string;
return 1;
}
diff --git a/src/core/transport/chttp2/hpack_parser.h b/src/core/transport/chttp2/hpack_parser.h
index c1768d9d5d..4f489d67fb 100644
--- a/src/core/transport/chttp2/hpack_parser.h
+++ b/src/core/transport/chttp2/hpack_parser.h
@@ -79,7 +79,7 @@ struct grpc_chttp2_hpack_parser {
/* number of source bytes read for the currently parsing string */
gpr_uint32 strgot;
/* huffman decoding state */
- gpr_uint16 huff_state;
+ gpr_int16 huff_state;
/* is the string being decoded binary? */
gpr_uint8 binary;
/* is the current string huffman encoded? */
diff --git a/src/core/transport/chttp2/hpack_table.c b/src/core/transport/chttp2/hpack_table.c
index 4fc154380e..e18778ab0b 100644
--- a/src/core/transport/chttp2/hpack_table.c
+++ b/src/core/transport/chttp2/hpack_table.c
@@ -139,7 +139,7 @@ grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
/* 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 - 1 - index + tbl->first_ent) %
+ gpr_uint32 offset = (tbl->num_ents - 1u - index + tbl->first_ent) %
GRPC_CHTTP2_MAX_TABLE_COUNT;
return tbl->ents[offset];
}
@@ -150,19 +150,22 @@ grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
/* Evict one element from the table */
static void evict1(grpc_chttp2_hptbl *tbl) {
grpc_mdelem *first_ent = tbl->ents[tbl->first_ent];
- tbl->mem_used -= GPR_SLICE_LENGTH(first_ent->key->slice) +
- GPR_SLICE_LENGTH(first_ent->value->slice) +
- GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
- tbl->first_ent = (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);
}
void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
/* determine how many bytes of buffer this entry represents */
- gpr_uint16 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) {
@@ -182,7 +185,7 @@ void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
}
/* evict entries to ensure no overflow */
- while (elem_bytes > tbl->max_bytes - tbl->mem_used) {
+ while (elem_bytes > (size_t)tbl->max_bytes - tbl->mem_used) {
evict1(tbl);
}
@@ -190,28 +193,30 @@ void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
tbl->ents[tbl->last_ent] = md;
/* update accounting values */
- tbl->last_ent = (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 += 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};
- int i;
+ 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 = i + 1;
+ 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++) {
- int idx = tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY;
+ 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;
diff --git a/src/core/transport/chttp2/incoming_metadata.c b/src/core/transport/chttp2/incoming_metadata.c
index 974b864ffb..d216c42113 100644
--- a/src/core/transport/chttp2/incoming_metadata.c
+++ b/src/core/transport/chttp2/incoming_metadata.c
@@ -122,7 +122,7 @@ void grpc_incoming_metadata_buffer_move_to_referencing_sopb(
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_intptr)sopb->ops[i].data.metadata.list.tail);
+ (void *)(delta + (gpr_uintptr)sopb->ops[i].data.metadata.list.tail);
}
src->count = 0;
}
diff --git a/src/core/transport/chttp2/internal.h b/src/core/transport/chttp2/internal.h
index 42cf0ecd5b..c8c1abb750 100644
--- a/src/core/transport/chttp2/internal.h
+++ b/src/core/transport/chttp2/internal.h
@@ -168,7 +168,7 @@ typedef struct {
grpc_iomgr_closure *pending_closures_tail;
/** window available for us to send to peer */
- gpr_uint32 outgoing_window;
+ gpr_int64 outgoing_window;
/** window available for peer to send to us - updated after parse */
gpr_uint32 incoming_window;
/** how much window would we like to have for incoming_window */
@@ -214,6 +214,8 @@ typedef struct {
grpc_chttp2_hpack_compressor hpack_compressor;
/** is this a client? */
gpr_uint8 is_client;
+ /** callback for when writing is done */
+ grpc_iomgr_closure done_cb;
} grpc_chttp2_transport_writing;
struct grpc_chttp2_transport_parsing {
@@ -278,7 +280,7 @@ struct grpc_chttp2_transport_parsing {
gpr_uint32 goaway_last_stream_index;
gpr_slice goaway_text;
- gpr_uint64 outgoing_window_update;
+ gpr_int64 outgoing_window_update;
/** pings awaiting responses */
grpc_chttp2_outstanding_ping pings;
@@ -291,6 +293,9 @@ struct grpc_chttp2_transport {
gpr_refcount refs;
char *peer_string;
+ /** when this drops to zero it's safe to shutdown the endpoint */
+ gpr_refcount shutdown_ep_refs;
+
gpr_mu mu;
/** is the transport destroying itself? */
@@ -329,8 +334,11 @@ struct grpc_chttp2_transport {
/** closure to execute writing */
grpc_iomgr_closure writing_action;
- /** closure to start reading from the endpoint */
- grpc_iomgr_closure reading_action;
+ /** closure to finish reading from the endpoint */
+ grpc_iomgr_closure recv_data;
+
+ /** incoming read bytes */
+ gpr_slice_buffer read_buffer;
/** address to place a newly accepted stream - set and unset by
grpc_chttp2_parsing_accept_stream; used by init_stream to
@@ -463,8 +471,7 @@ 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);
-void grpc_chttp2_terminate_writing(
- grpc_chttp2_transport_writing *transport_writing, int success);
+void grpc_chttp2_terminate_writing(void *transport_writing, int success);
void grpc_chttp2_cleanup_writing(grpc_chttp2_transport_global *global,
grpc_chttp2_transport_writing *writing);
@@ -602,20 +609,21 @@ extern int grpc_flowctl_trace;
else \
stmt
-#define GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(reason, transport, context, var, \
- delta) \
- if (!(grpc_flowctl_trace)) { \
- } else { \
- grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \
- transport->is_client, context->id, context->var, \
- delta); \
+#define GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(reason, transport, context, var, \
+ delta) \
+ if (!(grpc_flowctl_trace)) { \
+ } else { \
+ grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \
+ transport->is_client, context->id, \
+ (gpr_int64)(context->var), (gpr_int64)(delta)); \
}
-#define GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(reason, context, var, delta) \
- if (!(grpc_flowctl_trace)) { \
- } else { \
- grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \
- context->is_client, 0, context->var, delta); \
+#define GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(reason, context, var, delta) \
+ if (!(grpc_flowctl_trace)) { \
+ } else { \
+ grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \
+ context->is_client, 0, \
+ (gpr_int64)(context->var), (gpr_int64)(delta)); \
}
void grpc_chttp2_flowctl_trace(const char *file, int line, const char *reason,
diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c
index dc5eb18e42..a592ce7d28 100644
--- a/src/core/transport/chttp2/parsing.c
+++ b/src/core/transport/chttp2/parsing.c
@@ -131,7 +131,7 @@ void grpc_chttp2_publish_reads(
published later */
if (transport_parsing->goaway_received) {
grpc_chttp2_add_incoming_goaway(transport_global,
- transport_parsing->goaway_error,
+ (gpr_uint32)transport_parsing->goaway_error,
transport_parsing->goaway_text);
transport_parsing->goaway_text = gpr_empty_slice();
transport_parsing->goaway_received = 0;
@@ -194,7 +194,9 @@ void grpc_chttp2_publish_reads(
GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
"parsed", transport_parsing, stream_parsing, outgoing_window_update,
-(gpr_int64)stream_parsing->outgoing_window_update);
- stream_global->outgoing_window += 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) {
@@ -211,7 +213,7 @@ void grpc_chttp2_publish_reads(
if (stream_parsing->saw_rst_stream) {
stream_global->cancelled = 1;
stream_global->cancelled_status = grpc_chttp2_http2_error_to_grpc_status(
- stream_parsing->rst_stream_reason);
+ (grpc_chttp2_error_code)stream_parsing->rst_stream_reason);
if (stream_parsing->rst_stream_reason == GRPC_CHTTP2_NO_ERROR) {
stream_global->published_cancelled = 1;
}
@@ -379,9 +381,10 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing,
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, cur - beg, end - beg), 1)) {
+ if (!parse_frame_slice(transport_parsing,
+ gpr_slice_sub_no_ref(slice, (size_t)(cur - beg),
+ (size_t)(end - beg)),
+ 1)) {
return 0;
}
transport_parsing->deframe_state = GRPC_DTS_FH_0;
@@ -389,11 +392,12 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing,
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 - beg,
- cur + transport_parsing->incoming_frame_size - beg),
+ slice, cur_offset,
+ cur_offset + transport_parsing->incoming_frame_size),
1)) {
return 0;
}
@@ -401,12 +405,13 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing,
transport_parsing->incoming_stream = NULL;
goto dts_fh_0; /* loop */
} else {
- if (!parse_frame_slice(
- transport_parsing,
- gpr_slice_sub_no_ref(slice, cur - beg, end - beg), 0)) {
+ if (!parse_frame_slice(transport_parsing,
+ gpr_slice_sub_no_ref(slice, (size_t)(cur - beg),
+ (size_t)(end - beg)),
+ 0)) {
return 0;
}
- transport_parsing->incoming_frame_size -= (end - cur);
+ transport_parsing->incoming_frame_size -= (gpr_uint32)(end - cur);
return 1;
}
gpr_log(GPR_ERROR, "should never reach here");
@@ -474,7 +479,7 @@ 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) {
- int is_eoh = transport_parsing->expect_continuation_stream_id != 0;
+ 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;
@@ -617,8 +622,8 @@ static void on_header(void *tp, grpc_mdelem *md) {
static int init_header_frame_parser(
grpc_chttp2_transport_parsing *transport_parsing, int is_continuation) {
- int is_eoh = (transport_parsing->incoming_frame_flags &
- GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0;
+ 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;
diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c
index 1ea697f71e..6a22532bc2 100644
--- a/src/core/transport/chttp2/stream_encoder.c
+++ b/src/core/transport/chttp2/stream_encoder.c
@@ -74,17 +74,18 @@ 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,
- gpr_uint32 len, gpr_uint8 flags) {
- *p++ = len >> 16;
- *p++ = len >> 8;
- *p++ = 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++ = id >> 24;
- *p++ = id >> 16;
- *p++ = id >> 8;
- *p++ = 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 */
@@ -105,11 +106,12 @@ static void finish_frame(framer_state *st, int is_header_boundary,
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,
- (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;
}
@@ -134,7 +136,7 @@ static void begin_new_frame(framer_state *st, frame_type type) {
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,
- int need_bytes) {
+ 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) {
@@ -174,7 +176,7 @@ static void add_header_data(framer_state *st, gpr_slice slice) {
}
}
-static gpr_uint8 *add_tiny_header_data(framer_state *st, int 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);
}
@@ -185,10 +187,12 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c,
gpr_uint32 key_hash = elem->key->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;
- gpr_uint32 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);
+
/* Reserve space for this element in the remote table: if this overflows
the current table, drop elements until it fits, matching the decompressor
algorithm */
@@ -200,14 +204,16 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c,
c->table_elem_size[c->tail_remote_index %
GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]);
GPR_ASSERT(c->table_elems > 0);
- c->table_size -= c->table_elem_size[c->tail_remote_index %
- GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS];
+ 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] =
- elem_size;
- c->table_size += elem_size;
+ (gpr_uint16)elem_size;
+ c->table_size = (gpr_uint16)(c->table_size + elem_size);
c->table_elems++;
/* Store this element into {entries,indices}_elem */
@@ -270,7 +276,7 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c,
static void emit_indexed(grpc_chttp2_hpack_compressor *c, gpr_uint32 index,
framer_state *st) {
- int len = GRPC_CHTTP2_VARINT_LENGTH(index, 1);
+ gpr_uint32 len = GRPC_CHTTP2_VARINT_LENGTH(index, 1);
GRPC_CHTTP2_WRITE_VARINT(index, 1, 0x80, add_tiny_header_data(st, len), len);
}
@@ -288,14 +294,16 @@ static gpr_slice get_wire_value(grpc_mdelem *elem, gpr_uint8 *huffman_prefix) {
static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c,
gpr_uint32 key_index, grpc_mdelem *elem,
framer_state *st) {
- int len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2);
+ 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);
- int len_val = GPR_SLICE_LENGTH(value_slice);
- int len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
+ 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(len_val, 1, 0x00,
+ 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));
}
@@ -303,26 +311,30 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c,
static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c,
gpr_uint32 key_index, grpc_mdelem *elem,
framer_state *st) {
- int len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4);
+ 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);
- int len_val = GPR_SLICE_LENGTH(value_slice);
- int len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
+ 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(len_val, 1, 0x00,
+ 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) {
- int len_key = GPR_SLICE_LENGTH(elem->key->slice);
+ 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);
- int len_val = GPR_SLICE_LENGTH(value_slice);
- int len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1);
- int len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
+ 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);
@@ -334,12 +346,14 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c,
static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c,
grpc_mdelem *elem, framer_state *st) {
- int len_key = GPR_SLICE_LENGTH(elem->key->slice);
+ 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);
- int len_val = GPR_SLICE_LENGTH(value_slice);
- int len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1);
- int len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
+ 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);
@@ -488,7 +502,7 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count,
gpr_uint32 flow_controlled_bytes_taken = 0;
gpr_uint32 curop = 0;
gpr_uint8 *p;
- int compressed_flag_set = 0;
+ gpr_uint8 compressed_flag_set = 0;
while (curop < *inops_count) {
GPR_ASSERT(flow_controlled_bytes_taken <= max_flow_controlled_bytes);
@@ -514,10 +528,10 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count,
p = GPR_SLICE_START_PTR(slice);
p[0] = compressed_flag_set;
- p[1] = op->data.begin_message.length >> 24;
- p[2] = op->data.begin_message.length >> 16;
- p[3] = op->data.begin_message.length >> 8;
- p[4] = op->data.begin_message.length;
+ 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 */
@@ -541,7 +555,7 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count,
grpc_sopb_append(outops, op, 1);
curop++;
}
- flow_controlled_bytes_taken += GPR_SLICE_LENGTH(slice);
+ flow_controlled_bytes_taken += (gpr_uint32)GPR_SLICE_LENGTH(slice);
break;
}
}
@@ -565,7 +579,7 @@ void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof,
framer_state st;
gpr_slice slice;
grpc_stream_op *op;
- gpr_uint32 max_take_size;
+ size_t max_take_size;
gpr_uint32 curop = 0;
gpr_uint32 unref_op;
grpc_mdctx *mdctx = compressor->mdctx;
diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c
index 1dd768ada4..8a9b290ecb 100644
--- a/src/core/transport/chttp2/timeout_encoding.c
+++ b/src/core/transport/chttp2/timeout_encoding.c
@@ -123,7 +123,7 @@ void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer) {
enc_nanos(buffer, timeout.tv_nsec);
} else if (timeout.tv_sec < 1000 && timeout.tv_nsec != 0) {
enc_micros(buffer,
- timeout.tv_sec * 1000000 +
+ (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));
@@ -137,14 +137,14 @@ static int is_all_whitespace(const char *p) {
int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout) {
gpr_uint32 x = 0;
- const char *p = 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 * 10 + *p - '0';
+ gpr_uint32 xp = x * 10u + (gpr_uint32)*p - (gpr_uint32)'0';
have_digit = 1;
if (xp < x) {
*timeout = gpr_inf_future(GPR_CLOCK_REALTIME);
@@ -180,5 +180,5 @@ int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout) {
return 0;
}
p++;
- return is_all_whitespace(p);
+ return is_all_whitespace((const char *)p);
}
diff --git a/src/core/transport/chttp2/varint.c b/src/core/transport/chttp2/varint.c
index 0722c9ada9..056f68047b 100644
--- a/src/core/transport/chttp2/varint.c
+++ b/src/core/transport/chttp2/varint.c
@@ -33,7 +33,7 @@
#include "src/core/transport/chttp2/varint.h"
-int grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value) {
+gpr_uint32 grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value) {
if (tail_value < (1 << 7)) {
return 2;
} else if (tail_value < (1 << 14)) {
@@ -48,7 +48,8 @@ int grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value) {
}
void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value,
- gpr_uint8* target, int tail_length) {
+ gpr_uint8* target,
+ gpr_uint32 tail_length) {
switch (tail_length) {
case 5:
target[4] = (gpr_uint8)((tail_value >> 28) | 0x80);
diff --git a/src/core/transport/chttp2/varint.h b/src/core/transport/chttp2/varint.h
index 0a6fb55248..4dfcc76773 100644
--- a/src/core/transport/chttp2/varint.h
+++ b/src/core/transport/chttp2/varint.h
@@ -41,10 +41,11 @@
/* 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 */
-int 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, int tail_length);
+ gpr_uint8* target,
+ gpr_uint32 tail_length);
/* maximum value that can be bitpacked with the opcode if the opcode has a
prefix
@@ -54,15 +55,15 @@ void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value,
/* length required to bitpack a value */
#define GRPC_CHTTP2_VARINT_LENGTH(n, prefix_bits) \
((n) < GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits) \
- ? 1 \
+ ? 1u \
: grpc_chttp2_hpack_varint_length( \
(n)-GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits)))
#define GRPC_CHTTP2_WRITE_VARINT(n, prefix_bits, prefix_or, target, length) \
do { \
gpr_uint8* tgt = target; \
- if ((length) == 1) { \
- (tgt)[0] = (prefix_or) | (n); \
+ if ((length) == 1u) { \
+ (tgt)[0] = (gpr_uint8)((prefix_or) | (n)); \
} else { \
(tgt)[0] = (prefix_or) | GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits); \
grpc_chttp2_hpack_write_varint_tail( \
diff --git a/src/core/transport/chttp2/writing.c b/src/core/transport/chttp2/writing.c
index 123061b3fc..c015e82931 100644
--- a/src/core/transport/chttp2/writing.c
+++ b/src/core/transport/chttp2/writing.c
@@ -32,12 +32,14 @@
*/
#include "src/core/transport/chttp2/internal.h"
-#include "src/core/transport/chttp2/http2_errors.h"
+
+#include <limits.h>
#include <grpc/support/log.h>
+#include "src/core/transport/chttp2/http2_errors.h"
+
static void finalize_outbuf(grpc_chttp2_transport_writing *transport_writing);
-static void finish_write_cb(void *tw, grpc_endpoint_cb_status write_status);
int grpc_chttp2_unlocking_check_writes(
grpc_chttp2_transport_global *transport_global,
@@ -79,12 +81,13 @@ int grpc_chttp2_unlocking_check_writes(
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_MIN(transport_global->outgoing_window,
- stream_global->outgoing_window),
- &stream_writing->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,
@@ -114,6 +117,10 @@ int grpc_chttp2_unlocking_check_writes(
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(
@@ -165,16 +172,15 @@ void grpc_chttp2_perform_writes(
GPR_ASSERT(transport_writing->outbuf.count > 0);
GPR_ASSERT(endpoint);
- switch (grpc_endpoint_write(endpoint, transport_writing->outbuf.slices,
- transport_writing->outbuf.count, finish_write_cb,
- transport_writing)) {
- case GRPC_ENDPOINT_WRITE_DONE:
+ switch (grpc_endpoint_write(endpoint, &transport_writing->outbuf,
+ &transport_writing->done_cb)) {
+ case GRPC_ENDPOINT_DONE:
grpc_chttp2_terminate_writing(transport_writing, 1);
break;
- case GRPC_ENDPOINT_WRITE_ERROR:
+ case GRPC_ENDPOINT_ERROR:
grpc_chttp2_terminate_writing(transport_writing, 0);
break;
- case GRPC_ENDPOINT_WRITE_PENDING:
+ case GRPC_ENDPOINT_PENDING:
break;
}
}
@@ -198,6 +204,9 @@ static void finalize_outbuf(grpc_chttp2_transport_writing *transport_writing) {
&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) {
@@ -209,12 +218,6 @@ static void finalize_outbuf(grpc_chttp2_transport_writing *transport_writing) {
}
}
-static void finish_write_cb(void *tw, grpc_endpoint_cb_status write_status) {
- grpc_chttp2_transport_writing *transport_writing = tw;
- grpc_chttp2_terminate_writing(transport_writing,
- write_status == GRPC_ENDPOINT_CB_OK);
-}
-
void grpc_chttp2_cleanup_writing(
grpc_chttp2_transport_global *transport_global,
grpc_chttp2_transport_writing *transport_writing) {
@@ -243,6 +246,5 @@ void grpc_chttp2_cleanup_writing(
grpc_chttp2_list_add_read_write_state_changed(transport_global,
stream_global);
}
- transport_writing->outbuf.count = 0;
- transport_writing->outbuf.length = 0;
+ gpr_slice_buffer_reset_and_unref(&transport_writing->outbuf);
}