MCPcopy Create free account
hub / github.com/apache/brpc / AddWindowSize

Function AddWindowSize

src/brpc/policy/http2_rpc_protocol.cpp:267–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265}
266
267inline bool AddWindowSize(butil::atomic<int64_t>* window_size, int64_t diff) {
268 // A sender MUST NOT allow a flow-control window to exceed 2^31 - 1.
269 // If a sender receives a WINDOW_UPDATE that causes a flow-control window
270 // to exceed this maximum, it MUST terminate either the stream or the connection,
271 // as appropriate.
272 int64_t before_add = window_size->fetch_add(diff, butil::memory_order_relaxed);
273 if ((((before_add | diff) >> 31) & 1) == 0) {
274 // two positive int64_t, check positive overflow
275 if ((before_add + diff) & (1 << 31)) {
276 return false;
277 }
278 }
279 if ((((before_add & diff) >> 31) & 1) == 1) {
280 // two negative int64_t, check negaitive overflow
281 if (((before_add + diff) & (1 << 31)) == 0) {
282 return false;
283 }
284 }
285 // window_size being negative is OK
286 return true;
287}
288
289inline bool MinusWindowSize(butil::atomic<int64_t>* window_size, int64_t size) {
290 if (window_size->load(butil::memory_order_relaxed) < size) {

Callers 2

OnSettingsMethod · 0.85
OnWindowUpdateMethod · 0.85

Calls 1

fetch_addMethod · 0.80

Tested by

no test coverage detected