frame_window_update.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/support/log.h>
29 
32 
35  static const size_t frame_size = 13;
36  grpc_slice slice = GRPC_SLICE_MALLOC(frame_size);
37  stats->header_bytes += frame_size;
39 
41 
42  *p++ = 0;
43  *p++ = 0;
44  *p++ = 4;
46  *p++ = 0;
47  *p++ = static_cast<uint8_t>(id >> 24);
48  *p++ = static_cast<uint8_t>(id >> 16);
49  *p++ = static_cast<uint8_t>(id >> 8);
50  *p++ = static_cast<uint8_t>(id);
51  *p++ = static_cast<uint8_t>(window_delta >> 24);
52  *p++ = static_cast<uint8_t>(window_delta >> 16);
53  *p++ = static_cast<uint8_t>(window_delta >> 8);
54  *p++ = static_cast<uint8_t>(window_delta);
55 
56  return slice;
57 }
58 
61  if (flags || length != 4) {
63  "invalid window update: length=%d, flags=%02x", length, flags));
64  }
65  parser->byte = 0;
66  parser->amount = 0;
67  return GRPC_ERROR_NONE;
68 }
69 
72  const grpc_slice& slice, int is_last) {
73  const uint8_t* const beg = GRPC_SLICE_START_PTR(slice);
74  const uint8_t* const end = GRPC_SLICE_END_PTR(slice);
75  const uint8_t* cur = beg;
78 
79  while (p->byte != 4 && cur != end) {
80  p->amount |= (static_cast<uint32_t>(*cur)) << (8 * (3 - p->byte));
81  cur++;
82  p->byte++;
83  }
84 
85  if (s != nullptr) {
86  s->stats.incoming.framing_bytes += static_cast<uint32_t>(end - cur);
87  }
88 
89  if (p->byte == 4) {
90  // top bit is reserved and must be ignored.
91  uint32_t received_update = p->amount & 0x7fffffffu;
92  if (received_update == 0) {
94  absl::StrCat("invalid window update bytes: ", p->amount));
95  }
96  GPR_ASSERT(is_last);
97 
98  if (t->incoming_stream_id != 0) {
99  if (s != nullptr) {
101  &s->flow_control)
102  .RecvUpdate(received_update);
107  }
108  }
109  } else {
111  &t->flow_control);
112  upd.RecvUpdate(received_update);
116  }
117  }
118  }
119 
120  return GRPC_ERROR_NONE;
121 }
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
Definition: error.h:234
log.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
GRPC_CHTTP2_FRAME_WINDOW_UPDATE
#define GRPC_CHTTP2_FRAME_WINDOW_UPDATE
Definition: frame.h:35
internal.h
GRPC_SLICE_MALLOC
#define GRPC_SLICE_MALLOC(len)
Definition: include/grpc/slice.h:70
GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_UPDATE
@ GRPC_CHTTP2_INITIATE_WRITE_FLOW_CONTROL_UNSTALLED_BY_UPDATE
Definition: src/core/ext/transport/chttp2/transport/internal.h:123
GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL_UNSTALLED
@ GRPC_CHTTP2_INITIATE_WRITE_TRANSPORT_FLOW_CONTROL_UNSTALLED
Definition: src/core/ext/transport/chttp2/transport/internal.h:127
u
OPENSSL_EXPORT pem_password_cb void * u
Definition: pem.h:351
xds_manager.p
p
Definition: xds_manager.py:60
grpc_chttp2_window_update_parser_parse
grpc_error_handle grpc_chttp2_window_update_parser_parse(void *parser, grpc_chttp2_transport *t, grpc_chttp2_stream *s, const grpc_slice &slice, int is_last)
Definition: frame_window_update.cc:70
grpc_chttp2_window_update_parser
Definition: frame_window_update.h:32
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
grpc_chttp2_stream
Definition: src/core/ext/transport/chttp2/transport/internal.h:456
grpc_chttp2_mark_stream_writable
void grpc_chttp2_mark_stream_writable(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: chttp2_transport.cc:931
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
grpc_core::chttp2::TransportFlowControl::OutgoingUpdateContext
Definition: flow_control.h:201
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
gen_stats_data.stats
list stats
Definition: gen_stats_data.py:58
grpc_chttp2_window_update_parser_begin_frame
grpc_error_handle grpc_chttp2_window_update_parser_begin_frame(grpc_chttp2_window_update_parser *parser, uint32_t length, uint8_t flags)
Definition: frame_window_update.cc:59
window_delta
int64_t window_delta
Definition: flow_control_fuzzer.cc:92
grpc_core::chttp2::StallEdge::kUnstalled
@ kUnstalled
GRPC_SLICE_START_PTR
#define GRPC_SLICE_START_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:101
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
grpc_chttp2_window_update_create
grpc_slice grpc_chttp2_window_update_create(uint32_t id, uint32_t window_delta, grpc_transport_one_way_stats *stats)
Definition: frame_window_update.cc:33
grpc_core::chttp2::StreamFlowControl::OutgoingUpdateContext::RecvUpdate
void RecvUpdate(uint32_t size)
Definition: flow_control.h:334
GRPC_SLICE_END_PTR
#define GRPC_SLICE_END_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:110
grpc_core::chttp2::TransportFlowControl::OutgoingUpdateContext::Finish
StallEdge Finish()
Definition: flow_control.h:210
grpc_transport_one_way_stats
Definition: transport.h:243
memory_diff.cur
def cur
Definition: memory_diff.py:83
grpc_chttp2_list_remove_stalled_by_stream
bool grpc_chttp2_list_remove_stalled_by_stream(grpc_chttp2_transport *t, grpc_chttp2_stream *s)
Definition: stream_lists.cc:213
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
grpc_chttp2_initiate_write
void grpc_chttp2_initiate_write(grpc_chttp2_transport *t, grpc_chttp2_initiate_write_reason reason)
Definition: chttp2_transport.cc:891
GRPC_ERROR_CREATE_FROM_CPP_STRING
#define GRPC_ERROR_CREATE_FROM_CPP_STRING(desc)
Definition: error.h:297
frame_window_update.h
flow_control.h
grpc_chttp2_transport
Definition: src/core/ext/transport/chttp2/transport/internal.h:238
grpc_core::chttp2::StreamFlowControl::OutgoingUpdateContext
Definition: flow_control.h:329
grpc_core::chttp2::TransportFlowControl::OutgoingUpdateContext::RecvUpdate
void RecvUpdate(uint32_t size)
Definition: flow_control.h:207
grpc_error
Definition: error_internal.h:42
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
id
uint32_t id
Definition: flow_control_fuzzer.cc:70
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:22