示例#1
0
文件: writing.c 项目: kumarh1982/grpc
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;
        }
        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));
            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);
    }
}
示例#2
0
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
/* verify that the output generated by encoding the stream matches the
   hexstring passed in */
static void verify_sopb(size_t window_available, int eof,
                        size_t expect_window_used, const char *expected) {
  gpr_slice_buffer output;
  grpc_stream_op_buffer encops;
  gpr_slice merged;
  gpr_slice expect = parse_hexstring(expected);
  gpr_slice_buffer_init(&output);
  grpc_sopb_init(&encops);
  GPR_ASSERT(expect_window_used ==
             grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, window_available,
                                   &encops));
  grpc_chttp2_encode(encops.ops, encops.nops, eof, 0xdeadbeef, &g_compressor,
                     &output);
  encops.nops = 0;
  merged = grpc_slice_merge(output.slices, output.count);
  gpr_slice_buffer_destroy(&output);
  grpc_sopb_destroy(&encops);

  if (0 != gpr_slice_cmp(merged, expect)) {
    char *expect_str =
        gpr_hexdump((char *)GPR_SLICE_START_PTR(expect),
                    GPR_SLICE_LENGTH(expect), GPR_HEXDUMP_PLAINTEXT);
    char *got_str =
        gpr_hexdump((char *)GPR_SLICE_START_PTR(merged),
                    GPR_SLICE_LENGTH(merged), GPR_HEXDUMP_PLAINTEXT);
    gpr_log(GPR_ERROR, "mismatched output for %s", expected);
    gpr_log(GPR_ERROR, "EXPECT: %s", expect_str);
    gpr_log(GPR_ERROR, "GOT:    %s", got_str);
    gpr_free(expect_str);
    gpr_free(got_str);
    g_failure = 1;
  }

  gpr_slice_unref(merged);
  gpr_slice_unref(expect);
}