proxygen
Pipeline.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 using folly::WriteFlags;
20 
21 namespace wangle {
22 
25 }
26 
28  return writeFlags_;
29 }
30 
32  uint64_t minAvailable,
33  uint64_t allocationSize) {
34  readBufferSettings_ = std::make_pair(minAvailable, allocationSize);
35 }
36 
37 std::pair<uint64_t, uint64_t> PipelineBase::getReadBufferSettings() {
38  return readBufferSettings_;
39 }
40 
41 void PipelineBase::setTransportInfo(std::shared_ptr<TransportInfo> tInfo) {
42  transportInfo_ = tInfo;
43 }
44 
45 std::shared_ptr<TransportInfo> PipelineBase::getTransportInfo() {
46  return transportInfo_;
47 }
48 
50  const typename PipelineBase::ContextIterator& it) {
51  (*it)->detachPipeline();
52 
53  const auto dir = (*it)->getDirection();
54  if (dir == HandlerDir::BOTH || dir == HandlerDir::IN) {
55  auto it2 = std::find(inCtxs_.begin(), inCtxs_.end(), it->get());
56  CHECK(it2 != inCtxs_.end());
57  inCtxs_.erase(it2);
58  }
59 
60  if (dir == HandlerDir::BOTH || dir == HandlerDir::OUT) {
61  auto it2 = std::find(outCtxs_.begin(), outCtxs_.end(), it->get());
62  CHECK(it2 != outCtxs_.end());
63  outCtxs_.erase(it2);
64  }
65 
66  return ctxs_.erase(it);
67 }
68 
70  if (ctxs_.empty()) {
71  throw std::invalid_argument("No handlers in pipeline");
72  }
73  removeAt(ctxs_.begin());
74  return *this;
75 }
76 
78  if (ctxs_.empty()) {
79  throw std::invalid_argument("No handlers in pipeline");
80  }
81  removeAt(--ctxs_.end());
82  return *this;
83 }
84 
86  for (auto& ctx : ctxs_) {
87  if (ctx != owner_) {
88  ctx->detachPipeline();
89  }
90  }
91 }
92 
93 size_t PipelineBase::numHandlers() const {
94  return ctxs_.size();
95 }
96 
97 } // namespace wangle
std::vector< PipelineContext * > outCtxs_
Definition: Pipeline.h:137
std::shared_ptr< PipelineContext > owner_
Definition: Pipeline.h:158
flags
Definition: http_parser.h:127
PipelineBase & removeFront()
Definition: Pipeline.cpp:69
std::vector< std::shared_ptr< PipelineContext > > ctxs_
Definition: Pipeline.h:135
std::shared_ptr< TransportInfo > transportInfo_
Definition: Pipeline.h:142
void setWriteFlags(folly::WriteFlags flags)
Definition: Pipeline.cpp:23
ContextIterator removeAt(const ContextIterator &it)
Definition: Pipeline.cpp:49
PipelineBase & removeBack()
Definition: Pipeline.cpp:77
folly::WriteFlags writeFlags_
Definition: Pipeline.h:155
std::pair< uint64_t, uint64_t > getReadBufferSettings()
Definition: Pipeline.cpp:37
size_t numHandlers() const
Definition: Pipeline.cpp:93
void setReadBufferSettings(uint64_t minAvailable, uint64_t allocationSize)
Definition: Pipeline.cpp:31
std::vector< PipelineContext * > inCtxs_
Definition: Pipeline.h:136
std::vector< std::shared_ptr< PipelineContext > >::iterator ContextIterator
Definition: Pipeline.h:151
std::pair< uint64_t, uint64_t > readBufferSettings_
Definition: Pipeline.h:156
void setTransportInfo(std::shared_ptr< TransportInfo > tInfo)
Definition: Pipeline.cpp:41
folly::WriteFlags getWriteFlags()
Definition: Pipeline.cpp:27
std::shared_ptr< TransportInfo > getTransportInfo()
Definition: Pipeline.cpp:45