frame_rst_stream.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
22 
23 #include <stddef.h>
24 
25 #include "absl/strings/str_cat.h"
26 #include "absl/strings/str_format.h"
27 
28 #include <grpc/slice_buffer.h>
29 #include <grpc/support/log.h>
30 
37 
40  static const size_t frame_size = 13;
41  grpc_slice slice = GRPC_SLICE_MALLOC(frame_size);
42  if (stats != nullptr) stats->framing_bytes += frame_size;
44 
45  // Frame size.
46  *p++ = 0;
47  *p++ = 0;
48  *p++ = 4;
49  // Frame type.
51  // Flags.
52  *p++ = 0;
53  // Stream ID.
54  *p++ = static_cast<uint8_t>(id >> 24);
55  *p++ = static_cast<uint8_t>(id >> 16);
56  *p++ = static_cast<uint8_t>(id >> 8);
57  *p++ = static_cast<uint8_t>(id);
58  // Error code.
59  *p++ = static_cast<uint8_t>(code >> 24);
60  *p++ = static_cast<uint8_t>(code >> 16);
61  *p++ = static_cast<uint8_t>(code >> 8);
62  *p++ = static_cast<uint8_t>(code);
63 
64  return slice;
65 }
66 
70  t->num_pending_induced_frames++;
71  grpc_slice_buffer_add(&t->qbuf,
73 }
74 
77  if (length != 4) {
79  "invalid rst_stream: length=%d, flags=%02x", length, flags));
80  }
81  parser->byte = 0;
82  return GRPC_ERROR_NONE;
83 }
84 
88  const grpc_slice& slice,
89  int is_last) {
90  const uint8_t* const beg = GRPC_SLICE_START_PTR(slice);
91  const uint8_t* const end = GRPC_SLICE_END_PTR(slice);
92  const uint8_t* cur = beg;
95 
96  while (p->byte != 4 && cur != end) {
97  p->reason_bytes[p->byte] = *cur;
98  cur++;
99  p->byte++;
100  }
101  s->stats.incoming.framing_bytes += static_cast<uint64_t>(end - cur);
102 
103  if (p->byte == 4) {
104  GPR_ASSERT(is_last);
105  uint32_t reason = ((static_cast<uint32_t>(p->reason_bytes[0])) << 24) |
106  ((static_cast<uint32_t>(p->reason_bytes[1])) << 16) |
107  ((static_cast<uint32_t>(p->reason_bytes[2])) << 8) |
108  ((static_cast<uint32_t>(p->reason_bytes[3])));
111  "[chttp2 transport=%p stream=%p] received RST_STREAM(reason=%d)",
112  t, s, reason);
113  }
115  if (reason != GRPC_HTTP2_NO_ERROR || s->trailing_metadata_buffer.empty()) {
120  absl::StrCat("Received RST_STREAM with error code ", reason)),
121  GRPC_ERROR_INT_HTTP2_ERROR, static_cast<intptr_t>(reason));
122  }
123  grpc_chttp2_mark_stream_closed(t, s, true, true, error);
124  }
125 
126  return GRPC_ERROR_NONE;
127 }
trace.h
GPR_INFO
#define GPR_INFO
Definition: include/grpc/impl/codegen/log.h:56
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
Definition: error.h:234
log.h
metadata_batch.h
absl::StrCat
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: abseil-cpp/absl/strings/str_cat.cc:98
absl::StrFormat
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec< Args... > &format, const Args &... args)
Definition: abseil-cpp/absl/strings/str_format.h:338
internal.h
GRPC_ERROR_INT_HTTP2_ERROR
@ GRPC_ERROR_INT_HTTP2_ERROR
http2 error code associated with the error (see the HTTP2 RFC)
Definition: error.h:77
grpc_chttp2_rst_stream_parser_parse
grpc_error_handle grpc_chttp2_rst_stream_parser_parse(void *parser, grpc_chttp2_transport *t, grpc_chttp2_stream *s, const grpc_slice &slice, int is_last)
Definition: frame_rst_stream.cc:85
GRPC_SLICE_MALLOC
#define GRPC_SLICE_MALLOC(len)
Definition: include/grpc/slice.h:70
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_http_trace
grpc_core::TraceFlag grpc_http_trace(false, "http")
xds_manager.p
p
Definition: xds_manager.py:60
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
GRPC_TRACE_FLAG_ENABLED
#define GRPC_TRACE_FLAG_ENABLED(f)
Definition: debug/trace.h:114
grpc_status._async.code
code
Definition: grpcio_status/grpc_status/_async.py:34
grpc_chttp2_stream
Definition: src/core/ext/transport/chttp2/transport/internal.h:456
grpc_error_set_str
grpc_error_handle grpc_error_set_str(grpc_error_handle src, grpc_error_strs which, absl::string_view str)
Definition: error.cc:650
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
asyncio_get_stats.parser
parser
Definition: asyncio_get_stats.py:34
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
gen_stats_data.stats
list stats
Definition: gen_stats_data.py:58
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
GRPC_SLICE_START_PTR
#define GRPC_SLICE_START_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:101
slice_buffer.h
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
GRPC_ERROR_STR_GRPC_MESSAGE
@ GRPC_ERROR_STR_GRPC_MESSAGE
grpc status message associated with this error
Definition: error.h:120
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
GRPC_SLICE_END_PTR
#define GRPC_SLICE_END_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:110
grpc_transport_one_way_stats
Definition: transport.h:243
GRPC_CHTTP2_FRAME_RST_STREAM
#define GRPC_CHTTP2_FRAME_RST_STREAM
Definition: frame.h:31
GRPC_ERROR_CREATE_FROM_STATIC_STRING
#define GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc)
Definition: error.h:291
frame.h
grpc_chttp2_rst_stream_parser_begin_frame
grpc_error_handle grpc_chttp2_rst_stream_parser_begin_frame(grpc_chttp2_rst_stream_parser *parser, uint32_t length, uint8_t flags)
Definition: frame_rst_stream.cc:75
memory_diff.cur
def cur
Definition: memory_diff.py:83
grpc_slice_buffer_add
GPRAPI void grpc_slice_buffer_add(grpc_slice_buffer *sb, grpc_slice slice)
Definition: slice/slice_buffer.cc:170
grpc_chttp2_rst_stream_create
grpc_slice grpc_chttp2_rst_stream_create(uint32_t id, uint32_t code, grpc_transport_one_way_stats *stats)
Definition: frame_rst_stream.cc:38
grpc_error_set_int
grpc_error_handle grpc_error_set_int(grpc_error_handle src, grpc_error_ints which, intptr_t value)
Definition: error.cc:613
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
GRPC_ERROR_CREATE_FROM_CPP_STRING
#define GRPC_ERROR_CREATE_FROM_CPP_STRING(desc)
Definition: error.h:297
grpc_chttp2_rst_stream_parser
Definition: frame_rst_stream.h:32
http2_errors.h
grpc_chttp2_transport
Definition: src/core/ext/transport/chttp2/transport/internal.h:238
hpack_encoder.h
grpc_chttp2_mark_stream_closed
void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport *t, grpc_chttp2_stream *s, int close_reads, int close_writes, grpc_error_handle error)
Definition: chttp2_transport.cc:2193
grpc_chttp2_add_rst_stream_to_next_write
void grpc_chttp2_add_rst_stream_to_next_write(grpc_chttp2_transport *t, uint32_t id, uint32_t code, grpc_transport_one_way_stats *stats)
Definition: frame_rst_stream.cc:67
code
Definition: bloaty/third_party/zlib/contrib/infback9/inftree9.h:24
grpc_error
Definition: error_internal.h:42
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
frame_rst_stream.h
GRPC_HTTP2_NO_ERROR
@ GRPC_HTTP2_NO_ERROR
Definition: http2_errors.h:24
id
uint32_t id
Definition: flow_control_fuzzer.cc:70
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:25