clang-format

pull/4097/head
Craig Tiller 10 years ago
parent 856d0948da
commit 3c53bb2f46
  1. 3
      src/core/iomgr/pollset_windows.c
  2. 1
      src/core/surface/byte_buffer_reader.c
  3. 34
      src/core/transport/chttp2/hpack_encoder.c
  4. 6
      src/core/transport/chttp2/hpack_encoder.h
  5. 12
      src/core/transport/chttp2/hpack_parser.c
  6. 40
      src/core/transport/chttp2/hpack_table.c
  7. 9
      src/core/transport/chttp2/hpack_table.h
  8. 8
      src/core/transport/chttp2/parsing.c
  9. 11
      src/core/transport/chttp2/writing.c
  10. 31
      src/core/transport/chttp2_transport.c
  11. 18
      test/core/client_config/lb_policies_test.c
  12. 3
      test/core/end2end/tests/cancel_with_status.c
  13. 41
      test/core/end2end/tests/hpack_size.c
  14. 3
      test/core/end2end/tests/negative_deadline.c
  15. 4
      test/core/network_benchmarks/low_level_ping_pong.c
  16. 16
      test/core/transport/chttp2/hpack_table_test.c

@ -126,7 +126,8 @@ void grpc_pollset_destroy(grpc_pollset *pollset) {}
void grpc_pollset_reset(grpc_pollset *pollset) { void grpc_pollset_reset(grpc_pollset *pollset) {
GPR_ASSERT(pollset->shutting_down); GPR_ASSERT(pollset->shutting_down);
GPR_ASSERT(!has_workers(&pollset->root_worker, GRPC_POLLSET_WORKER_LINK_POLLSET)); GPR_ASSERT(
!has_workers(&pollset->root_worker, GRPC_POLLSET_WORKER_LINK_POLLSET));
pollset->shutting_down = 0; pollset->shutting_down = 0;
pollset->is_iocp_worker = 0; pollset->is_iocp_worker = 0;
pollset->kicked_without_pollers = 0; pollset->kicked_without_pollers = 0;

@ -121,4 +121,3 @@ gpr_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader *reader) {
} }
return out_slice; return out_slice;
} }

