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
This commit is contained in:
sfc-gh-tclinkenbeard 2020-12-26 16:30:00 -04:00
parent 2c8ca5d7f9
commit 913401aaee
5 changed files with 67 additions and 36 deletions

View File

@ -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.

View File

@ -47,6 +47,7 @@ set(FLOW_SRCS
Platform.h
Profiler.actor.cpp
Profiler.h
SendBufferIterator.h
SignalSafeUnwind.cpp
SignalSafeUnwind.h
SimpleOpt.h

View File

@ -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));
}

48
flow/SendBufferIterator.h Normal file
View File

@ -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 <boost/asio.hpp>
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<int>::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

View File

@ -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<int>::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