From 913401aaee31aab216a83f8a1f085a67b3d62940 Mon Sep 17 00:00:00 2001 From: sfc-gh-tclinkenbeard Date: Sat, 26 Dec 2020 16:30:00 -0400 Subject: [PATCH] Move SendBufferIterator out of network.h This class is only needed for implementation in Net2.actor.cpp and SimExternalConnection.actor.cpp, so this class should not be included everywhere network.h is included --- fdbrpc/SimExternalConnection.actor.cpp | 1 + flow/CMakeLists.txt | 1 + flow/Net2.actor.cpp | 33 +++++++++--------- flow/SendBufferIterator.h | 48 ++++++++++++++++++++++++++ flow/network.h | 20 ----------- 5 files changed, 67 insertions(+), 36 deletions(-) create mode 100644 flow/SendBufferIterator.h diff --git a/fdbrpc/SimExternalConnection.actor.cpp b/fdbrpc/SimExternalConnection.actor.cpp index feca41d349..15779a53f0 100644 --- a/fdbrpc/SimExternalConnection.actor.cpp +++ b/fdbrpc/SimExternalConnection.actor.cpp @@ -26,6 +26,7 @@ #include "fdbclient/FDBTypes.h" #include "fdbrpc/SimExternalConnection.h" #include "flow/Net2Packet.h" +#include "flow/SendBufferIterator.h" #include "flow/UnitTest.h" #include "flow/actorcompiler.h" // This must be the last #include. diff --git a/flow/CMakeLists.txt b/flow/CMakeLists.txt index f791a35831..31dc72cbc2 100644 --- a/flow/CMakeLists.txt +++ b/flow/CMakeLists.txt @@ -47,6 +47,7 @@ set(FLOW_SRCS Platform.h Profiler.actor.cpp Profiler.h + SendBufferIterator.h SignalSafeUnwind.cpp SignalSafeUnwind.h SimpleOpt.h diff --git a/flow/Net2.actor.cpp b/flow/Net2.actor.cpp index 913ea9f0b7..f26393a29e 100644 --- a/flow/Net2.actor.cpp +++ b/flow/Net2.actor.cpp @@ -43,6 +43,7 @@ #include "flow/AsioReactor.h" #include "flow/Profiler.h" #include "flow/ProtocolVersion.h" +#include "flow/SendBufferIterator.h" #include "flow/TLSConfig.actor.h" #include "flow/genericactors.actor.h" #include "flow/Util.h" @@ -1875,6 +1876,22 @@ void ASIOReactor::wake() { } // namespace N2 +SendBufferIterator::SendBufferIterator(SendBuffer const* p, int limit) : p(p), limit(limit) { + ASSERT(limit > 0); +} + +void SendBufferIterator::operator++() { + limit -= p->bytes_written - p->bytes_sent; + if (limit > 0) + p = p->next; + else + p = nullptr; +} + +boost::asio::const_buffer SendBufferIterator::operator*() const { + return boost::asio::const_buffer(p->data() + p->bytes_sent, std::min(limit, p->bytes_written - p->bytes_sent)); +} + INetwork* newNet2(const TLSConfig& tlsConfig, bool useThreadPool, bool useMetrics) { try { N2::g_net2 = new N2::Net2(tlsConfig, useThreadPool, useMetrics); @@ -2034,19 +2051,3 @@ void net2_test() { printf(" Used: %lld\n", FastAllocator<4096>::getTotalMemory()); */ }; - -SendBufferIterator::SendBufferIterator(SendBuffer const* p, int limit) : p(p), limit(limit) { - ASSERT(limit > 0); -} - -void SendBufferIterator::operator++() { - limit -= p->bytes_written - p->bytes_sent; - if (limit > 0) - p = p->next; - else - p = nullptr; -} - -boost::asio::const_buffer SendBufferIterator::operator*() const { - return boost::asio::const_buffer(p->data() + p->bytes_sent, std::min(limit, p->bytes_written - p->bytes_sent)); -} diff --git a/flow/SendBufferIterator.h b/flow/SendBufferIterator.h new file mode 100644 index 0000000000..001d546265 --- /dev/null +++ b/flow/SendBufferIterator.h @@ -0,0 +1,48 @@ +/* + * SendBufferIterator.h + * + * This source file is part of the FoundationDB open source project + * + * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __SENDBUFFER_ITERATOR_H__ +#define __SENDBUFFER_ITERATOR_H__ + +#include "flow/serialize.h" + +#include + +class SendBufferIterator { + SendBuffer const* p; + int limit; + +public: + using value_type = boost::asio::const_buffer; + using iterator_category = std::forward_iterator_tag; + using difference_type = size_t; + using pointer = boost::asio::const_buffer*; + using reference = boost::asio::const_buffer&; + + SendBufferIterator(SendBuffer const* p = nullptr, int limit = std::numeric_limits::max()); + + bool operator==(SendBufferIterator const& r) const { return p == r.p; } + bool operator!=(SendBufferIterator const& r) const { return p != r.p; } + void operator++(); + + boost::asio::const_buffer operator*() const; +}; + +#endif diff --git a/flow/network.h b/flow/network.h index 766d1fa9cf..c028c076ba 100644 --- a/flow/network.h +++ b/flow/network.h @@ -603,24 +603,4 @@ public: // Returns the interface that should be used to make and accept socket connections }; -// TODO: Move into header file that is included only where necessary -struct SendBufferIterator { - typedef boost::asio::const_buffer value_type; - typedef std::forward_iterator_tag iterator_category; - typedef size_t difference_type; - typedef boost::asio::const_buffer* pointer; - typedef boost::asio::const_buffer& reference; - - SendBuffer const* p; - int limit; - - SendBufferIterator(SendBuffer const* p = nullptr, int limit = std::numeric_limits::max()); - - bool operator==(SendBufferIterator const& r) const { return p == r.p; } - bool operator!=(SendBufferIterator const& r) const { return p != r.p; } - void operator++(); - - boost::asio::const_buffer operator*() const; -}; - #endif