2 * Copyright 2015 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <folly/wangle/channel/Pipeline.h>
19 namespace folly { namespace wangle {
21 void PipelineBase::setWriteFlags(WriteFlags flags) {
25 WriteFlags PipelineBase::getWriteFlags() {
29 void PipelineBase::setReadBufferSettings(
30 uint64_t minAvailable,
31 uint64_t allocationSize) {
32 readBufferSettings_ = std::make_pair(minAvailable, allocationSize);
35 std::pair<uint64_t, uint64_t> PipelineBase::getReadBufferSettings() {
36 return readBufferSettings_;
39 typename PipelineBase::ContextIterator PipelineBase::removeAt(
40 const typename PipelineBase::ContextIterator& it) {
41 (*it)->detachPipeline();
43 const auto dir = (*it)->getDirection();
44 if (dir == HandlerDir::BOTH || dir == HandlerDir::IN) {
45 auto it2 = std::find(inCtxs_.begin(), inCtxs_.end(), it->get());
46 CHECK(it2 != inCtxs_.end());
50 if (dir == HandlerDir::BOTH || dir == HandlerDir::OUT) {
51 auto it2 = std::find(outCtxs_.begin(), outCtxs_.end(), it->get());
52 CHECK(it2 != outCtxs_.end());
56 return ctxs_.erase(it);
59 PipelineBase& PipelineBase::removeFront() {
61 throw std::invalid_argument("No handlers in pipeline");
63 removeAt(ctxs_.begin());
67 PipelineBase& PipelineBase::removeBack() {
69 throw std::invalid_argument("No handlers in pipeline");
71 removeAt(--ctxs_.end());
75 void PipelineBase::detachHandlers() {
76 for (auto& ctx : ctxs_) {
78 ctx->detachPipeline();