proxygen
HTTPParallelCodec.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11 
12 #include <bitset>
13 #include <folly/Optional.h>
14 #include <deque>
19 #include <zlib.h>
20 
21 namespace folly { namespace io {
22 class Cursor;
23 }}
24 
25 namespace proxygen {
26 
32 public:
33  explicit HTTPParallelCodec(TransportDirection direction);
34 
36  return transportDirection_;
37  }
38 
39  StreamID createStream() override;
40  bool isBusy() const override { return false; }
41  bool supportsStreamFlowControl() const override { return true; }
42  bool supportsSessionFlowControl() const override { return true; }
43  bool supportsParallelRequests() const override { return true; }
44  bool closeOnEgressComplete() const override { return false; }
45  void setCallback(Callback* callback) override { callback_ = callback; }
46  void setParserPaused(bool /* paused */) override {}
47  void onIngressEOF() override {}
48  bool isReusable() const override;
49  bool isWaitingToDrain() const override;
50  StreamID getLastIncomingStreamID() const override { return lastStreamID_; }
51  void enableDoubleGoawayDrain() override;
52 
53  bool onIngressUpgradeMessage(const HTTPMessage& msg) override;
54 
55  void setNextEgressStreamId(StreamID nextEgressStreamID) {
56  if (nextEgressStreamID > nextEgressStreamID_ &&
57  (nextEgressStreamID & 0x1) == (nextEgressStreamID_ & 0x1) &&
58  nextEgressStreamID_ < std::numeric_limits<int32_t>::max()) {
59  nextEgressStreamID_ = nextEgressStreamID;
60  }
61  }
62 
64  bool odd = stream & 0x01;
65  bool upstream = (transportDirection_ == TransportDirection::UPSTREAM);
66  return (odd && upstream) || (!odd && !upstream);
67  }
68 
70  bool isInitiated = isInitiatedStream(stream);
71  return (isInitiated && stream <= ingressGoawayAck_) ||
72  (!isInitiated && stream <= egressGoawayAck_);
73  }
74 
75 protected:
78  StreamID lastStreamID_{0};
83 
84  enum ClosingState {
85  OPEN = 0,
86  OPEN_WITH_GRACEFUL_DRAIN_ENABLED = 1,
87  FIRST_GOAWAY_SENT = 2,
88  CLOSING = 3, // SPDY only
89  CLOSED = 4 // HTTP2 only
90  } sessionClosing_;
91 
92  template<typename T, typename... Args>
93  bool deliverCallbackIfAllowed(T callbackFn, char const* cbName,
94  StreamID stream, Args&&... args) {
95  if (isStreamIngressEgressAllowed(stream)) {
96  if (callback_) {
97  (*callback_.*callbackFn)(stream, std::forward<Args>(args)...);
98  }
99  return true;
100  } else {
101  VLOG(2) << "Suppressing " << cbName << " for stream=" <<
102  stream << " egressGoawayAck_=" << egressGoawayAck_;
103  }
104  return false;
105  }
106 
107 
108 };
109 } // proxygen
void setCallback(Callback *callback) override
bool deliverCallbackIfAllowed(T callbackFn, char const *cbName, StreamID stream, Args &&...args)
LogLevel max
Definition: LogLevel.cpp:31
bool isInitiatedStream(StreamID stream) const
void setNextEgressStreamId(StreamID nextEgressStreamID)
folly::std T
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
auto odd
Definition: CombineTest.cpp:35
bool supportsParallelRequests() const override
bool isBusy() const override
bool supportsStreamFlowControl() const override
void setParserPaused(bool) override
bool closeOnEgressComplete() const override
bool supportsSessionFlowControl() const override
bool isStreamIngressEgressAllowed(StreamID stream) const
const char * string
Definition: Conv.cpp:212
StreamID getLastIncomingStreamID() const override
uint64_t StreamID
Definition: HTTPCodec.h:49
folly::Function< void()> callback_
TransportDirection transportDirection_
TransportDirection getTransportDirection() const override