コード例 #1
0
ファイル: chttp2_transport.c プロジェクト: spietz-handy/grpc
static void destruct_transport(grpc_exec_ctx *exec_ctx,
                               grpc_chttp2_transport *t) {
  size_t i;

  gpr_mu_lock(&t->mu);

  GPR_ASSERT(t->ep == NULL);

  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->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);

  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);

  grpc_chttp2_stream_map_destroy(&t->parsing_stream_map);
  grpc_chttp2_stream_map_destroy(&t->new_stream_map);
  grpc_connectivity_state_destroy(exec_ctx, &t->channel_callback.state_tracker);

  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_exec_ctx_enqueue(exec_ctx, 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);
}
コード例 #2
0
ファイル: stream_encoder_test.c プロジェクト: alindeman/grpc
static void test_decode_random_headers_inner(int max_len) {
  int i;
  test_decode_random_header_state st;
  gpr_slice_buffer output;
  gpr_slice merged;
  grpc_stream_op_buffer encops;
  grpc_chttp2_hpack_parser parser;

  grpc_chttp2_hpack_parser_init(&parser, g_mdctx);
  grpc_sopb_init(&encops);

  gpr_log(GPR_INFO, "max_len = %d", max_len);

  for (i = 0; i < 10000; i++) {
    randstr(st.key, max_len);
    randstr(st.value, max_len);

    add_sopb_headers(1, st.key, st.value);
    gpr_slice_buffer_init(&output);
    GPR_ASSERT(0 ==
               grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, 0, &encops));
    grpc_chttp2_encode(encops.ops, encops.nops, 0, 0xdeadbeef, &g_compressor,
                       &output);
    encops.nops = 0;
    merged = grpc_slice_merge(output.slices, output.count);
    gpr_slice_buffer_destroy(&output);

    st.got_hdr = 0;
    parser.on_header = chk_hdr;
    parser.on_header_user_data = &st;
    grpc_chttp2_hpack_parser_parse(&parser, GPR_SLICE_START_PTR(merged) + 9,
                                   GPR_SLICE_END_PTR(merged));
    GPR_ASSERT(st.got_hdr);

    gpr_slice_unref(merged);
  }

  grpc_chttp2_hpack_parser_destroy(&parser);
  grpc_sopb_destroy(&encops);
}
コード例 #3
0
ファイル: hpack_parser_test.c プロジェクト: An-mol/grpc
static void test_vectors(grpc_slice_split_mode mode) {
  grpc_chttp2_hpack_parser parser;

  grpc_chttp2_hpack_parser_init(&parser);
  /* D.2.1 */
  test_vector(&parser, mode,
              "400a 6375 7374 6f6d 2d6b 6579 0d63 7573"
              "746f 6d2d 6865 6164 6572",
              "custom-key", "custom-header", NULL);
  /* D.2.2 */
  test_vector(&parser, mode, "040c 2f73 616d 706c 652f 7061 7468", ":path",
              "/sample/path", NULL);
  /* D.2.3 */
  test_vector(&parser, mode,
              "1008 7061 7373 776f 7264 0673 6563 7265"
              "74",
              "password", "secret", NULL);
  /* D.2.4 */
  test_vector(&parser, mode, "82", ":method", "GET", NULL);
  grpc_chttp2_hpack_parser_destroy(&parser);

  grpc_chttp2_hpack_parser_init(&parser);
  /* D.3.1 */
  test_vector(&parser, mode,
              "8286 8441 0f77 7777 2e65 7861 6d70 6c65"
              "2e63 6f6d",
              ":method", "GET", ":scheme", "http", ":path", "/", ":authority",
              "www.example.com", NULL);
  /* D.3.2 */
  test_vector(&parser, mode, "8286 84be 5808 6e6f 2d63 6163 6865", ":method",
              "GET", ":scheme", "http", ":path", "/", ":authority",
              "www.example.com", "cache-control", "no-cache", NULL);
  /* D.3.3 */
  test_vector(&parser, mode,
              "8287 85bf 400a 6375 7374 6f6d 2d6b 6579"
              "0c63 7573 746f 6d2d 7661 6c75 65",
              ":method", "GET", ":scheme", "https", ":path", "/index.html",
              ":authority", "www.example.com", "custom-key", "custom-value",
              NULL);
  grpc_chttp2_hpack_parser_destroy(&parser);

  grpc_chttp2_hpack_parser_init(&parser);
  /* D.4.1 */
  test_vector(&parser, mode,
              "8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4"
              "ff",
              ":method", "GET", ":scheme", "http", ":path", "/", ":authority",
              "www.example.com", NULL);
  /* D.4.2 */
  test_vector(&parser, mode, "8286 84be 5886 a8eb 1064 9cbf", ":method", "GET",
              ":scheme", "http", ":path", "/", ":authority", "www.example.com",
              "cache-control", "no-cache", NULL);
  /* D.4.3 */
  test_vector(&parser, mode,
              "8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925"
              "a849 e95b b8e8 b4bf",
              ":method", "GET", ":scheme", "https", ":path", "/index.html",
              ":authority", "www.example.com", "custom-key", "custom-value",
              NULL);
  grpc_chttp2_hpack_parser_destroy(&parser);

  grpc_chttp2_hpack_parser_init(&parser);
  grpc_chttp2_hptbl_set_max_bytes(&parser.table, 256);
  grpc_chttp2_hptbl_set_current_table_size(&parser.table, 256);
  /* D.5.1 */
  test_vector(&parser, mode,
              "4803 3330 3258 0770 7269 7661 7465 611d"
              "4d6f 6e2c 2032 3120 4f63 7420 3230 3133"
              "2032 303a 3133 3a32 3120 474d 546e 1768"
              "7474 7073 3a2f 2f77 7777 2e65 7861 6d70"
              "6c65 2e63 6f6d",
              ":status", "302", "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:21 GMT", "location",
              "https://www.example.com", NULL);
  /* D.5.2 */
  test_vector(&parser, mode, "4803 3330 37c1 c0bf", ":status", "307",
              "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:21 GMT", "location",
              "https://www.example.com", NULL);
  /* D.5.3 */
  test_vector(&parser, mode,
              "88c1 611d 4d6f 6e2c 2032 3120 4f63 7420"
              "3230 3133 2032 303a 3133 3a32 3220 474d"
              "54c0 5a04 677a 6970 7738 666f 6f3d 4153"
              "444a 4b48 514b 425a 584f 5157 454f 5049"
              "5541 5851 5745 4f49 553b 206d 6178 2d61"
              "6765 3d33 3630 303b 2076 6572 7369 6f6e"
              "3d31",
              ":status", "200", "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:22 GMT", "location",
              "https://www.example.com", "content-encoding", "gzip",
              "set-cookie",
              "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL);
  grpc_chttp2_hpack_parser_destroy(&parser);

  grpc_chttp2_hpack_parser_init(&parser);
  grpc_chttp2_hptbl_set_max_bytes(&parser.table, 256);
  grpc_chttp2_hptbl_set_current_table_size(&parser.table, 256);
  /* D.6.1 */
  test_vector(&parser, mode,
              "4882 6402 5885 aec3 771a 4b61 96d0 7abe"
              "9410 54d4 44a8 2005 9504 0b81 66e0 82a6"
              "2d1b ff6e 919d 29ad 1718 63c7 8f0b 97c8"
              "e9ae 82ae 43d3",
              ":status", "302", "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:21 GMT", "location",
              "https://www.example.com", NULL);
  /* D.6.2 */
  test_vector(&parser, mode, "4883 640e ffc1 c0bf", ":status", "307",
              "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:21 GMT", "location",
              "https://www.example.com", NULL);
  /* D.6.3 */
  test_vector(&parser, mode,
              "88c1 6196 d07a be94 1054 d444 a820 0595"
              "040b 8166 e084 a62d 1bff c05a 839b d9ab"
              "77ad 94e7 821d d7f2 e6c7 b335 dfdf cd5b"
              "3960 d5af 2708 7f36 72c1 ab27 0fb5 291f"
              "9587 3160 65c0 03ed 4ee5 b106 3d50 07",
              ":status", "200", "cache-control", "private", "date",
              "Mon, 21 Oct 2013 20:13:22 GMT", "location",
              "https://www.example.com", "content-encoding", "gzip",
              "set-cookie",
              "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1", NULL);
  grpc_chttp2_hpack_parser_destroy(&parser);
}