@ -160,13 +160,11 @@ static void evict_entry(grpc_chttp2_hpack_compressor *c) {
c->tail_remote_index++; c->tail_remote_index++;
GPR_ASSERT(c->tail_remote_index > 0); GPR_ASSERT(c->tail_remote_index > 0);
GPR_ASSERT(c->table_size >= GPR_ASSERT(c->table_size >=
c->table_elem_size[c->tail_remote_index % c->table_elem_size[c->tail_remote_index % c->cap_table_elems]);
c->cap_table_elems]);
GPR_ASSERT(c->table_elems > 0); GPR_ASSERT(c->table_elems > 0);
c->table_size = c->table_size = (gpr_uint16)(
(gpr_uint16)(c->table_size - c->table_size -
c->table_elem_size[c->tail_remote_index % c->table_elem_size[c->tail_remote_index % c->cap_table_elems]);
c->cap_table_elems]);
c->table_elems--; c->table_elems--;
} }
@ -194,8 +192,7 @@ static void add_elem(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem) {
evict_entry(c); evict_entry(c);
} }
GPR_ASSERT(c->table_elems < c->max_table_size); GPR_ASSERT(c->table_elems < c->max_table_size);
c->table_elem_size[new_index % c->cap_table_elems] = c->table_elem_size[new_index % c->cap_table_elems] = (gpr_uint16)elem_size;
(gpr_uint16)elem_size;
c->table_size = (gpr_uint16)(c->table_size + elem_size); c->table_size = (gpr_uint16)(c->table_size + elem_size);
c->table_elems++; c->table_elems++;
@ -341,9 +338,11 @@ static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c,
add_header_data(st, gpr_slice_ref(value_slice)); add_header_data(st, gpr_slice_ref(value_slice));
} }
static void emit_advertise_table_size_change(grpc_chttp2_hpack_compressor *c, framer_state *st) { static void emit_advertise_table_size_change(grpc_chttp2_hpack_compressor *c,
framer_state *st) {
gpr_uint32 len = GRPC_CHTTP2_VARINT_LENGTH(c->max_table_size, 3); gpr_uint32 len = GRPC_CHTTP2_VARINT_LENGTH(c->max_table_size, 3);
GRPC_CHTTP2_WRITE_VARINT(c->max_table_size, 3, 0x20, add_tiny_header_data(st, len), len); GRPC_CHTTP2_WRITE_VARINT(c->max_table_size, 3, 0x20,
add_tiny_header_data(st, len), len);
c->advertise_table_size_change = 0; c->advertise_table_size_change = 0;
} }
@ -477,8 +476,10 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c,
c->max_table_size = GRPC_CHTTP2_HPACKC_INITIAL_TABLE_SIZE; c->max_table_size = GRPC_CHTTP2_HPACKC_INITIAL_TABLE_SIZE;
c->cap_table_elems = c->max_table_elems = elems_for_bytes(c->max_table_size); c->cap_table_elems = c->max_table_elems = elems_for_bytes(c->max_table_size);
c->max_usable_size = GRPC_CHTTP2_HPACKC_INITIAL_TABLE_SIZE; c->max_usable_size = GRPC_CHTTP2_HPACKC_INITIAL_TABLE_SIZE;
c->table_elem_size = gpr_malloc(sizeof(*c->table_elem_size) * c->cap_table_elems); c->table_elem_size =
memset(c->table_elem_size, 0, sizeof(*c->table_elem_size) * c->cap_table_elems); gpr_malloc(sizeof(*c->table_elem_size) * c->cap_table_elems);
memset(c->table_elem_size, 0,
sizeof(*c->table_elem_size) * c->cap_table_elems);
} }
void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c) { void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c) {
@ -491,16 +492,19 @@ void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c) {
gpr_free(c->table_elem_size); gpr_free(c->table_elem_size);
} }
void grpc_chttp2_hpack_compressor_set_max_usable_size(grpc_chttp2_hpack_compressor *c, gpr_uint32 max_table_size) { void grpc_chttp2_hpack_compressor_set_max_usable_size(
grpc_chttp2_hpack_compressor *c, gpr_uint32 max_table_size) {
c->max_usable_size = max_table_size; c->max_usable_size = max_table_size;
grpc_chttp2_hpack_compressor_set_max_table_size(c, GPR_MIN(c->max_table_size, max_table_size)); grpc_chttp2_hpack_compressor_set_max_table_size(
c, GPR_MIN(c->max_table_size, max_table_size));
} }
static void rebuild_elems(grpc_chttp2_hpack_compressor *c, gpr_uint32 new_cap) { static void rebuild_elems(grpc_chttp2_hpack_compressor *c, gpr_uint32 new_cap) {
} }
void grpc_chttp2_hpack_compressor_set_max_table_size(grpc_chttp2_hpack_compressor *c, gpr_uint32 max_table_size) { void grpc_chttp2_hpack_compressor_set_max_table_size(
grpc_chttp2_hpack_compressor *c, gpr_uint32 max_table_size) {
max_table_size = GPR_MIN(max_table_size, c->max_usable_size); max_table_size = GPR_MIN(max_table_size, c->max_usable_size);
if (max_table_size == c->max_table_size) { if (max_table_size == c->max_table_size) {
return; return;

@ -89,8 +89,10 @@ typedef struct {
void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c, void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c,
grpc_mdctx *mdctx); grpc_mdctx *mdctx);
void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c); void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c);
void grpc_chttp2_hpack_compressor_set_max_table_size(grpc_chttp2_hpack_compressor *c, gpr_uint32 max_table_size); void grpc_chttp2_hpack_compressor_set_max_table_size(
void grpc_chttp2_hpack_compressor_set_max_usable_size(grpc_chttp2_hpack_compressor *c, gpr_uint32 max_table_size); grpc_chttp2_hpack_compressor *c, gpr_uint32 max_table_size);
void grpc_chttp2_hpack_compressor_set_max_usable_size(
grpc_chttp2_hpack_compressor *c, gpr_uint32 max_table_size);
void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor *c, gpr_uint32 id, void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor *c, gpr_uint32 id,
grpc_metadata_batch *metadata, int is_eof, grpc_metadata_batch *metadata, int is_eof,

@ -752,7 +752,8 @@ static int finish_lithdr_incidx(grpc_chttp2_hpack_parser *p,
return on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx, return on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx,
GRPC_MDSTR_REF(md->key), GRPC_MDSTR_REF(md->key),
take_string(p, &p->value)), take_string(p, &p->value)),
1) && parse_begin(p, cur, end); 1) &&
parse_begin(p, cur, end);
} }
/* finish a literal header with incremental indexing with no index */ /* finish a literal header with incremental indexing with no index */
@ -814,7 +815,8 @@ static int finish_lithdr_notidx_v(grpc_chttp2_hpack_parser *p,
return on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx, return on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx,
take_string(p, &p->key), take_string(p, &p->key),
take_string(p, &p->value)), take_string(p, &p->value)),
0) && parse_begin(p, cur, end); 0) &&
parse_begin(p, cur, end);
} }
/* parse a literal header without incremental indexing; index < 15 */ /* parse a literal header without incremental indexing; index < 15 */
@ -906,7 +908,8 @@ static int parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser *p,
static int finish_max_tbl_size(grpc_chttp2_hpack_parser *p, static int finish_max_tbl_size(grpc_chttp2_hpack_parser *p,
const gpr_uint8 *cur, const gpr_uint8 *end) { const gpr_uint8 *cur, const gpr_uint8 *end) {
gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index); gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index);
return grpc_chttp2_hptbl_set_current_table_size(&p->table, p->index) && parse_begin(p, cur, end); return grpc_chttp2_hptbl_set_current_table_size(&p->table, p->index) &&
parse_begin(p, cur, end);
} }
/* parse a max table size change, max size < 15 */ /* parse a max table size change, max size < 15 */
@ -934,7 +937,8 @@ static int parse_error(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
return 0; return 0;
} }
static int parse_illegal_op(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, const gpr_uint8 *end) { static int parse_illegal_op(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
const gpr_uint8 *end) {
GPR_ASSERT(cur != end); GPR_ASSERT(cur != end);
gpr_log(GPR_DEBUG, "Illegal hpack op code %d", *cur); gpr_log(GPR_DEBUG, "Illegal hpack op code %d", *cur);
return parse_error(p, cur, end); return parse_error(p, cur, end);

@ -172,7 +172,8 @@ static struct {
}; };
static gpr_uint32 entries_for_bytes(gpr_uint32 bytes) { static gpr_uint32 entries_for_bytes(gpr_uint32 bytes) {
return (bytes + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD - 1) / GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; return (bytes + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD - 1) /
GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
} }
void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx) { void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx) {
@ -180,8 +181,10 @@ void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx) {
memset(tbl, 0, sizeof(*tbl)); memset(tbl, 0, sizeof(*tbl));
tbl->mdctx = mdctx; tbl->mdctx = mdctx;
tbl->current_table_bytes = tbl->max_bytes = GRPC_CHTTP2_INITIAL_HPACK_TABLE_SIZE; tbl->current_table_bytes = tbl->max_bytes =
tbl->max_entries = tbl->cap_entries = entries_for_bytes(tbl->current_table_bytes); GRPC_CHTTP2_INITIAL_HPACK_TABLE_SIZE;
tbl->max_entries = tbl->cap_entries =
entries_for_bytes(tbl->current_table_bytes);
tbl->ents = gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries); tbl->ents = gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries);
memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries); memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries);
for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) {
@ -196,8 +199,7 @@ void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl *tbl) {
GRPC_MDELEM_UNREF(tbl->static_ents[i]); GRPC_MDELEM_UNREF(tbl->static_ents[i]);
} }
for (i = 0; i < tbl->num_ents; i++) { for (i = 0; i < tbl->num_ents; i++) {
GRPC_MDELEM_UNREF( GRPC_MDELEM_UNREF(tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]);
tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]);
} }
gpr_free(tbl->ents); gpr_free(tbl->ents);
} }
@ -211,8 +213,8 @@ grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
/* Otherwise, find the value in the list of valid entries */ /* Otherwise, find the value in the list of valid entries */
tbl_index -= (GRPC_CHTTP2_LAST_STATIC_ENTRY + 1); tbl_index -= (GRPC_CHTTP2_LAST_STATIC_ENTRY + 1);
if (tbl_index < tbl->num_ents) { if (tbl_index < tbl->num_ents) {
gpr_uint32 offset = (tbl->num_ents - 1u - tbl_index + tbl->first_ent) % gpr_uint32 offset =
tbl->cap_entries; (tbl->num_ents - 1u - tbl_index + tbl->first_ent) % tbl->cap_entries;
return tbl->ents[offset]; return tbl->ents[offset];
} }
/* Invalid entry: return error */ /* Invalid entry: return error */
@ -227,8 +229,7 @@ static void evict1(grpc_chttp2_hptbl *tbl) {
GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
GPR_ASSERT(elem_bytes <= tbl->mem_used); GPR_ASSERT(elem_bytes <= tbl->mem_used);
tbl->mem_used -= (gpr_uint32)elem_bytes; tbl->mem_used -= (gpr_uint32)elem_bytes;
tbl->first_ent = tbl->first_ent = ((tbl->first_ent + 1) % tbl->cap_entries);
((tbl->first_ent + 1) % tbl->cap_entries);
tbl->num_ents--; tbl->num_ents--;
GRPC_MDELEM_UNREF(first_ent); GRPC_MDELEM_UNREF(first_ent);
} }
@ -246,7 +247,8 @@ static void rebuild_ents(grpc_chttp2_hptbl *tbl, gpr_uint32 new_cap) {
tbl->first_ent = 0; tbl->first_ent = 0;
} }
void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl *tbl, gpr_uint32 max_bytes) { void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl *tbl,
gpr_uint32 max_bytes) {
if (tbl->max_bytes == max_bytes) { if (tbl->max_bytes == max_bytes) {
return; return;
} }
@ -257,12 +259,15 @@ void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl *tbl, gpr_uint32 max_byte
tbl->max_bytes = max_bytes; tbl->max_bytes = max_bytes;
} }
int grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl, gpr_uint32 bytes) { int grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl,
gpr_uint32 bytes) {
if (tbl->current_table_bytes == bytes) { if (tbl->current_table_bytes == bytes) {
return 1; return 1;
} }
if (bytes > tbl->max_bytes) { if (bytes > tbl->max_bytes) {
gpr_log(GPR_ERROR, "Attempt to make hpack table %d bytes when max is %d bytes", bytes, tbl->max_bytes); gpr_log(GPR_ERROR,
"Attempt to make hpack table %d bytes when max is %d bytes", bytes,
tbl->max_bytes);
return 0; return 0;
} }
gpr_log(GPR_DEBUG, "Update hpack parser table size to %d", bytes); gpr_log(GPR_DEBUG, "Update hpack parser table size to %d", bytes);
@ -289,7 +294,10 @@ int grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
if (tbl->current_table_bytes > tbl->max_bytes) { if (tbl->current_table_bytes > tbl->max_bytes) {
gpr_log(GPR_ERROR, "HPACK max table size reduced to %d but not reflected by hpack stream", tbl->max_bytes); gpr_log(
GPR_ERROR,
"HPACK max table size reduced to %d but not reflected by hpack stream",
tbl->max_bytes);
return 0; return 0;
} }
@ -319,8 +327,7 @@ int grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
tbl->ents[tbl->last_ent] = GRPC_MDELEM_REF(md); tbl->ents[tbl->last_ent] = GRPC_MDELEM_REF(md);
/* update accounting values */ /* update accounting values */
tbl->last_ent = tbl->last_ent = ((tbl->last_ent + 1) % tbl->cap_entries);
((tbl->last_ent + 1) % tbl->cap_entries);
tbl->num_ents++; tbl->num_ents++;
tbl->mem_used += (gpr_uint32)elem_bytes; tbl->mem_used += (gpr_uint32)elem_bytes;
return 1; return 1;
@ -344,8 +351,7 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find(
for (i = 0; i < tbl->num_ents; i++) { for (i = 0; i < tbl->num_ents; i++) {
gpr_uint32 idx = gpr_uint32 idx =
(gpr_uint32)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); (gpr_uint32)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY);
grpc_mdelem *ent = grpc_mdelem *ent = tbl->ents[(tbl->first_ent + i) % tbl->cap_entries];
tbl->ents[(tbl->first_ent + i) % tbl->cap_entries];
if (md->key != ent->key) continue; if (md->key != ent->key) continue;
r.index = idx; r.index = idx;
r.has_value = md->value == ent->value; r.has_value = md->value == ent->value;

@ -88,14 +88,17 @@ typedef struct {
/* initialize a hpack table */ /* initialize a hpack table */
void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx); 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_destroy(grpc_chttp2_hptbl *tbl);
void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl *tbl, gpr_uint32 max_bytes); void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl *tbl,
int grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl, gpr_uint32 bytes); gpr_uint32 max_bytes);
int grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl,
gpr_uint32 bytes);
/* lookup a table entry based on its hpack index */ /* lookup a table entry based on its hpack index */
grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
gpr_uint32 index); gpr_uint32 index);
/* add a table entry to the index */ /* add a table entry to the index */
int grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) GRPC_MUST_USE_RESULT; int grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl,
grpc_mdelem *md) GRPC_MUST_USE_RESULT;
/* Find a key/value pair in the table... returns the index in the table of the /* 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 */ most similar entry, or 0 if the value was not found */
typedef struct { typedef struct {

@ -78,7 +78,9 @@ void grpc_chttp2_prepare_to_read(
GPR_TIMER_BEGIN("grpc_chttp2_prepare_to_read", 0); GPR_TIMER_BEGIN("grpc_chttp2_prepare_to_read", 0);
transport_parsing->next_stream_id = transport_global->next_stream_id; transport_parsing->next_stream_id = transport_global->next_stream_id;
transport_parsing->last_sent_max_table_size = transport_global->settings[GRPC_SENT_SETTINGS][GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE]; transport_parsing->last_sent_max_table_size =
transport_global->settings[GRPC_SENT_SETTINGS]
[GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE];
/* update the parsing view of incoming window */ /* update the parsing view of incoming window */
while (grpc_chttp2_list_pop_unannounced_incoming_window_available( while (grpc_chttp2_list_pop_unannounced_incoming_window_available(
@ -821,7 +823,9 @@ static int init_settings_frame_parser(
} }
if (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_FLAG_ACK) { if (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_FLAG_ACK) {
transport_parsing->settings_ack_received = 1; transport_parsing->settings_ack_received = 1;
grpc_chttp2_hptbl_set_max_bytes(&transport_parsing->hpack_parser.table, transport_parsing->last_sent_max_table_size); grpc_chttp2_hptbl_set_max_bytes(
&transport_parsing->hpack_parser.table,
transport_parsing->last_sent_max_table_size);
} }
transport_parsing->parser = grpc_chttp2_settings_parser_parse; transport_parsing->parser = grpc_chttp2_settings_parser_parse;
transport_parsing->parser_data = &transport_parsing->simple.settings; transport_parsing->parser_data = &transport_parsing->simple.settings;

@ -45,8 +45,7 @@ static void finalize_outbuf(grpc_exec_ctx *exec_ctx,
int grpc_chttp2_unlocking_check_writes( int grpc_chttp2_unlocking_check_writes(
grpc_chttp2_transport_global *transport_global, grpc_chttp2_transport_global *transport_global,
grpc_chttp2_transport_writing *transport_writing, grpc_chttp2_transport_writing *transport_writing, int is_parsing) {
int is_parsing) {
grpc_chttp2_stream_global *stream_global; grpc_chttp2_stream_global *stream_global;
grpc_chttp2_stream_writing *stream_writing; grpc_chttp2_stream_writing *stream_writing;
@ -56,11 +55,13 @@ int grpc_chttp2_unlocking_check_writes(
gpr_slice_buffer_swap(&transport_global->qbuf, &transport_writing->outbuf); gpr_slice_buffer_swap(&transport_global->qbuf, &transport_writing->outbuf);
GPR_ASSERT(transport_global->qbuf.count == 0); GPR_ASSERT(transport_global->qbuf.count == 0);
grpc_chttp2_hpack_compressor_set_max_table_size(&transport_writing->hpack_compressor, transport_global->settings[GRPC_PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE]); grpc_chttp2_hpack_compressor_set_max_table_size(
&transport_writing->hpack_compressor,
transport_global->settings[GRPC_PEER_SETTINGS]
[GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE]);
if (transport_global->dirtied_local_settings && if (transport_global->dirtied_local_settings &&
!transport_global->sent_local_settings && !transport_global->sent_local_settings && !is_parsing) {
!is_parsing) {
gpr_slice_buffer_add( gpr_slice_buffer_add(
&transport_writing->outbuf, &transport_writing->outbuf,
grpc_chttp2_settings_create( grpc_chttp2_settings_create(

@ -338,21 +338,30 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
t->global.next_stream_id = t->global.next_stream_id =
(gpr_uint32)channel_args->args[i].value.integer; (gpr_uint32)channel_args->args[i].value.integer;
} }
} else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER)) { } else if (0 == strcmp(channel_args->args[i].key,
GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER)) {
if (channel_args->args[i].type != GRPC_ARG_INTEGER) { if (channel_args->args[i].type != GRPC_ARG_INTEGER) {
gpr_log(GPR_ERROR, "%s: must be an integer", GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER); gpr_log(GPR_ERROR, "%s: must be an integer",
GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER);
} else if (channel_args->args[i].value.integer < 0) { } else if (channel_args->args[i].value.integer < 0) {
gpr_log(GPR_DEBUG, "%s: must be non-negative", GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER); gpr_log(GPR_DEBUG, "%s: must be non-negative",
GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER);
} else { } else {
push_setting(t, GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE, (gpr_uint32)channel_args->args[i].value.integer); push_setting(t, GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE,
(gpr_uint32)channel_args->args[i].value.integer);
} }
} else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER)) { } else if (0 == strcmp(channel_args->args[i].key,
GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER)) {
if (channel_args->args[i].type != GRPC_ARG_INTEGER) { if (channel_args->args[i].type != GRPC_ARG_INTEGER) {
gpr_log(GPR_ERROR, "%s: must be an integer", GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER); gpr_log(GPR_ERROR, "%s: must be an integer",
GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER);
} else if (channel_args->args[i].value.integer < 0) { } else if (channel_args->args[i].value.integer < 0) {
gpr_log(GPR_DEBUG, "%s: must be non-negative", GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER); gpr_log(GPR_DEBUG, "%s: must be non-negative",
GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER);
} else { } else {
grpc_chttp2_hpack_compressor_set_max_usable_size(&t->writing.hpack_compressor, (gpr_uint32)channel_args->args[i].value.integer); grpc_chttp2_hpack_compressor_set_max_usable_size(
&t->writing.hpack_compressor,
(gpr_uint32)channel_args->args[i].value.integer);
} }
} }
} }
@ -579,7 +588,8 @@ static void lock(grpc_chttp2_transport *t) { gpr_mu_lock(&t->mu); }
static void unlock(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { static void unlock(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) {
GPR_TIMER_BEGIN("unlock", 0); GPR_TIMER_BEGIN("unlock", 0);
if (!t->writing_active && !t->closed && if (!t->writing_active && !t->closed &&
grpc_chttp2_unlocking_check_writes(&t->global, &t->writing, t->parsing_active)) { grpc_chttp2_unlocking_check_writes(&t->global, &t->writing,
t->parsing_active)) {
t->writing_active = 1; t->writing_active = 1;
REF_TRANSPORT(t, "writing"); REF_TRANSPORT(t, "writing");
grpc_exec_ctx_enqueue(exec_ctx, &t->writing_action, 1); grpc_exec_ctx_enqueue(exec_ctx, &t->writing_action, 1);
@ -1054,7 +1064,8 @@ void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx,
to the upper layers - drop what we've got, and then publish to the upper layers - drop what we've got, and then publish
what we want - which is safe because we haven't told anyone what we want - which is safe because we haven't told anyone
about the metadata yet */ about the metadata yet */
if (!stream_global->published_trailing_metadata || stream_global->recv_trailing_metadata_finished != NULL) { if (!stream_global->published_trailing_metadata ||
stream_global->recv_trailing_metadata_finished != NULL) {
grpc_mdctx *mdctx = grpc_mdctx *mdctx =
TRANSPORT_FROM_GLOBAL(transport_global)->metadata_context; TRANSPORT_FROM_GLOBAL(transport_global)->metadata_context;
char status_string[GPR_LTOA_MIN_BUFSIZE]; char status_string[GPR_LTOA_MIN_BUFSIZE];

@ -135,9 +135,8 @@ static void kill_server(const servers_fixture *f, size_t i) {
gpr_log(GPR_INFO, "KILLING SERVER %d", i); gpr_log(GPR_INFO, "KILLING SERVER %d", i);
GPR_ASSERT(f->servers[i] != NULL); GPR_ASSERT(f->servers[i] != NULL);
grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000));
GPR_ASSERT( GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(10000), n_millis_time(5000),
grpc_completion_queue_pluck(f->cq, tag(10000), n_millis_time(5000), NULL) NULL).type == GRPC_OP_COMPLETE);
.type == GRPC_OP_COMPLETE);
grpc_server_destroy(f->servers[i]); grpc_server_destroy(f->servers[i]);
f->servers[i] = NULL; f->servers[i] = NULL;
} }
@ -203,8 +202,8 @@ static void teardown_servers(servers_fixture *f) {
if (f->servers[i] == NULL) continue; if (f->servers[i] == NULL) continue;
grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000));
GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(10000), GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(10000),
n_millis_time(5000), NULL) n_millis_time(5000),
.type == GRPC_OP_COMPLETE); NULL).type == GRPC_OP_COMPLETE);
grpc_server_destroy(f->servers[i]); grpc_server_destroy(f->servers[i]);
} }
grpc_completion_queue_shutdown(f->cq); grpc_completion_queue_shutdown(f->cq);
@ -269,8 +268,8 @@ int *perform_request(servers_fixture *f, grpc_channel *client,
memset(s_valid, 0, f->num_servers * sizeof(int)); memset(s_valid, 0, f->num_servers * sizeof(int));
c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq,
"/foo", "foo.test.google.fr", gpr_inf_future(GPR_CLOCK_REALTIME), "/foo", "foo.test.google.fr",
NULL); gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
GPR_ASSERT(c); GPR_ASSERT(c);
completed_client = 0; completed_client = 0;
@ -303,8 +302,9 @@ int *perform_request(servers_fixture *f, grpc_channel *client,
grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL)); grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL));
s_idx = -1; s_idx = -1;
while ((ev = grpc_completion_queue_next(f->cq, n_millis_time(s_idx == -1 ? 3000 : 200), NULL)) while ((ev = grpc_completion_queue_next(
.type != GRPC_QUEUE_TIMEOUT) { f->cq, n_millis_time(s_idx == -1 ? 3000 : 200), NULL)).type !=
GRPC_QUEUE_TIMEOUT) {
GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
read_tag = ((int)(gpr_intptr)ev.tag); read_tag = ((int)(gpr_intptr)ev.tag);
gpr_log(GPR_DEBUG, "EVENT: success:%d, type:%d, tag:%d iter:%d", gpr_log(GPR_DEBUG, "EVENT: success:%d, type:%d, tag:%d iter:%d",

@ -166,7 +166,8 @@ static void simple_request_body(grpc_end2end_test_fixture f, size_t num_ops) {
cq_verifier_destroy(cqv); cq_verifier_destroy(cqv);
} }
static void test_invoke_simple_request(grpc_end2end_test_config config, size_t num_ops) { static void test_invoke_simple_request(grpc_end2end_test_config config,
size_t num_ops) {
grpc_end2end_test_fixture f; grpc_end2end_test_fixture f;
f = begin_test(config, "test_invoke_simple_request", NULL, NULL); f = begin_test(config, "test_invoke_simple_request", NULL, NULL);

@ -49,8 +49,7 @@
static void *tag(gpr_intptr t) { return (void *)t; } static void *tag(gpr_intptr t) { return (void *)t; }
const char *hobbits[][2] = { const char *hobbits[][2] = {{"Adaldrida", "Brandybuck"},
{"Adaldrida", "Brandybuck"},
{"Adamanta", "Took"}, {"Adamanta", "Took"},
{"Adalgrim", "Took"}, {"Adalgrim", "Took"},
{"Adelard", "Took"}, {"Adelard", "Took"},
@ -230,15 +229,10 @@ const char *hobbits[][2] = {
{"Wilcome", "Cotton"}, {"Wilcome", "Cotton"},
{"Wilibald", "Bolger"}, {"Wilibald", "Bolger"},
{"Will", "Whitfoot"}, {"Will", "Whitfoot"},
{"Wiseman", "Gamwich"} {"Wiseman", "Gamwich"}};
};
const char *dragons[] = { const char *dragons[] = {"Ancalagon", "Glaurung", "Scatha",
"Ancalagon", "Smaug the Magnificent"};
"Glaurung",
"Scatha",
"Smaug the Magnificent"
};
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char *test_name, const char *test_name,
@ -406,7 +400,8 @@ static void simple_request_body(grpc_end2end_test_fixture f, size_t index) {
cq_verifier_destroy(cqv); cq_verifier_destroy(cqv);
} }
static void test_size(grpc_end2end_test_config config, int encode_size, int decode_size) { static void test_size(grpc_end2end_test_config config, int encode_size,
int decode_size) {
size_t i; size_t i;
grpc_end2end_test_fixture f; grpc_end2end_test_fixture f;
grpc_arg server_arg; grpc_arg server_arg;
@ -428,7 +423,8 @@ static void test_size(grpc_end2end_test_config config, int encode_size, int deco
client_args.args = &client_arg; client_args.args = &client_arg;
gpr_asprintf(&name, "test_size:e=%d:d=%d", encode_size, decode_size); gpr_asprintf(&name, "test_size:e=%d:d=%d", encode_size, decode_size);
f = begin_test(config, name, encode_size != 4096 ? &client_args : NULL, decode_size != 4096 ? &server_args : NULL); f = begin_test(config, name, encode_size != 4096 ? &client_args : NULL,
decode_size != 4096 ? &server_args : NULL);
for (i = 0; i < 4 * GPR_ARRAY_SIZE(hobbits); i++) { for (i = 0; i < 4 * GPR_ARRAY_SIZE(hobbits); i++) {
simple_request_body(f, i); simple_request_body(f, i);
} }
@ -439,24 +435,9 @@ static void test_size(grpc_end2end_test_config config, int encode_size, int deco
void grpc_end2end_tests(grpc_end2end_test_config config) { void grpc_end2end_tests(grpc_end2end_test_config config) {
static const int interesting_sizes[] = { static const int interesting_sizes[] = {
4096, 4096, 0, 1, 32, 100, 1000, 4095, 4097, 8192, 16384, 32768,
0, 1024 * 1024 - 1, 1024 * 1024, 1024 * 1024 + 1, 2 * 1024 * 1024,
1, 3 * 1024 * 1024, 4 * 1024 * 1024};
32,
100,
1000,
4095,
4097,
8192,
16384,
32768,
1024*1024-1,
1024*1024,
1024*1024+1,
2*1024*1024,
3*1024*1024,
4*1024*1024
};
size_t i, j; size_t i, j;
for (i = 0; i < GPR_ARRAY_SIZE(interesting_sizes); i++) { for (i = 0; i < GPR_ARRAY_SIZE(interesting_sizes); i++) {

@ -163,7 +163,8 @@ static void simple_request_body(grpc_end2end_test_fixture f, size_t num_ops) {
cq_verifier_destroy(cqv); cq_verifier_destroy(cqv);
} }
static void test_invoke_simple_request(grpc_end2end_test_config config, size_t num_ops) { static void test_invoke_simple_request(grpc_end2end_test_config config,
size_t num_ops) {
grpc_end2end_test_fixture f; grpc_end2end_test_fixture f;
f = begin_test(config, "test_invoke_simple_request", NULL, NULL); f = begin_test(config, "test_invoke_simple_request", NULL, NULL);

@ -174,8 +174,8 @@ static int epoll_read_bytes(struct thread_args *args, char *buf, int spin) {
GPR_ASSERT(ev.data.fd == args->fds.read_fd); GPR_ASSERT(ev.data.fd == args->fds.read_fd);
do { do {
do { do {
err2 = read(args->fds.read_fd, buf + bytes_read, err2 =
read_size - bytes_read); read(args->fds.read_fd, buf + bytes_read, read_size - bytes_read);
} while (err2 < 0 && errno == EINTR); } while (err2 < 0 && errno == EINTR);
if (errno == EAGAIN) break; if (errno == EAGAIN) break;
bytes_read += (size_t)err2; bytes_read += (size_t)err2;

@ -145,7 +145,8 @@ static void test_many_additions(void) {
for (i = 0; i < 1000000; i++) { for (i = 0; i < 1000000; i++) {
gpr_asprintf(&key, "K:%d", i); gpr_asprintf(&key, "K:%d", i);
gpr_asprintf(&value, "VALUE:%d", i); gpr_asprintf(&value, "VALUE:%d", i);
GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, key, value))); GPR_ASSERT(grpc_chttp2_hptbl_add(
&tbl, grpc_mdelem_from_strings(mdctx, key, value)));
assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value); assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value);
gpr_free(key); gpr_free(key);
gpr_free(value); gpr_free(value);
@ -182,9 +183,12 @@ static void test_find(void) {
mdctx = grpc_mdctx_create(); mdctx = grpc_mdctx_create();
grpc_chttp2_hptbl_init(&tbl, mdctx); grpc_chttp2_hptbl_init(&tbl, mdctx);
GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, "abc", "xyz"))); GPR_ASSERT(grpc_chttp2_hptbl_add(
GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, "abc", "123"))); &tbl, grpc_mdelem_from_strings(mdctx, "abc", "xyz")));
GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, "x", "1"))); GPR_ASSERT(grpc_chttp2_hptbl_add(
&tbl, grpc_mdelem_from_strings(mdctx, "abc", "123")));
GPR_ASSERT(
grpc_chttp2_hptbl_add(&tbl, grpc_mdelem_from_strings(mdctx, "x", "1")));
r = find_simple(&tbl, "abc", "123"); r = find_simple(&tbl, "abc", "123");
GPR_ASSERT(r.index == 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY); GPR_ASSERT(r.index == 2 + GRPC_CHTTP2_LAST_STATIC_ENTRY);
@ -233,8 +237,8 @@ static void test_find(void) {
/* overflow the string buffer, check find still works */ /* overflow the string buffer, check find still works */
for (i = 0; i < 10000; i++) { for (i = 0; i < 10000; i++) {
gpr_ltoa(i, buffer); gpr_ltoa(i, buffer);
GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, GPR_ASSERT(grpc_chttp2_hptbl_add(
grpc_mdelem_from_strings(mdctx, "test", buffer))); &tbl, grpc_mdelem_from_strings(mdctx, "test", buffer)));
} }
r = find_simple(&tbl, "abc", "123"); r = find_simple(&tbl, "abc", "123");

Loading…
Cancel
Save